Heater for threaded program
Dependents: LEX_Threaded_Programming_V3
Diff: Heater.cpp
- Revision:
- 41:b1602c68abcd
- Parent:
- 39:5dffedda7a0d
- Child:
- 42:166d9bc7675e
--- a/Heater.cpp Mon Sep 30 16:09:43 2019 +0000 +++ b/Heater.cpp Mon Oct 14 14:15:51 2019 +0000 @@ -46,21 +46,21 @@ R = cal_a + cal_b*R; //Convert to Ohms } - //Get error and integrated error values - error = R_ref - R; - error_integrated += error * (float) thermal.thermal_control_loop_interval_ms; - - //Only allow positive integrated errors and limit change in integrated error - //to help avoid integral windup - if (abs(error) > thermal.pid_wind_up_limit_ohm) error = error * thermal.pid_wind_up_limit_ohm / abs(error); } void Heater::update() { + + //Get error + error = R_ref - R; + //Update PWM from setpoint and resistance double duty_cycle = thermal.pid_kp_mho * error; - + + //Get integrated error if (thermal.pid_integral_time_ms > 0) // set integral time to zero to have no integral term + if (abs(error) > thermal.pid_wind_up_limit_ohm) error = error * thermal.pid_wind_up_limit_ohm / abs(error); + error_integrated += error * (float) thermal.thermal_control_loop_interval_ms; duty_cycle += thermal.pid_kp_mho * error_integrated/thermal.pid_integral_time_ms; if (duty_cycle > thermal.pid_pwm_limit)