temperature_control.bed.set_and_wait_m_code 190 #
temperature_control.bed.designator B #
+#temperature_control.bed.bang_bang false # set to true to use bang bang control rather than PID
+#temperature_control.bed.hysteresis 2.0 # set to the temperature in degrees C to use as hysteresis when using bang bang
+
# Switch module for fan control
switch.fan.enable true #
switch.fan.input_on_command M106 #
network.webserver.enable true # enable the webserver
network.telnet.enable true # enable the telnet server
network.ip_address auto # use dhcp to get ip address
-# uncomment the 3 below to manually setup ip address
+# uncomment the 3 below to manually setup ip address
#network.ip_address 192.168.3.222 # the IP address
#network.ip_mask 255.255.255.0 # the ip mask
#network.ip_gateway 192.168.3.1 # the gateway address
#define readings_per_second_checksum CHECKSUM("readings_per_second")
#define max_pwm_checksum CHECKSUM("max_pwm")
#define pwm_frequency_checksum CHECKSUM("pwm_frequency")
+#define bang_bang_checksum CHECKSUM("bang_bang")
+#define hysteresis_checksum CHECKSUM("hysteresis")
#define t0_checksum CHECKSUM("t0")
#define beta_checksum CHECKSUM("beta")
#define vadc_checksum CHECKSUM("vadc")
// Heater pin
this->heater_pin.from_string( THEKERNEL->config->value(temperature_control_checksum, this->name_checksum, heater_pin_checksum)->required()->as_string())->as_output();
this->heater_pin.max_pwm( THEKERNEL->config->value(temperature_control_checksum, this->name_checksum, max_pwm_checksum)->by_default(255)->as_number() );
+
this->heater_pin.set(0);
+ this->heater_on= false;
+
+ // used to enable bang bang control of heater
+ this->use_bangbang= THEKERNEL->config->value(temperature_control_checksum, this->name_checksum, bang_bang_checksum)->by_default(false)->as_bool();
+ this->hysteresis= THEKERNEL->config->value(temperature_control_checksum, this->name_checksum, hysteresis_checksum)->by_default(2)->as_number();
set_low_on_debug(heater_pin.port_number, heater_pin.pin);
*/
void TemperatureControl::pid_process(float temperature)
{
- float error = target_temperature - temperature;
+ if(use_bangbang) {
+ // bang bang if very simple, if temp is < target - hysteresis turn on full else if temp is > target + hysteresis turn heater off
+ // good for relays
+ if(temperature > target_temperature+hysteresis && heater_on) {
+ heater_pin.set(false);
+ heater_on= false;
+ this->o= 0; // for display purposes only
+
+ }else if(temperature < target_temperature-hysteresis && !heater_on) {
+ if(heater_pin.max_pwm() >= 255) {
+ // turn on full
+ this->heater_pin.set(true);
+ this->o= 255; // for display purposes only
+ }else{
+ // only to whatever max pwm is configured
+ this->heater_pin.pwm(heater_pin.max_pwm());
+ this->o= heater_pin.max_pwm(); // for display purposes only
+ }
+ heater_on= true;
+ }
+ return;
+ }
+ // regular PID control
+ float error = target_temperature - temperature;
this->iTerm += (error * this->i_factor);
if (this->iTerm > this->i_max) this->iTerm = this->i_max;
else if (this->iTerm < 0.0) this->iTerm = 0.0;