Redundant PSU Control with EDM (#26751)

This commit is contained in:
InsanityAutomation 2024-03-09 22:22:23 -05:00 committed by GitHub
parent 4f2b7271bd
commit 504219817c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 51 additions and 4 deletions

View file

@ -405,6 +405,15 @@
//#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power //#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
//#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay //#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay
//#define PSU_OFF_REDUNDANT // Second pin for redundant power control
//#define PSU_OFF_REDUNDANT_INVERTED // Redundant pin state is the inverse of PSU_ACTIVE_STATE
//#define PS_ON1_PIN 6 // Redundant pin required to enable power in combination with PS_ON_PIN
//#define PS_ON_EDM_PIN 8 // External Device Monitoring pins for external power control relay feedback. Fault on mismatch.
//#define PS_ON1_EDM_PIN 9
#define PS_EDM_RESPONSE 250 // (ms) Time to allow for relay action
//#define POWER_OFF_TIMER // Enable M81 D<seconds> to power off after a delay //#define POWER_OFF_TIMER // Enable M81 D<seconds> to power off after a delay
//#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown //#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown

View file

@ -671,6 +671,12 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check()); TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check());
#if ANY(PSU_CONTROL, AUTO_POWER_CONTROL) && PIN_EXISTS(PS_ON_EDM)
if ( ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)
&& (READ(PS_ON_PIN) != READ(PS_ON_EDM_PIN) || TERN0(PSU_OFF_REDUNDANT, extDigitalRead(PS_ON1_PIN) != extDigitalRead(PS_ON1_EDM_PIN)))
) kill(GET_TEXT_F(MSG_POWER_EDM_FAULT));
#endif
#if ENABLED(EXTRUDER_RUNOUT_PREVENT) #if ENABLED(EXTRUDER_RUNOUT_PREVENT)
if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP) if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP)
&& ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS)) && ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))

View file

@ -60,6 +60,10 @@ bool Power::psu_on;
millis_t Power::lastPowerOn; millis_t Power::lastPowerOn;
#endif #endif
#if PSU_TRACK_STATE_MS
millis_t Power::last_state_change_ms = 0;
#endif
/** /**
* Initialize pins & state for the power manager. * Initialize pins & state for the power manager.
* *
@ -87,8 +91,14 @@ void Power::power_on() {
#endif #endif
OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE); OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE);
#if ENABLED(PSU_OFF_REDUNDANT)
OUT_WRITE(PS_ON1_PIN, TERN_(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE);
#endif
TERN_(PSU_TRACK_STATE_MS, last_state_change_ms = millis());
psu_on = true; psu_on = true;
safe_delay(PSU_POWERUP_DELAY); safe_delay(PSU_POWERUP_DELAY);
restore_stepper_drivers(); restore_stepper_drivers();
TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY)); TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
@ -117,6 +127,11 @@ void Power::power_off() {
#endif #endif
OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE); OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE);
#if ENABLED(PSU_OFF_REDUNDANT)
OUT_WRITE(PS_ON1_PIN, IF_DISABLED(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE);
#endif
TERN_(PSU_TRACK_STATE_MS, last_state_change_ms = millis());
psu_on = false; psu_on = false;
#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN) #if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)

View file

@ -24,8 +24,11 @@
/** /**
* power.h - power control * power.h - power control
*/ */
#if PIN_EXISTS(PS_ON_EDM) || (PIN_EXISTS(PS_ON1_EDM) && ENABLED(PSU_OFF_REDUNDANT))
#define PSU_TRACK_STATE_MS 1
#endif
#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) #if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER, PSU_TRACK_STATE_MS)
#include "../core/millis_t.h" #include "../core/millis_t.h"
#endif #endif
@ -37,6 +40,10 @@ class Power {
static void power_on(); static void power_on();
static void power_off(); static void power_off();
#if PSU_TRACK_STATE_MS
static millis_t last_state_change_ms;
#endif
#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN) #if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
#if ENABLED(POWER_OFF_TIMER) #if ENABLED(POWER_OFF_TIMER)
static millis_t power_off_time; static millis_t power_off_time;

View file

@ -3740,6 +3740,8 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive."
#error "POWER_OFF_DELAY must be a positive value." #error "POWER_OFF_DELAY must be a positive value."
#elif ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN) && !(defined(AUTO_POWER_E_TEMP) || defined(AUTO_POWER_CHAMBER_TEMP) || defined(AUTO_POWER_COOLER_TEMP)) #elif ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN) && !(defined(AUTO_POWER_E_TEMP) || defined(AUTO_POWER_CHAMBER_TEMP) || defined(AUTO_POWER_COOLER_TEMP))
#error "POWER_OFF_WAIT_FOR_COOLDOWN requires AUTO_POWER_E_TEMP, AUTO_POWER_CHAMBER_TEMP, and/or AUTO_POWER_COOLER_TEMP." #error "POWER_OFF_WAIT_FOR_COOLDOWN requires AUTO_POWER_E_TEMP, AUTO_POWER_CHAMBER_TEMP, and/or AUTO_POWER_COOLER_TEMP."
#elif ENABLED(PSU_OFF_REDUNDANT) && !PIN_EXISTS(PS_ON1)
#error "PSU_OFF_REDUNDANT requires PS_ON1_PIN."
#endif #endif
#endif #endif

View file

@ -155,6 +155,7 @@ namespace LanguageNarrow_en {
LSTR MSG_SPINDLE_REVERSE = _UxGT("Spindle Reverse"); LSTR MSG_SPINDLE_REVERSE = _UxGT("Spindle Reverse");
LSTR MSG_SWITCH_PS_ON = _UxGT("Switch Power On"); LSTR MSG_SWITCH_PS_ON = _UxGT("Switch Power On");
LSTR MSG_SWITCH_PS_OFF = _UxGT("Switch Power Off"); LSTR MSG_SWITCH_PS_OFF = _UxGT("Switch Power Off");
LSTR MSG_POWER_EDM_FAULT = _UxGT("Power EDM Fault");
LSTR MSG_EXTRUDE = _UxGT("Extrude"); LSTR MSG_EXTRUDE = _UxGT("Extrude");
LSTR MSG_RETRACT = _UxGT("Retract"); LSTR MSG_RETRACT = _UxGT("Retract");
LSTR MSG_MOVE_AXIS = _UxGT("Move Axis"); LSTR MSG_MOVE_AXIS = _UxGT("Move Axis");

View file

@ -901,6 +901,9 @@
#if PIN_EXISTS(PS_ON) #if PIN_EXISTS(PS_ON)
REPORT_NAME_DIGITAL(__LINE__, PS_ON_PIN) REPORT_NAME_DIGITAL(__LINE__, PS_ON_PIN)
#endif #endif
#if PIN_EXISTS(PS_ON1)
REPORT_NAME_DIGITAL(__LINE__, PS_ON1_PIN)
#endif
// //
// LCD // LCD

View file

@ -477,6 +477,10 @@
#undef PS_ON_PIN #undef PS_ON_PIN
#define PS_ON_PIN -1 #define PS_ON_PIN -1
#endif #endif
#if DISABLED(PSU_OFF_REDUNDANT) || !defined(PS_ON1_PIN)
#undef PS_ON1_PIN
#define PS_ON1_PIN -1
#endif
#ifndef KILL_PIN #ifndef KILL_PIN
#define KILL_PIN -1 #define KILL_PIN -1
#endif #endif