Heater for threaded program

Dependents:   LEX_Threaded_Programming_V3

Committer:
justinbuckland
Date:
Mon Nov 18 13:48:31 2019 +0000
Revision:
46:47c394467c66
Parent:
45:5f588512529b
Child:
48:cd2a9b799e89
added R_smooth calculation to reduce noise

Who changed what in which revision?

UserRevisionLine numberNew contents of line
omatthews 0:4e33cc8171f4 1 /*------------------------------------------------------------------------------
omatthews 0:4e33cc8171f4 2 Library header file for heater operations
omatthews 0:4e33cc8171f4 3 Date: 16/07/2018
omatthews 0:4e33cc8171f4 4
omatthews 0:4e33cc8171f4 5
omatthews 0:4e33cc8171f4 6 ------------------------------------------------------------------------------*/
omatthews 0:4e33cc8171f4 7
omatthews 0:4e33cc8171f4 8 #ifndef Heater_H
omatthews 0:4e33cc8171f4 9 #define Heater_H
omatthews 0:4e33cc8171f4 10 #include "mbed.h"
omatthews 0:4e33cc8171f4 11 #include "ADS8568_ADC.h"
omatthews 17:0bfed0e96927 12 #include "FastPWM.h"
omatthews 26:f6c98b05ee85 13 #include "memspcr.pb.h"
omatthews 0:4e33cc8171f4 14
justinbuckland 46:47c394467c66 15 #define R_SMOOTH_FACTOR 0.5 // resisstance smoothing factor (0 = no smoothing, 1 = infinite smoothing)
justinbuckland 46:47c394467c66 16
omatthews 0:4e33cc8171f4 17 class Heater
omatthews 0:4e33cc8171f4 18 {
omatthews 7:59ece353eea2 19 //This class provides the interface through which each heater can be controlled
omatthews 30:055d856f05b5 20 public:
omatthews 30:055d856f05b5 21 /** Constructor
omatthews 30:055d856f05b5 22 * @param thermal passes in all the control information needed for the heater
omatthews 30:055d856f05b5 23 * @param i_port is the ADC port relating to the current read
omatthews 30:055d856f05b5 24 * @param v_port is the ADC port relating to the voltage read
omatthews 30:055d856f05b5 25 * @param * drive is a pointer to the main heater
omatthews 30:055d856f05b5 26 * @param * guard is a pointer to the guard heater
omatthews 30:055d856f05b5 27 **/
justinbuckland 35:5acf01897ed6 28 Heater(const int i_port, const int v_port, float cal_a, float cal_b, FastPWM * drive, FastPWM * guard, ADS8568_ADC * adc, DigitalIn adc_busy, const memspcr_ThermalConfiguration & thermal = memspcr_ThermalConfiguration_init_zero);
omatthews 0:4e33cc8171f4 29
justinbuckland 32:34921454e932 30
omatthews 30:055d856f05b5 31 //Public member functions
omatthews 30:055d856f05b5 32
justinbuckland 32:34921454e932 33 void read(); //Updates the resistance and error values for the heater
justinbuckland 32:34921454e932 34 void update(); //Holds R_ref for hold_time miliseconds
omatthews 30:055d856f05b5 35 void turn_on(); //Turns the heater on
omatthews 30:055d856f05b5 36 void turn_off(); //Turns the heater off
omatthews 25:09a315a59956 37
justinbuckland 32:34921454e932 38 //Getters and setters
omatthews 30:055d856f05b5 39 void Set_ref(float R);
omatthews 30:055d856f05b5 40 void Set_D(float D);
justinbuckland 42:166d9bc7675e 41 float Get_D() const;
omatthews 30:055d856f05b5 42 int Get_i() const;
omatthews 30:055d856f05b5 43 int Get_v() const;
omatthews 30:055d856f05b5 44 float Get_R() const;
justinbuckland 42:166d9bc7675e 45 float Get_R_avg();
justinbuckland 45:5f588512529b 46 float Get_R_var();
omatthews 31:7c6f05326c4d 47 float Get_R_ref() const;
omatthews 31:7c6f05326c4d 48 float Get_error() const;
omatthews 31:7c6f05326c4d 49 float Get_error_integrated() const;
omatthews 0:4e33cc8171f4 50
omatthews 30:055d856f05b5 51 protected:
omatthews 16:cd837b230b09 52
omatthews 30:055d856f05b5 53 const memspcr_ThermalConfiguration thermal;
justinbuckland 35:5acf01897ed6 54 int curr; //Latest current reading from ADC
justinbuckland 35:5acf01897ed6 55 int v; //Latest voltage reading from ADC
justinbuckland 35:5acf01897ed6 56 float R; //Latest resistance calculated from ADC current and voltage
justinbuckland 46:47c394467c66 57 float R_smooth; //Smoothed resistance for more noise-tolerant heater control
justinbuckland 46:47c394467c66 58 float R_avg; //Average resistance since last log event
justinbuckland 45:5f588512529b 59 float R_var; //Variance resistance since last log event
justinbuckland 45:5f588512529b 60 float R_acc; //Accumulated sum of resistance values since last log event
justinbuckland 45:5f588512529b 61 float R2_acc; //Accumulated sum of squares of resistance values since last log event
justinbuckland 42:166d9bc7675e 62 int n_acc; //Number of resistance measurements since last log event
justinbuckland 35:5acf01897ed6 63 float R_ref; //Current referance for resistance
justinbuckland 35:5acf01897ed6 64 float error; //R_ref - R
omatthews 30:055d856f05b5 65 float error_integrated; //Integrated error
omatthews 31:7c6f05326c4d 66 ADS8568_ADC * adc;
omatthews 31:7c6f05326c4d 67 DigitalIn adc_busy;
justinbuckland 35:5acf01897ed6 68 int i_port; //ADC port which corresponds to current measurements
justinbuckland 35:5acf01897ed6 69 int v_port; //ADC port which corresponds to voltage measurements
justinbuckland 35:5acf01897ed6 70 float cal_a;
justinbuckland 35:5acf01897ed6 71 float cal_b; //Resistance calibration ADC units to Ohms: R_Ohm = cal_a + cal_b * R_ADC
justinbuckland 35:5acf01897ed6 72 FastPWM * drive; //Pointer to the driver
justinbuckland 35:5acf01897ed6 73 FastPWM * guard; //Pointer to the guard
omatthews 30:055d856f05b5 74
omatthews 0:4e33cc8171f4 75 };
omatthews 30:055d856f05b5 76
omatthews 19:fccdd7127f94 77 #endif