Heater for threaded program

Dependents:   LEX_Threaded_Programming_V3

Revision:
46:47c394467c66
Parent:
45:5f588512529b
Child:
47:06a9691d0a7b
--- a/Heater.cpp	Sat Nov 16 06:05:55 2019 +0000
+++ b/Heater.cpp	Mon Nov 18 13:48:31 2019 +0000
@@ -21,6 +21,7 @@
     //Initialise values for averaging resistance
     n_acc = 0;
     R_acc = 0;
+    R_smooth = 0;
     R2_acc = 0;
 }
 
@@ -53,8 +54,9 @@
     }
     
     // Calculate accumulated resistance values for R_avg and R_var output
+    R_smooth = R_SMOOTH_FACTOR*R_smooth + (1-R_SMOOTH_FACTOR)*R;
     R_acc = R_acc + R;
-    R2_acc = R2_acc + R*R
+    R2_acc = R2_acc + R*R;
     n_acc ++;
         
 }
@@ -63,7 +65,8 @@
 {
 
     //Get error
-    error = R_ref - R;
+    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;
@@ -115,7 +118,7 @@
 float Heater::Get_R_avg()
 {
     R_avg = R_acc / (float) n_acc;
-    R_var = (R2_acc*R2_acc - R_avg*R_avg) / n_acc
+    R_var = (R2_acc*R2_acc - R_avg*R_avg) / n_acc;
     R_acc = 0;
     R2_acc = 0;
     n_acc = 0;