Skip to content

Commit 5042198

Browse files
✨ Redundant PSU Control with EDM (#26751)
1 parent 4f2b727 commit 5042198

File tree

8 files changed

+51
-4
lines changed

8 files changed

+51
-4
lines changed

Marlin/Configuration.h

+12-3
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,18 @@
401401
//#define PS_OFF_SOUND // Beep 1s when power off
402402
#define PSU_ACTIVE_STATE LOW // Set 'LOW' for ATX, 'HIGH' for X-Box
403403

404-
//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
405-
//#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
406-
//#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay
404+
//#define PSU_DEFAULT_OFF // Keep power off until enabled directly with M80
405+
//#define PSU_POWERUP_DELAY 250 // (ms) Delay for the PSU to warm up to full power
406+
//#define LED_POWEROFF_TIMEOUT 10000 // (ms) Turn off LEDs after power-off, with this amount of delay
407+
408+
//#define PSU_OFF_REDUNDANT // Second pin for redundant power control
409+
//#define PSU_OFF_REDUNDANT_INVERTED // Redundant pin state is the inverse of PSU_ACTIVE_STATE
410+
411+
//#define PS_ON1_PIN 6 // Redundant pin required to enable power in combination with PS_ON_PIN
412+
413+
//#define PS_ON_EDM_PIN 8 // External Device Monitoring pins for external power control relay feedback. Fault on mismatch.
414+
//#define PS_ON1_EDM_PIN 9
415+
#define PS_EDM_RESPONSE 250 // (ms) Time to allow for relay action
407416

408417
//#define POWER_OFF_TIMER // Enable M81 D<seconds> to power off after a delay
409418
//#define POWER_OFF_WAIT_FOR_COOLDOWN // Enable M81 S to power off only after cooldown

Marlin/src/MarlinCore.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,12 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {
671671

672672
TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check());
673673

674+
#if ANY(PSU_CONTROL, AUTO_POWER_CONTROL) && PIN_EXISTS(PS_ON_EDM)
675+
if ( ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE)
676+
&& (READ(PS_ON_PIN) != READ(PS_ON_EDM_PIN) || TERN0(PSU_OFF_REDUNDANT, extDigitalRead(PS_ON1_PIN) != extDigitalRead(PS_ON1_EDM_PIN)))
677+
) kill(GET_TEXT_F(MSG_POWER_EDM_FAULT));
678+
#endif
679+
674680
#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
675681
if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP)
676682
&& ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))

Marlin/src/feature/power.cpp

+15
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ bool Power::psu_on;
6060
millis_t Power::lastPowerOn;
6161
#endif
6262

63+
#if PSU_TRACK_STATE_MS
64+
millis_t Power::last_state_change_ms = 0;
65+
#endif
66+
6367
/**
6468
* Initialize pins & state for the power manager.
6569
*
@@ -87,8 +91,14 @@ void Power::power_on() {
8791
#endif
8892

8993
OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE);
94+
#if ENABLED(PSU_OFF_REDUNDANT)
95+
OUT_WRITE(PS_ON1_PIN, TERN_(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE);
96+
#endif
97+
TERN_(PSU_TRACK_STATE_MS, last_state_change_ms = millis());
98+
9099
psu_on = true;
91100
safe_delay(PSU_POWERUP_DELAY);
101+
92102
restore_stepper_drivers();
93103
TERN_(HAS_TRINAMIC_CONFIG, safe_delay(PSU_POWERUP_DELAY));
94104

@@ -117,6 +127,11 @@ void Power::power_off() {
117127
#endif
118128

119129
OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE);
130+
#if ENABLED(PSU_OFF_REDUNDANT)
131+
OUT_WRITE(PS_ON1_PIN, IF_DISABLED(PSU_OFF_REDUNDANT_INVERTED, !)PSU_ACTIVE_STATE);
132+
#endif
133+
TERN_(PSU_TRACK_STATE_MS, last_state_change_ms = millis());
134+
120135
psu_on = false;
121136

122137
#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)

Marlin/src/feature/power.h

+8-1
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@
2424
/**
2525
* power.h - power control
2626
*/
27+
#if PIN_EXISTS(PS_ON_EDM) || (PIN_EXISTS(PS_ON1_EDM) && ENABLED(PSU_OFF_REDUNDANT))
28+
#define PSU_TRACK_STATE_MS 1
29+
#endif
2730

28-
#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER)
31+
#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER, PSU_TRACK_STATE_MS)
2932
#include "../core/millis_t.h"
3033
#endif
3134

@@ -37,6 +40,10 @@ class Power {
3740
static void power_on();
3841
static void power_off();
3942

43+
#if PSU_TRACK_STATE_MS
44+
static millis_t last_state_change_ms;
45+
#endif
46+
4047
#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
4148
#if ENABLED(POWER_OFF_TIMER)
4249
static millis_t power_off_time;

Marlin/src/inc/SanityCheck.h

+2
Original file line numberDiff line numberDiff line change
@@ -3740,6 +3740,8 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive."
37403740
#error "POWER_OFF_DELAY must be a positive value."
37413741
#elif ENABLED(POWER_OFF_WAIT_FOR_COOLDOWN) && !(defined(AUTO_POWER_E_TEMP) || defined(AUTO_POWER_CHAMBER_TEMP) || defined(AUTO_POWER_COOLER_TEMP))
37423742
#error "POWER_OFF_WAIT_FOR_COOLDOWN requires AUTO_POWER_E_TEMP, AUTO_POWER_CHAMBER_TEMP, and/or AUTO_POWER_COOLER_TEMP."
3743+
#elif ENABLED(PSU_OFF_REDUNDANT) && !PIN_EXISTS(PS_ON1)
3744+
#error "PSU_OFF_REDUNDANT requires PS_ON1_PIN."
37433745
#endif
37443746
#endif
37453747

Marlin/src/lcd/language/language_en.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ namespace LanguageNarrow_en {
155155
LSTR MSG_SPINDLE_REVERSE = _UxGT("Spindle Reverse");
156156
LSTR MSG_SWITCH_PS_ON = _UxGT("Switch Power On");
157157
LSTR MSG_SWITCH_PS_OFF = _UxGT("Switch Power Off");
158+
LSTR MSG_POWER_EDM_FAULT = _UxGT("Power EDM Fault");
158159
LSTR MSG_EXTRUDE = _UxGT("Extrude");
159160
LSTR MSG_RETRACT = _UxGT("Retract");
160161
LSTR MSG_MOVE_AXIS = _UxGT("Move Axis");

Marlin/src/pins/pinsDebug_list.h

+3
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,9 @@
901901
#if PIN_EXISTS(PS_ON)
902902
REPORT_NAME_DIGITAL(__LINE__, PS_ON_PIN)
903903
#endif
904+
#if PIN_EXISTS(PS_ON1)
905+
REPORT_NAME_DIGITAL(__LINE__, PS_ON1_PIN)
906+
#endif
904907

905908
//
906909
// LCD

Marlin/src/pins/pins_postprocess.h

+4
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,10 @@
477477
#undef PS_ON_PIN
478478
#define PS_ON_PIN -1
479479
#endif
480+
#if DISABLED(PSU_OFF_REDUNDANT) || !defined(PS_ON1_PIN)
481+
#undef PS_ON1_PIN
482+
#define PS_ON1_PIN -1
483+
#endif
480484
#ifndef KILL_PIN
481485
#define KILL_PIN -1
482486
#endif

0 commit comments

Comments
 (0)