Heater for threaded program

Dependents:   LEX_Threaded_Programming_V3

Revision:
42:166d9bc7675e
Parent:
41:b1602c68abcd
Child:
43:d34ac9d8648c
diff -r b1602c68abcd -r 166d9bc7675e Heater.cpp
--- a/Heater.cpp	Mon Oct 14 14:15:51 2019 +0000
+++ b/Heater.cpp	Thu Oct 17 10:29:13 2019 +0000
@@ -12,10 +12,15 @@
 Heater::Heater(const int i_port, const int v_port, const float cal_a, const float cal_b, FastPWM * drive, FastPWM * guard, ADS8568_ADC * adc, DigitalIn adc_busy, const memspcr_ThermalConfiguration & thermal)
     :thermal(thermal), i_port(i_port), v_port(v_port), cal_a(cal_a), cal_b(cal_b), drive(drive), guard(guard), adc(adc), adc_busy(adc_busy)
 {
+    //Set up PWM 
     drive->prescaler(1);
     guard->prescaler(1);
     drive->period_ticks(1000);
     guard->period_ticks(1000);
+    
+    //Initialise values for averaging resistance
+    n_acc = 0;
+    R_acc = 0;
 }
 
 void Heater::read()
@@ -45,6 +50,10 @@
         R = (float)v/curr;                
         R = cal_a + cal_b*R;  //Convert to Ohms
     }
+    
+    // Calcualate accumulated resistance values for R_avg output
+    R_acc = R_acc + R;
+    n_acc ++;
         
 }
 
@@ -82,7 +91,7 @@
     guard->write(D*thermal.guard_drive_ratio);
 }
 
-int Heater::Get_D() const
+float Heater::Get_D() const
 {
     return drive->read();
 }
@@ -101,6 +110,14 @@
     return R;
 }
 
+float Heater::Get_R_avg()
+{
+    R_avg = R_acc / (float) n_acc;
+    R_acc = 0;
+    n_acc = 0;
+    return R_avg;
+}
+
 float Heater::Get_R_ref() const
 {
     return R_ref;