From 71eafbf96b20af165e77cbc1f831da0b316ea144 Mon Sep 17 00:00:00 2001 From: Michael Moon Date: Wed, 9 Feb 2011 08:16:15 +1100 Subject: [PATCH] keep power on when heaters are active Reported-by: Jacky2K@forums.reprap.org --- clock.c | 3 ++- gcode_process.c | 4 +++- heater.c | 14 ++++++++++++++ heater.h | 2 ++ 4 files changed, 21 insertions(+), 2 deletions(-) diff --git a/clock.c b/clock.c index 01bcbf1..6d035d2 100644 --- a/clock.c +++ b/clock.c @@ -7,12 +7,13 @@ #include "temp.h" #include "timer.h" #include "debug.h" +#include "heater.h" void clock_250ms() { if (steptimeout > (30 * 4)) { power_off(); } - else + else if (heaters_all_off()) steptimeout++; ifclock(CLOCK_FLAG_1S) { diff --git a/gcode_process.c b/gcode_process.c index b36711d..844d76a 100644 --- a/gcode_process.c +++ b/gcode_process.c @@ -389,8 +389,10 @@ void process_gcode_command() { break; // M135- set heater output case 135: - if (next_target.seen_S) + if (next_target.seen_S) { heater_set(next_target.P, next_target.S); + power_on(); + } break; case 140: //Set heated bed temperature diff --git a/heater.c b/heater.c index 8059665..8779dc1 100644 --- a/heater.c +++ b/heater.c @@ -44,6 +44,8 @@ struct { uint16_t sanity_counter; uint16_t sane_temperature; #endif + + uint8_t heater_output; } heaters_runtime[NUM_HEATERS]; #define DEFAULT_P 8192 @@ -244,6 +246,8 @@ void heater_set(heater_t index, uint8_t value) { if (index >= NUM_HEATERS) return; + heaters_runtime[index].heater_output = value; + if (heaters[index].heater_pwm) { *(heaters[index].heater_pwm) = value; #ifdef DEBUG @@ -259,6 +263,16 @@ void heater_set(heater_t index, uint8_t value) { } } +uint8_t heaters_all_off() { + uint8_t i; + for (i = 0; i < NUM_HEATERS; i++) { + if (heaters_runtime[i].heater_output > 0) + return 0; + } + + return 255; +} + void pid_set_p(heater_t index, int32_t p) { #ifndef BANG_BANG if (index >= NUM_HEATERS) diff --git a/heater.h b/heater.h index b0c9f5c..edd3d23 100644 --- a/heater.h +++ b/heater.h @@ -24,6 +24,8 @@ void heater_save_settings(void); void heater_set(heater_t index, uint8_t value); void heater_tick(heater_t h, temp_sensor_t t, uint16_t current_temp, uint16_t target_temp); +uint8_t heaters_all_off(void); + void pid_set_p(heater_t index, int32_t p); void pid_set_i(heater_t index, int32_t i); void pid_set_d(heater_t index, int32_t d);