Heater files
Dependents: LEX-Demo-Firmware-Logging LEX-Demo-Firmware-Logging
Heater.h@16:cd837b230b09, 2019-07-24 (annotated)
- Committer:
- omatthews
- Date:
- Wed Jul 24 14:29:44 2019 +0000
- Revision:
- 16:cd837b230b09
- Parent:
- 15:e7838491c104
- Child:
- 17:0bfed0e96927
Works quite well - needed to pass by pointer to change duty cycle!
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 | 0:4e33cc8171f4 | 12 | |
omatthews | 14:f266bf960b8d | 13 | #define MEAS_DELAY 80 // measurement delay for ADC |
omatthews | 12:8a048f111140 | 14 | #define WAIT_DELAY 5 // wait delay for ADC |
omatthews | 12:8a048f111140 | 15 | |
omatthews | 16:cd837b230b09 | 16 | #define N_ROLL_AVG 1 // rolling average for R values |
omatthews | 1:4435d407d827 | 17 | #define ALL_CH 15 //value of convst bus to read all chanels simultaneosly |
omatthews | 14:f266bf960b8d | 18 | #define Kd 0.5f //proportional gain |
omatthews | 14:f266bf960b8d | 19 | #define Ki 1.0f //Integrator gain |
omatthews | 0:4e33cc8171f4 | 20 | |
omatthews | 0:4e33cc8171f4 | 21 | class Heater |
omatthews | 0:4e33cc8171f4 | 22 | { |
omatthews | 7:59ece353eea2 | 23 | //This class provides the interface through which each heater can be controlled |
omatthews | 0:4e33cc8171f4 | 24 | public: |
omatthews | 0:4e33cc8171f4 | 25 | /** Constructor |
omatthews | 7:59ece353eea2 | 26 | * @param i_port, the port for the current in the ADC |
omatthews | 7:59ece353eea2 | 27 | * @param v_port, the port for the voltage in the ADC |
omatthews | 7:59ece353eea2 | 28 | * @param drive, the motor drive |
omatthews | 7:59ece353eea2 | 29 | * @param R_ref, the target value for R |
omatthews | 0:4e33cc8171f4 | 30 | */ |
omatthews | 16:cd837b230b09 | 31 | Heater(int i_port, int v_port, PwmOut * drive, float corr_grad, float corr_int, float R_ref = 1); |
omatthews | 0:4e33cc8171f4 | 32 | |
omatthews | 0:4e33cc8171f4 | 33 | //Public member functions |
omatthews | 0:4e33cc8171f4 | 34 | |
omatthews | 2:7f15386fcc90 | 35 | void read(); |
omatthews | 0:4e33cc8171f4 | 36 | void hold(int hold_time); |
omatthews | 7:59ece353eea2 | 37 | void ramp_R(int ramp_time, float R_final, float R_start); |
omatthews | 7:59ece353eea2 | 38 | void ramp_T(int ramp_time, float T_final, float T_start); |
omatthews | 11:785a0329f802 | 39 | void output(); |
omatthews | 7:59ece353eea2 | 40 | |
omatthews | 7:59ece353eea2 | 41 | //Conversions between temperature and resistance |
omatthews | 7:59ece353eea2 | 42 | float R_to_T(float R); |
omatthews | 7:59ece353eea2 | 43 | float T_to_R(float T); |
omatthews | 1:4435d407d827 | 44 | |
omatthews | 1:4435d407d827 | 45 | |
omatthews | 2:7f15386fcc90 | 46 | |
omatthews | 2:7f15386fcc90 | 47 | //Getters and setters |
omatthews | 7:59ece353eea2 | 48 | void Set_T_ref(float T); |
omatthews | 7:59ece353eea2 | 49 | void Set_R_ref(float R); |
omatthews | 15:e7838491c104 | 50 | void Set_D(float D); |
omatthews | 2:7f15386fcc90 | 51 | int Get_i(); |
omatthews | 2:7f15386fcc90 | 52 | int Get_v(); |
omatthews | 0:4e33cc8171f4 | 53 | float Get_R(); |
omatthews | 7:59ece353eea2 | 54 | float Get_T(); |
omatthews | 7:59ece353eea2 | 55 | |
omatthews | 0:4e33cc8171f4 | 56 | |
omatthews | 1:4435d407d827 | 57 | void turn_on(); |
omatthews | 1:4435d407d827 | 58 | void turn_off(); |
omatthews | 0:4e33cc8171f4 | 59 | |
omatthews | 0:4e33cc8171f4 | 60 | |
omatthews | 0:4e33cc8171f4 | 61 | |
omatthews | 0:4e33cc8171f4 | 62 | protected: |
omatthews | 0:4e33cc8171f4 | 63 | |
omatthews | 0:4e33cc8171f4 | 64 | |
omatthews | 2:7f15386fcc90 | 65 | int curr; |
omatthews | 2:7f15386fcc90 | 66 | int v; |
omatthews | 0:4e33cc8171f4 | 67 | float R; |
omatthews | 7:59ece353eea2 | 68 | float R_ref; |
omatthews | 12:8a048f111140 | 69 | float error; |
omatthews | 12:8a048f111140 | 70 | float error_integrated; |
omatthews | 1:4435d407d827 | 71 | |
omatthews | 0:4e33cc8171f4 | 72 | int i_port; |
omatthews | 0:4e33cc8171f4 | 73 | int v_port; |
omatthews | 16:cd837b230b09 | 74 | PwmOut * drive; |
omatthews | 16:cd837b230b09 | 75 | |
omatthews | 7:59ece353eea2 | 76 | //Heater correlations give temperature for a given resistance (assume linear relationship) |
omatthews | 7:59ece353eea2 | 77 | float corr_grad; |
omatthews | 7:59ece353eea2 | 78 | float corr_int; |
omatthews | 0:4e33cc8171f4 | 79 | |
omatthews | 0:4e33cc8171f4 | 80 | }; |
omatthews | 0:4e33cc8171f4 | 81 | |
omatthews | 8:5da71ae16115 | 82 | #endif |
omatthews | 8:5da71ae16115 | 83 |