Manage heaters. More...
#include "heater.h"#include <stdlib.h>#include <avr/eeprom.h>#include <avr/pgmspace.h>#include "arduino.h"#include "debug.h"#include "temp.h"#include "crc.h"#include "sersendf.h"#include "config.h"Data Structures | |
| struct | heater_definition_t |
| simply holds pinout data- port, pin, pwm channel if used More... | |
| struct | EE_factor |
| this lives in the eeprom so we can save our PID settings for each heater More... | |
Defines | |
| #define | DEFINE_HEATER(name, port, pin, pwm) { &(port), (pin), &(pwm) }, |
| helper macro to fill heater definition struct from config.h | |
| #define | DEFAULT_P 8192 |
| default scaled P factor, equivalent to 8.0 | |
| #define | DEFAULT_I 512 |
| default scaled I factor, equivalent to 0.5 | |
| #define | DEFAULT_D 24576 |
| default scaled D factor, equivalent to 24 | |
| #define | DEFAULT_I_LIMIT 384 |
| default scaled I limit | |
Functions | |
| void | heater_init () |
| initialise heater subsystem Set directions, initialise PWM timers, read PID factors from eeprom, etc | |
| void | heater_save_settings () |
| Write PID factors to eeprom. | |
| void | heater_tick (heater_t h, temp_sensor_t t, uint16_t current_temp, uint16_t target_temp) |
| run heater PID algorithm | |
| void | heater_set (heater_t index, uint8_t value) |
| manually set PWM output | |
| uint8_t | heaters_all_off () |
| turn off all heaters | |
| void | pid_set_p (heater_t index, int32_t p) |
| set heater P factor | |
| void | pid_set_i (heater_t index, int32_t i) |
| set heater I factor | |
| void | pid_set_d (heater_t index, int32_t d) |
| set heater D factor | |
| void | pid_set_i_limit (heater_t index, int32_t i_limit) |
| set heater I limit | |
| void | heater_print (uint16_t i) |
| send heater debug info to host | |
Variables | |
| struct { | |
| int32_t p_factor | |
| scaled P factor | |
| int32_t i_factor | |
| scaled I factor | |
| int32_t d_factor | |
| scaled D factor | |
| int16_t i_limit | |
scaled I limit, such that | |
| } | heaters_pid [NUM_HEATERS] |
| this struct holds the heater PID factors | |
| struct { | |
| int16_t heater_i | |
integrator, | |
| uint16_t temp_history [TH_COUNT] | |
| store last TH_COUNT readings in a ring, so we can smooth out our differentiator | |
| uint8_t temp_history_pointer | |
| pointer to last entry in ring | |
| uint8_t heater_output | |
| this is the PID value we eventually send to the heater | |
| } | heaters_runtime [NUM_HEATERS] |
| EE_factor EEMEM | EE_factors [NUM_HEATERS] |
Manage heaters.
| void heater_print | ( | uint16_t | i ) |
send heater debug info to host
| i | index of heater to send info for |
Referenced by process_gcode_command().
| void heater_set | ( | heater_t | index, |
| uint8_t | value | ||
| ) |
manually set PWM output
| index | the heater we're setting the output for |
| value | the PWM value to write |
anything done by this function is overwritten by heater_tick above if the heater has an associated temp sensor
Referenced by dda_start(), dda_step(), heater_tick(), and process_gcode_command().
| void heater_tick | ( | heater_t | h, |
| temp_sensor_t | t, | ||
| uint16_t | current_temp, | ||
| uint16_t | target_temp | ||
| ) |
run heater PID algorithm
| h | which heater we're running the loop for |
| t | which temp sensor this heater is attached to |
| current_temp | the temperature that the associated temp sensor is reporting |
| target_temp | the temperature we're trying to achieve |
Referenced by temp_sensor_tick().
| uint8_t heaters_all_off | ( | void | ) |
| void pid_set_d | ( | heater_t | index, |
| int32_t | d | ||
| ) |
set heater D factor
| index | heater to change D factor for |
| d | scaled D factor |
Referenced by process_gcode_command().
| void pid_set_i | ( | heater_t | index, |
| int32_t | i | ||
| ) |
set heater I factor
| index | heater to change I factor for |
| i | scaled I factor |
Referenced by process_gcode_command().
| void pid_set_i_limit | ( | heater_t | index, |
| int32_t | i_limit | ||
| ) |
set heater I limit
| index | heater to set I limit for |
| i_limit | scaled I limit |
Referenced by process_gcode_command().
| void pid_set_p | ( | heater_t | index, |
| int32_t | p | ||
| ) |
set heater P factor
| index | heater to change factor for |
| p | scaled P factor |
Referenced by process_gcode_command().
this struct holds the heater PID factors
PID is a fascinating way to control any closed loop control, combining the error (P), cumulative error (I) and rate at which we're approacing the setpoint (D) in such a way that when correctly tuned, the system will achieve target temperature quickly and with little to no overshoot
At every sample, we calculate
where S is setpoint and T is temperature.
The three factors kP, kI, kD are chosen to give the desired behaviour given the dynamics of the system.
See http://www.eetimes.com/design/embedded/4211211/PID-without-a-PhD for the full story
Referenced by heater_init(), heater_print(), heater_save_settings(), heater_tick(), pid_set_d(), pid_set_i(), pid_set_i_limit(), and pid_set_p().
1.7.2