From d753e2ca7f7e2523a456e406c7a9300f0eacdc6c Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Mon, 10 Aug 2015 15:07:15 +0200 Subject: [PATCH] ARM: enable temperature control. Postponed until now to allow better testing of heaters earlier. Also made pid_init() to handle all heaters at once. --- heater-arm.c | 4 +--- heater-avr.c | 3 ++- heater.c | 55 +++++++++++++++++++++++++++------------------------- heater.h | 2 +- temp.c | 3 +-- 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/heater-arm.c b/heater-arm.c index 27f0f99..647b55f 100644 --- a/heater-arm.c +++ b/heater-arm.c @@ -173,9 +173,7 @@ void heater_init() { #include "config_wrapper.h" #undef DEFINE_HEATER -#if 0 - pid_init(i); -#endif /* 0 */ + pid_init(); } /** Set PWM output. diff --git a/heater-avr.c b/heater-avr.c index 993b7cf..c8a6dc8 100644 --- a/heater-avr.c +++ b/heater-avr.c @@ -191,7 +191,6 @@ void heater_init() { } } - pid_init(i); } // set all heater pins to output @@ -201,6 +200,8 @@ void heater_init() { WRITE(pin, invert ? 1 : 0); #include "config_wrapper.h" #undef DEFINE_HEATER + + pid_init(); } /** \brief manually set PWM output diff --git a/heater.c b/heater.c index cf1bfba..bf9a080 100644 --- a/heater.c +++ b/heater.c @@ -78,35 +78,38 @@ heater_runtime_t heaters_runtime[NUM_HEATERS]; \param i Index of the heater to initialise by Teacup numbering. */ -void pid_init(heater_t i) { +void pid_init() { + uint8_t i; - #ifdef HEATER_SANITY_CHECK - // 0 is a "sane" temperature when we're trying to cool down. - heaters_runtime[i].sane_temperature = 0; - #endif + for (i = 0; i < NUM_HEATERS; i++) { + #ifdef HEATER_SANITY_CHECK + // 0 is a "sane" temperature when we're trying to cool down. + heaters_runtime[i].sane_temperature = 0; + #endif - #ifndef BANG_BANG - #ifdef EECONFIG - // Read factors from EEPROM. - heaters_pid[i].p_factor = - eeprom_read_dword((uint32_t *)&EE_factors[i].EE_p_factor); - heaters_pid[i].i_factor = - eeprom_read_dword((uint32_t *)&EE_factors[i].EE_i_factor); - heaters_pid[i].d_factor = - eeprom_read_dword((uint32_t *)&EE_factors[i].EE_d_factor); - heaters_pid[i].i_limit = - eeprom_read_word((uint16_t *)&EE_factors[i].EE_i_limit); + #ifndef BANG_BANG + #ifdef EECONFIG + // Read factors from EEPROM. + heaters_pid[i].p_factor = + eeprom_read_dword((uint32_t *)&EE_factors[i].EE_p_factor); + heaters_pid[i].i_factor = + eeprom_read_dword((uint32_t *)&EE_factors[i].EE_i_factor); + heaters_pid[i].d_factor = + eeprom_read_dword((uint32_t *)&EE_factors[i].EE_d_factor); + heaters_pid[i].i_limit = + eeprom_read_word((uint16_t *)&EE_factors[i].EE_i_limit); - if (crc_block(&heaters_pid[i].p_factor, 14) != - eeprom_read_word((uint16_t *)&EE_factors[i].crc)) - #endif /* EECONFIG */ - { - heaters_pid[i].p_factor = DEFAULT_P; - heaters_pid[i].i_factor = DEFAULT_I; - heaters_pid[i].d_factor = DEFAULT_D; - heaters_pid[i].i_limit = DEFAULT_I_LIMIT; - } - #endif /* BANG_BANG */ + if (crc_block(&heaters_pid[i].p_factor, 14) != + eeprom_read_word((uint16_t *)&EE_factors[i].crc)) + #endif /* EECONFIG */ + { + heaters_pid[i].p_factor = DEFAULT_P; + heaters_pid[i].i_factor = DEFAULT_I; + heaters_pid[i].d_factor = DEFAULT_D; + heaters_pid[i].i_limit = DEFAULT_I_LIMIT; + } + #endif /* BANG_BANG */ + } } /** \brief run heater PID algorithm diff --git a/heater.h b/heater.h index 39ffc8c..4330371 100644 --- a/heater.h +++ b/heater.h @@ -69,7 +69,7 @@ typedef struct { extern heater_runtime_t heaters_runtime[]; void heater_init(void); -void pid_init(heater_t index); +void pid_init(void); void heater_set(heater_t index, uint8_t value); void heater_tick(heater_t h, temp_type_t type, uint16_t current_temp, uint16_t target_temp); diff --git a/temp.c b/temp.c index e781897..160ec20 100644 --- a/temp.c +++ b/temp.c @@ -122,6 +122,7 @@ void temp_init() { /// called every 10ms from clock.c - check all temp sensors that are ready for checking void temp_sensor_tick() { temp_sensor_t i = 0; + for (; i < NUM_TEMP_SENSORS; i++) { if (temp_sensors_runtime[i].next_read_time) { temp_sensors_runtime[i].next_read_time--; @@ -297,9 +298,7 @@ void temp_sensor_tick() { } if (temp_sensors[i].heater < NUM_HEATERS) { - #ifndef __ARMEL_NOTYET__ heater_tick(temp_sensors[i].heater, temp_sensors[i].temp_type, temp_sensors_runtime[i].last_read_temp, temp_sensors_runtime[i].target_temp); - #endif /* __ARMEL_NOTYET__ */ } if (DEBUG_PID && (debug_flags & DEBUG_PID))