From 3d1ebf1186155257a4f302d6883e41c12f684a89 Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Fri, 11 May 2012 16:34:42 +0200 Subject: [PATCH] Review power supply timeout. - Move the variable from dda.c to pinio.c. - Reset the timeout on each power on, to guarantee a minimum PSU on time. --- clock.c | 4 ++-- dda.c | 8 ++------ dda.h | 4 ---- gcode_process.c | 1 - pinio.c | 5 +++++ pinio.h | 7 +++++++ 6 files changed, 16 insertions(+), 13 deletions(-) diff --git a/clock.c b/clock.c index d4f31ac..26c9641 100644 --- a/clock.c +++ b/clock.c @@ -25,14 +25,14 @@ void clock_250ms() { #ifndef NO_AUTO_IDLE if (temp_all_zero()) { - if (steptimeout > (30 * 4)) { + if (psu_timeout > (30 * 4)) { power_off(); } else { uint8_t save_reg = SREG; cli(); CLI_SEI_BUG_MEMORY_BARRIER(); - steptimeout++; + psu_timeout++; MEMORY_BARRIER(); SREG = save_reg; } diff --git a/dda.c b/dda.c index 348b0b3..f15055f 100644 --- a/dda.c +++ b/dda.c @@ -28,9 +28,6 @@ #error STEPS_PER_MM_Y is gone, review your config.h and use STEPS_PER_M_Y #endif -/// step timeout -volatile uint8_t steptimeout = 0; - /* position tracking */ @@ -275,7 +272,6 @@ void dda_create(DDA *dda, TARGET *target) { } else { // get steppers ready to go - steptimeout = 0; power_on(); stepper_enable(); x_enable(); @@ -483,7 +479,7 @@ void dda_start(DDA *dda) { // called from interrupt context: keep it simple! if ( ! dda->nullmove) { // get ready to go - steptimeout = 0; + psu_timeout = 0; if (dda->z_delta) z_enable(); @@ -823,7 +819,7 @@ void dda_step(DDA *dda) { z_disable(); } else - steptimeout = 0; + psu_timeout = 0; #ifdef ACCELERATION_RAMPING // we don't hit maximum speed exactly with acceleration calculation, so limit it here diff --git a/dda.h b/dda.h index e96b57f..940fb04 100644 --- a/dda.h +++ b/dda.h @@ -221,10 +221,6 @@ typedef struct { variables */ -/// steptimeout is set to zero when we step, and increases over time so we can turn the motors off when they've been idle for a while -/// It is also used inside and outside of interrupts, which is why it has been made volatile -extern volatile uint8_t steptimeout; - /// startpoint holds the endpoint of the most recently created DDA, so we know where the next one created starts. could also be called last_endpoint extern TARGET startpoint; diff --git a/gcode_process.c b/gcode_process.c index 4cf5fe3..3c44c9c 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -704,7 +704,6 @@ void process_gcode_command() { y_enable(); z_enable(); e_enable(); - steptimeout = 0; break; case 191: diff --git a/pinio.c b/pinio.c index 22cc1ed..b6191cc 100644 --- a/pinio.c +++ b/pinio.c @@ -3,6 +3,9 @@ static char ps_is_on = 0; +/// step/psu timeout +volatile uint8_t psu_timeout = 0; + void power_on() { if (ps_is_on == 0) { @@ -13,6 +16,8 @@ void power_on() { #endif ps_is_on = 1; } + + psu_timeout = 0; } void power_off() { diff --git a/pinio.h b/pinio.h index 4baa461..d5cc9aa 100644 --- a/pinio.h +++ b/pinio.h @@ -11,6 +11,13 @@ Power */ +/// psu_timeout is set to zero when we step, and increases over time so we can +/// turn the motors off when they've been idle for a while. +/// A second function is to guarantee a minimum on time of the PSU. +/// Timeout counting is done in clock.c. +/// It is used inside and outside of interrupts, which is why it has been made volatile +extern volatile uint8_t psu_timeout; + void power_on(void); void power_off(void);