Heater for threaded program
Dependents: LEX_Threaded_Programming_V3
Diff: Heater.cpp
- Revision:
- 45:5f588512529b
- Parent:
- 44:e358867319f6
- Child:
- 46:47c394467c66
--- a/Heater.cpp Fri Nov 15 15:59:32 2019 +0000 +++ b/Heater.cpp Sat Nov 16 06:05:55 2019 +0000 @@ -21,6 +21,7 @@ //Initialise values for averaging resistance n_acc = 0; R_acc = 0; + R2_acc = 0; } void Heater::read() @@ -51,8 +52,9 @@ R = cal_a + cal_b*R; //Convert to Ohms } - // Calcualate accumulated resistance values for R_avg output + // Calculate accumulated resistance values for R_avg and R_var output R_acc = R_acc + R; + R2_acc = R2_acc + R*R n_acc ++; } @@ -113,11 +115,18 @@ 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_acc = 0; + R2_acc = 0; n_acc = 0; return R_avg; } +float Heater::Get_R_var() // need to call Get_R_avg to calculate R_var before calling this function +{ + return R_var; +} + float Heater::Get_R_ref() const { return R_ref;