Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redundant PSU Control with EDM #26751

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Marlin/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,15 @@
//#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 PSU_OFF_REDUNDANT // Second pin for redundant power control
//#define PSU_OFF_REDUNDANT_OPPOSING // Redundant pin works opposite standard pin

//#define PS_ON1_PIN 6 // Redundant Pin

//#define PS_ON_EDM_PIN 8 // EDM Pins to monitor feedback on external power control relay. Fault on mismatch.
//#define PS_ON1_EDM_PIN 9
#define PS_EDM_RESPONSE 250 // Time in MS to allow for relay action

//#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

Expand Down
19 changes: 19 additions & 0 deletions Marlin/src/MarlinCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -671,6 +671,25 @@ inline void manage_inactivity(const bool no_stepper_sleep=false) {

TERN_(HOTEND_IDLE_TIMEOUT, hotend_idle.check());

#if ANY(PSU_CONTROL, AUTO_POWER_CONTROL)
#if defined(PS_ON_EDM_PIN)
if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE))
{
if(READ(PS_ON_PIN)!=READ(PS_ON_EDM_PIN))
kill(GET_TEXT_F(PS_ON_EDM_FAIL));
}
#endif

#if defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT)
if(ELAPSED(ms, powerManager.last_state_change_ms + PS_EDM_RESPONSE))
{
if(extDigitalRead(PS_ON1_PIN)!=extDigitalRead(PS_ON1_EDM_PIN))
kill(GET_TEXT_F(PS_ON1_EDM_FAIL));
}

#endif
#endif

#if ENABLED(EXTRUDER_RUNOUT_PREVENT)
if (thermalManager.degHotend(active_extruder) > (EXTRUDER_RUNOUT_MINTEMP)
&& ELAPSED(ms, gcode.previous_move_ms + SEC_TO_MS(EXTRUDER_RUNOUT_SECONDS))
Expand Down
25 changes: 25 additions & 0 deletions Marlin/src/feature/power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ bool Power::psu_on;
millis_t Power::lastPowerOn;
#endif

#if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT))
thinkyhead marked this conversation as resolved.
Show resolved Hide resolved
millis_t Power::last_state_change_ms = 0;
#endif

/**
* Initialize pins & state for the power manager.
*
Expand Down Expand Up @@ -87,6 +91,16 @@ void Power::power_on() {
#endif

OUT_WRITE(PS_ON_PIN, PSU_ACTIVE_STATE);
#if ENABLED(PSU_OFF_REDUNDANT)
#if (ENABLED(PSU_OFF_REDUNDANT_OPPOSING))
OUT_WRITE(PS_ON1_PIN, !PSU_ACTIVE_STATE);
#else
OUT_WRITE(PS_ON1_PIN, PSU_ACTIVE_STATE);
#endif
#endif
#if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT))
last_state_change_ms = millis();
#endif
psu_on = true;
safe_delay(PSU_POWERUP_DELAY);
restore_stepper_drivers();
Expand Down Expand Up @@ -117,6 +131,17 @@ void Power::power_off() {
#endif

OUT_WRITE(PS_ON_PIN, !PSU_ACTIVE_STATE);
#if ENABLED(PSU_OFF_REDUNDANT)
#if (ENABLED(PSU_OFF_REDUNDANT_OPPOSING))
OUT_WRITE(PS_ON1_PIN, PSU_ACTIVE_STATE);
#else
OUT_WRITE(PS_ON1_PIN, !PSU_ACTIVE_STATE);
#endif
#endif
#if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT))
last_state_change_ms = millis();
#endif

psu_on = false;

#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
Expand Down
6 changes: 5 additions & 1 deletion Marlin/src/feature/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* power.h - power control
*/

#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER)
#if ANY(AUTO_POWER_CONTROL, POWER_OFF_TIMER) || defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT))
#include "../core/millis_t.h"
#endif

Expand All @@ -37,6 +37,10 @@ class Power {
static void power_on();
static void power_off();

#if defined(PS_ON_EDM_PIN) || (defined(PS_ON_EDM_PIN) && ENABLED(PSU_OFF_REDUNDANT))
static millis_t last_state_change_ms;
#endif

#if ANY(POWER_OFF_TIMER, POWER_OFF_WAIT_FOR_COOLDOWN)
#if ENABLED(POWER_OFF_TIMER)
static millis_t power_off_time;
Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/inc/SanityCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -3641,6 +3641,8 @@ static_assert(_PLUS_TEST(3), "DEFAULT_MAX_ACCELERATION values must be positive."
#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))
#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

Expand Down
2 changes: 2 additions & 0 deletions Marlin/src/lcd/language/language_en.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ namespace LanguageNarrow_en {
LSTR MSG_SPINDLE_REVERSE = _UxGT("Spindle Reverse");
LSTR MSG_SWITCH_PS_ON = _UxGT("Switch Power On");
LSTR MSG_SWITCH_PS_OFF = _UxGT("Switch Power Off");
LSTR PS_ON_EDM_FAIL = _UxGT("PS_ON EDM Fault");
LSTR PS_ON1_EDM_FAIL = _UxGT("PS_ON1 EDM Fault");
LSTR MSG_EXTRUDE = _UxGT("Extrude");
LSTR MSG_RETRACT = _UxGT("Retract");
LSTR MSG_MOVE_AXIS = _UxGT("Move Axis");
Expand Down
3 changes: 3 additions & 0 deletions Marlin/src/pins/pinsDebug_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,9 @@
#if PIN_EXISTS(PS_ON)
REPORT_NAME_DIGITAL(__LINE__, PS_ON_PIN)
#endif
#if PIN_EXISTS(PS_ON1)
REPORT_NAME_DIGITAL(__LINE__, PS_ON1_PIN)
#endif

//
// LCD
Expand Down
4 changes: 4 additions & 0 deletions Marlin/src/pins/pins_postprocess.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,10 @@
#undef PS_ON_PIN
#define PS_ON_PIN -1
#endif
#if DISABLED(PSU_OFF_REDUNDANT) || DISABLED(PSU_CONTROL) || !defined(PS_ON1_PIN)
#undef PS_ON1_PIN
#define PS_ON1_PIN -1
#endif
#ifndef KILL_PIN
#define KILL_PIN -1
#endif
Expand Down
Loading