Heater for threaded program
Dependents: LEX_Threaded_Programming_V3
Heater.h@42:166d9bc7675e, 2019-10-17 (annotated)
- Committer:
- justinbuckland
- Date:
- Thu Oct 17 10:29:13 2019 +0000
- Revision:
- 42:166d9bc7675e
- Parent:
- 35:5acf01897ed6
- Child:
- 45:5f588512529b
Added R_avg calc and fixed Get_D to return float
Who changed what in which revision?
User | Revision | Line number | New 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 | |
omatthews | 0:4e33cc8171f4 | 15 | class Heater |
omatthews | 0:4e33cc8171f4 | 16 | { |
omatthews | 7:59ece353eea2 | 17 | //This class provides the interface through which each heater can be controlled |
omatthews | 30:055d856f05b5 | 18 | public: |
omatthews | 30:055d856f05b5 | 19 | /** Constructor |
omatthews | 30:055d856f05b5 | 20 | * @param thermal passes in all the control information needed for the heater |
omatthews | 30:055d856f05b5 | 21 | * @param i_port is the ADC port relating to the current read |
omatthews | 30:055d856f05b5 | 22 | * @param v_port is the ADC port relating to the voltage read |
omatthews | 30:055d856f05b5 | 23 | * @param * drive is a pointer to the main heater |
omatthews | 30:055d856f05b5 | 24 | * @param * guard is a pointer to the guard heater |
omatthews | 30:055d856f05b5 | 25 | **/ |
justinbuckland | 35:5acf01897ed6 | 26 | 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 | 27 | |
justinbuckland | 32:34921454e932 | 28 | |
omatthews | 30:055d856f05b5 | 29 | //Public member functions |
omatthews | 30:055d856f05b5 | 30 | |
justinbuckland | 32:34921454e932 | 31 | void read(); //Updates the resistance and error values for the heater |
justinbuckland | 32:34921454e932 | 32 | void update(); //Holds R_ref for hold_time miliseconds |
omatthews | 30:055d856f05b5 | 33 | void turn_on(); //Turns the heater on |
omatthews | 30:055d856f05b5 | 34 | void turn_off(); //Turns the heater off |
omatthews | 25:09a315a59956 | 35 | |
justinbuckland | 32:34921454e932 | 36 | //Getters and setters |
omatthews | 30:055d856f05b5 | 37 | void Set_ref(float R); |
omatthews | 30:055d856f05b5 | 38 | void Set_D(float D); |
justinbuckland | 42:166d9bc7675e | 39 | float Get_D() const; |
omatthews | 30:055d856f05b5 | 40 | int Get_i() const; |
omatthews | 30:055d856f05b5 | 41 | int Get_v() const; |
omatthews | 30:055d856f05b5 | 42 | float Get_R() const; |
justinbuckland | 42:166d9bc7675e | 43 | float Get_R_avg(); |
omatthews | 31:7c6f05326c4d | 44 | float Get_R_ref() const; |
omatthews | 31:7c6f05326c4d | 45 | float Get_error() const; |
omatthews | 31:7c6f05326c4d | 46 | float Get_error_integrated() const; |
omatthews | 0:4e33cc8171f4 | 47 | |
omatthews | 30:055d856f05b5 | 48 | protected: |
omatthews | 16:cd837b230b09 | 49 | |
omatthews | 30:055d856f05b5 | 50 | const memspcr_ThermalConfiguration thermal; |
justinbuckland | 35:5acf01897ed6 | 51 | int curr; //Latest current reading from ADC |
justinbuckland | 35:5acf01897ed6 | 52 | int v; //Latest voltage reading from ADC |
justinbuckland | 35:5acf01897ed6 | 53 | float R; //Latest resistance calculated from ADC current and voltage |
justinbuckland | 42:166d9bc7675e | 54 | float R_avg; //Average resitance since last log event |
justinbuckland | 42:166d9bc7675e | 55 | float R_acc; //Accumulated sum of resistance vaules since last log event |
justinbuckland | 42:166d9bc7675e | 56 | int n_acc; //Number of resistance measurements since last log event |
justinbuckland | 35:5acf01897ed6 | 57 | float R_ref; //Current referance for resistance |
justinbuckland | 35:5acf01897ed6 | 58 | float error; //R_ref - R |
omatthews | 30:055d856f05b5 | 59 | float error_integrated; //Integrated error |
omatthews | 31:7c6f05326c4d | 60 | ADS8568_ADC * adc; |
omatthews | 31:7c6f05326c4d | 61 | DigitalIn adc_busy; |
justinbuckland | 35:5acf01897ed6 | 62 | int i_port; //ADC port which corresponds to current measurements |
justinbuckland | 35:5acf01897ed6 | 63 | int v_port; //ADC port which corresponds to voltage measurements |
justinbuckland | 35:5acf01897ed6 | 64 | float cal_a; |
justinbuckland | 35:5acf01897ed6 | 65 | float cal_b; //Resistance calibration ADC units to Ohms: R_Ohm = cal_a + cal_b * R_ADC |
justinbuckland | 35:5acf01897ed6 | 66 | FastPWM * drive; //Pointer to the driver |
justinbuckland | 35:5acf01897ed6 | 67 | FastPWM * guard; //Pointer to the guard |
omatthews | 30:055d856f05b5 | 68 | |
omatthews | 0:4e33cc8171f4 | 69 | }; |
omatthews | 30:055d856f05b5 | 70 | |
omatthews | 19:fccdd7127f94 | 71 | #endif |