Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LEX_Threaded_Programming_V3
Heater.h@45:5f588512529b, 2019-11-16 (annotated)
- Committer:
- justinbuckland
- Date:
- Sat Nov 16 06:05:55 2019 +0000
- Revision:
- 45:5f588512529b
- Parent:
- 42:166d9bc7675e
- Child:
- 46:47c394467c66
Added calculation of variance of resistance measurements
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(); |
| justinbuckland | 45:5f588512529b | 44 | float Get_R_var(); |
| omatthews | 31:7c6f05326c4d | 45 | float Get_R_ref() const; |
| omatthews | 31:7c6f05326c4d | 46 | float Get_error() const; |
| omatthews | 31:7c6f05326c4d | 47 | float Get_error_integrated() const; |
| omatthews | 0:4e33cc8171f4 | 48 | |
| omatthews | 30:055d856f05b5 | 49 | protected: |
| omatthews | 16:cd837b230b09 | 50 | |
| omatthews | 30:055d856f05b5 | 51 | const memspcr_ThermalConfiguration thermal; |
| justinbuckland | 35:5acf01897ed6 | 52 | int curr; //Latest current reading from ADC |
| justinbuckland | 35:5acf01897ed6 | 53 | int v; //Latest voltage reading from ADC |
| justinbuckland | 35:5acf01897ed6 | 54 | float R; //Latest resistance calculated from ADC current and voltage |
| justinbuckland | 42:166d9bc7675e | 55 | float R_avg; //Average resitance since last log event |
| justinbuckland | 45:5f588512529b | 56 | float R_var; //Variance resistance since last log event |
| justinbuckland | 45:5f588512529b | 57 | float R_acc; //Accumulated sum of resistance values since last log event |
| justinbuckland | 45:5f588512529b | 58 | float R2_acc; //Accumulated sum of squares of resistance values since last log event |
| justinbuckland | 42:166d9bc7675e | 59 | int n_acc; //Number of resistance measurements since last log event |
| justinbuckland | 35:5acf01897ed6 | 60 | float R_ref; //Current referance for resistance |
| justinbuckland | 35:5acf01897ed6 | 61 | float error; //R_ref - R |
| omatthews | 30:055d856f05b5 | 62 | float error_integrated; //Integrated error |
| omatthews | 31:7c6f05326c4d | 63 | ADS8568_ADC * adc; |
| omatthews | 31:7c6f05326c4d | 64 | DigitalIn adc_busy; |
| justinbuckland | 35:5acf01897ed6 | 65 | int i_port; //ADC port which corresponds to current measurements |
| justinbuckland | 35:5acf01897ed6 | 66 | int v_port; //ADC port which corresponds to voltage measurements |
| justinbuckland | 35:5acf01897ed6 | 67 | float cal_a; |
| justinbuckland | 35:5acf01897ed6 | 68 | float cal_b; //Resistance calibration ADC units to Ohms: R_Ohm = cal_a + cal_b * R_ADC |
| justinbuckland | 35:5acf01897ed6 | 69 | FastPWM * drive; //Pointer to the driver |
| justinbuckland | 35:5acf01897ed6 | 70 | FastPWM * guard; //Pointer to the guard |
| omatthews | 30:055d856f05b5 | 71 | |
| omatthews | 0:4e33cc8171f4 | 72 | }; |
| omatthews | 30:055d856f05b5 | 73 | |
| omatthews | 19:fccdd7127f94 | 74 | #endif |