Heater for threaded program
Dependents: LEX_Threaded_Programming_V3
Diff: Heater.cpp
- Revision:
- 48:cd2a9b799e89
- Parent:
- 47:06a9691d0a7b
- Child:
- 49:35fd40559960
diff -r 06a9691d0a7b -r cd2a9b799e89 Heater.cpp --- a/Heater.cpp Mon Nov 18 17:50:03 2019 +0000 +++ b/Heater.cpp Tue Dec 17 13:28:23 2019 +0000 @@ -65,17 +65,18 @@ { //Get error - error = R_ref - R; // use single reading R values - //error = R_ref - R_smooth; // use smoothed R values + //error = R_ref - R; // use single reading R values + error = R_ref - R_smooth; // use smoothed R values //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 + //Integral term (if used) + 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) duty_cycle = thermal.pid_pwm_limit;