Heater for threaded program

Dependents:   LEX_Threaded_Programming

Committer:
omatthews
Date:
Sun Jul 28 11:49:57 2019 +0000
Revision:
18:f5d26d3d532f
Parent:
17:0bfed0e96927
Child:
19:fccdd7127f94
Added in consts

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 0:4e33cc8171f4 13
omatthews 17:0bfed0e96927 14 #define MEAS_DELAY 50 // measurement delay for ADC
omatthews 18:f5d26d3d532f 15 #define WAIT_DELAY 3 // wait delay for ADC
omatthews 12:8a048f111140 16
omatthews 16:cd837b230b09 17 #define N_ROLL_AVG 1 // rolling average for R values
omatthews 1:4435d407d827 18 #define ALL_CH 15 //value of convst bus to read all chanels simultaneosly
omatthews 17:0bfed0e96927 19 #define Kp 30.0f //proportional gain
omatthews 18:f5d26d3d532f 20 #define Ti 1.0f //Integration time
omatthews 17:0bfed0e96927 21 #define Kd 0.0f //Differentiator gain
omatthews 18:f5d26d3d532f 22 #define WIND_UP_LIMIT 0.005f //The change in error which turns off the integral term
omatthews 18:f5d26d3d532f 23 #define PWM_PERIOD 5 //Period of Pwm for the motor
omatthews 18:f5d26d3d532f 24 #define LOG_LIM 100 //Period of Pwm for the motor
omatthews 18:f5d26d3d532f 25
omatthews 0:4e33cc8171f4 26
omatthews 0:4e33cc8171f4 27 class Heater
omatthews 0:4e33cc8171f4 28 {
omatthews 7:59ece353eea2 29 //This class provides the interface through which each heater can be controlled
omatthews 0:4e33cc8171f4 30 public:
omatthews 0:4e33cc8171f4 31 /** Constructor
omatthews 18:f5d26d3d532f 32 * @param i_port, the current port in the ADC
omatthews 18:f5d26d3d532f 33 * @param v_port, the voltage port in the ADC
omatthews 18:f5d26d3d532f 34 * @param * drive, a pointer to the motor drive
omatthews 18:f5d26d3d532f 35 * @param * corr_grad, the gradient of the linear relationship between resistance and temperature
omatthews 18:f5d26d3d532f 36 * @param * corr_int, the intercept of the linear relationship between resistance and temperature
omatthews 18:f5d26d3d532f 37 * @param R_ref (default value 1), optional parameter sets the target value for R
omatthews 18:f5d26d3d532f 38 **/
omatthews 18:f5d26d3d532f 39 Heater(const int i_port, const int v_port, FastPWM * drive, const float corr_grad, const float corr_int, float R_ref = 1);
omatthews 0:4e33cc8171f4 40
omatthews 0:4e33cc8171f4 41 //Public member functions
omatthews 0:4e33cc8171f4 42
omatthews 18:f5d26d3d532f 43 void read(); //Updates the resistance and error values for the heater
omatthews 18:f5d26d3d532f 44 void hold(const int hold_time); //Holds R_ref for hold_time miliseconds
omatthews 18:f5d26d3d532f 45 void ramp_R(const int ramp_time, const float R_final, const float R_start); //Ramps for ramp_time miliseconds from R_start to R_final
omatthews 18:f5d26d3d532f 46 void ramp_T(const int ramp_time, const float T_final, const float T_start); //Same as above but with T
omatthews 18:f5d26d3d532f 47 void output() const; //Prints the current state of the heater
omatthews 18:f5d26d3d532f 48 void turn_on(); //Turns the heater on
omatthews 18:f5d26d3d532f 49 void turn_off(); //Turns the heater off
omatthews 7:59ece353eea2 50
omatthews 18:f5d26d3d532f 51
omatthews 18:f5d26d3d532f 52 //Linear conversions between temperature and resistance
omatthews 18:f5d26d3d532f 53 float R_to_T(const float R) const;
omatthews 18:f5d26d3d532f 54 float T_to_R(const float T) const;
omatthews 1:4435d407d827 55
omatthews 1:4435d407d827 56
omatthews 2:7f15386fcc90 57
omatthews 2:7f15386fcc90 58 //Getters and setters
omatthews 7:59ece353eea2 59 void Set_T_ref(float T);
omatthews 7:59ece353eea2 60 void Set_R_ref(float R);
omatthews 15:e7838491c104 61 void Set_D(float D);
omatthews 18:f5d26d3d532f 62 int Get_i() const;
omatthews 18:f5d26d3d532f 63 int Get_v() const;
omatthews 18:f5d26d3d532f 64 float Get_R() const;
omatthews 18:f5d26d3d532f 65 float Get_T() const;
omatthews 7:59ece353eea2 66
omatthews 0:4e33cc8171f4 67
omatthews 18:f5d26d3d532f 68
omatthews 0:4e33cc8171f4 69
omatthews 0:4e33cc8171f4 70
omatthews 0:4e33cc8171f4 71
omatthews 0:4e33cc8171f4 72 protected:
omatthews 0:4e33cc8171f4 73
omatthews 0:4e33cc8171f4 74
omatthews 18:f5d26d3d532f 75 int curr; //Latest current reading from ADC
omatthews 18:f5d26d3d532f 76 int v; //Latest voltage reading from ADC
omatthews 18:f5d26d3d532f 77 float R; //Latest resistance calculated from ADC current and voltage
omatthews 18:f5d26d3d532f 78 float R_ref; //Current referance for resistance
omatthews 18:f5d26d3d532f 79 float error; //R_ref - R
omatthews 18:f5d26d3d532f 80 //float error_diff; //Differential error
omatthews 18:f5d26d3d532f 81 float error_integrated; //Integrated error
omatthews 1:4435d407d827 82
omatthews 18:f5d26d3d532f 83 const int i_port; //ADC port which corresponds to current measurements
omatthews 18:f5d26d3d532f 84 const int v_port; //ADC port which corresponds to voltage measurements
omatthews 18:f5d26d3d532f 85 FastPWM * drive; //Pointer to the driver
omatthews 16:cd837b230b09 86
omatthews 7:59ece353eea2 87 //Heater correlations give temperature for a given resistance (assume linear relationship)
omatthews 18:f5d26d3d532f 88 const float corr_grad;
omatthews 18:f5d26d3d532f 89 const float corr_int;
omatthews 0:4e33cc8171f4 90
omatthews 0:4e33cc8171f4 91 };
omatthews 0:4e33cc8171f4 92
omatthews 8:5da71ae16115 93 #endif
omatthews 8:5da71ae16115 94