ARM: enable temperature control.

Postponed until now to allow better testing of heaters earlier.

Also made pid_init() to handle all heaters at once.
This commit is contained in:
Markus Hitter 2015-08-10 15:07:15 +02:00
parent be6ca4c857
commit d753e2ca7f
5 changed files with 34 additions and 33 deletions

View File

@ -173,9 +173,7 @@ void heater_init() {
#include "config_wrapper.h" #include "config_wrapper.h"
#undef DEFINE_HEATER #undef DEFINE_HEATER
#if 0 pid_init();
pid_init(i);
#endif /* 0 */
} }
/** Set PWM output. /** Set PWM output.

View File

@ -191,7 +191,6 @@ void heater_init() {
} }
} }
pid_init(i);
} }
// set all heater pins to output // set all heater pins to output
@ -201,6 +200,8 @@ void heater_init() {
WRITE(pin, invert ? 1 : 0); WRITE(pin, invert ? 1 : 0);
#include "config_wrapper.h" #include "config_wrapper.h"
#undef DEFINE_HEATER #undef DEFINE_HEATER
pid_init();
} }
/** \brief manually set PWM output /** \brief manually set PWM output

View File

@ -78,35 +78,38 @@ heater_runtime_t heaters_runtime[NUM_HEATERS];
\param i Index of the heater to initialise by Teacup numbering. \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 for (i = 0; i < NUM_HEATERS; i++) {
// 0 is a "sane" temperature when we're trying to cool down. #ifdef HEATER_SANITY_CHECK
heaters_runtime[i].sane_temperature = 0; // 0 is a "sane" temperature when we're trying to cool down.
#endif heaters_runtime[i].sane_temperature = 0;
#endif
#ifndef BANG_BANG #ifndef BANG_BANG
#ifdef EECONFIG #ifdef EECONFIG
// Read factors from EEPROM. // Read factors from EEPROM.
heaters_pid[i].p_factor = heaters_pid[i].p_factor =
eeprom_read_dword((uint32_t *)&EE_factors[i].EE_p_factor); eeprom_read_dword((uint32_t *)&EE_factors[i].EE_p_factor);
heaters_pid[i].i_factor = heaters_pid[i].i_factor =
eeprom_read_dword((uint32_t *)&EE_factors[i].EE_i_factor); eeprom_read_dword((uint32_t *)&EE_factors[i].EE_i_factor);
heaters_pid[i].d_factor = heaters_pid[i].d_factor =
eeprom_read_dword((uint32_t *)&EE_factors[i].EE_d_factor); eeprom_read_dword((uint32_t *)&EE_factors[i].EE_d_factor);
heaters_pid[i].i_limit = heaters_pid[i].i_limit =
eeprom_read_word((uint16_t *)&EE_factors[i].EE_i_limit); eeprom_read_word((uint16_t *)&EE_factors[i].EE_i_limit);
if (crc_block(&heaters_pid[i].p_factor, 14) != if (crc_block(&heaters_pid[i].p_factor, 14) !=
eeprom_read_word((uint16_t *)&EE_factors[i].crc)) eeprom_read_word((uint16_t *)&EE_factors[i].crc))
#endif /* EECONFIG */ #endif /* EECONFIG */
{ {
heaters_pid[i].p_factor = DEFAULT_P; heaters_pid[i].p_factor = DEFAULT_P;
heaters_pid[i].i_factor = DEFAULT_I; heaters_pid[i].i_factor = DEFAULT_I;
heaters_pid[i].d_factor = DEFAULT_D; heaters_pid[i].d_factor = DEFAULT_D;
heaters_pid[i].i_limit = DEFAULT_I_LIMIT; heaters_pid[i].i_limit = DEFAULT_I_LIMIT;
} }
#endif /* BANG_BANG */ #endif /* BANG_BANG */
}
} }
/** \brief run heater PID algorithm /** \brief run heater PID algorithm

View File

@ -69,7 +69,7 @@ typedef struct {
extern heater_runtime_t heaters_runtime[]; extern heater_runtime_t heaters_runtime[];
void heater_init(void); 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_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); void heater_tick(heater_t h, temp_type_t type, uint16_t current_temp, uint16_t target_temp);

3
temp.c
View File

@ -122,6 +122,7 @@ void temp_init() {
/// called every 10ms from clock.c - check all temp sensors that are ready for checking /// called every 10ms from clock.c - check all temp sensors that are ready for checking
void temp_sensor_tick() { void temp_sensor_tick() {
temp_sensor_t i = 0; temp_sensor_t i = 0;
for (; i < NUM_TEMP_SENSORS; i++) { for (; i < NUM_TEMP_SENSORS; i++) {
if (temp_sensors_runtime[i].next_read_time) { if (temp_sensors_runtime[i].next_read_time) {
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) { 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); 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)) if (DEBUG_PID && (debug_flags & DEBUG_PID))