Heater for threaded program

Dependents:   LEX_Threaded_Programming

Committer:
omatthews
Date:
Mon Aug 19 07:55:38 2019 +0000
Revision:
25:09a315a59956
Parent:
24:6debc2fb9ff3
Child:
26:f6c98b05ee85
10/08/2019

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 20:2d34a03ae57e 14 #define MEAS_DELAY 60 // measurement delay for ADC in us
omatthews 19:fccdd7127f94 15 #define WAIT_DELAY 3 // wait delay for ADC in ms
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 24:6debc2fb9ff3 19 #define Kp 4.0f //proportional gain
omatthews 24:6debc2fb9ff3 20 #define Ti 0.5f //Integration time
omatthews 20:2d34a03ae57e 21 #define Kd 0.1f //Differentiator gain
omatthews 20:2d34a03ae57e 22 #define WIND_UP_LIMIT 0.1f //The change in error which turns off the integral term
omatthews 19:fccdd7127f94 23 #define PWM_PERIOD 5 //Period of Pwm for the motor in us
omatthews 24:6debc2fb9ff3 24 #define LOG_LIM 10 //Number of reads before the result is logged
omatthews 24:6debc2fb9ff3 25 #define GUARD_PWM_RATIO 0.25 //Ratio of guard duty cycle to heater duty cycle
omatthews 18:f5d26d3d532f 26
omatthews 0:4e33cc8171f4 27
omatthews 0:4e33cc8171f4 28 class Heater
omatthews 0:4e33cc8171f4 29 {
omatthews 7:59ece353eea2 30 //This class provides the interface through which each heater can be controlled
omatthews 0:4e33cc8171f4 31 public:
omatthews 0:4e33cc8171f4 32 /** Constructor
omatthews 18:f5d26d3d532f 33 * @param i_port, the current port in the ADC
omatthews 18:f5d26d3d532f 34 * @param v_port, the voltage port in the ADC
omatthews 19:fccdd7127f94 35 * @param * drive, a pointer to the heater drive
omatthews 19:fccdd7127f94 36 * @param * guard, a pointer to the guard
omatthews 18:f5d26d3d532f 37 * @param * corr_grad, the gradient of the linear relationship between resistance and temperature
omatthews 18:f5d26d3d532f 38 * @param * corr_int, the intercept of the linear relationship between resistance and temperature
omatthews 18:f5d26d3d532f 39 * @param R_ref (default value 1), optional parameter sets the target value for R
omatthews 18:f5d26d3d532f 40 **/
omatthews 25:09a315a59956 41 Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float corr_grad, const float corr_int, float R_ref = 0);
omatthews 0:4e33cc8171f4 42
omatthews 0:4e33cc8171f4 43 //Public member functions
omatthews 0:4e33cc8171f4 44
omatthews 18:f5d26d3d532f 45 void read(); //Updates the resistance and error values for the heater
omatthews 25:09a315a59956 46 void update(); //Holds R_ref for hold_time miliseconds
omatthews 18:f5d26d3d532f 47 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 48 void output() const; //Prints the current state of the heater
omatthews 18:f5d26d3d532f 49 void turn_on(); //Turns the heater on
omatthews 18:f5d26d3d532f 50 void turn_off(); //Turns the heater off
omatthews 7:59ece353eea2 51
omatthews 18:f5d26d3d532f 52
omatthews 25:09a315a59956 53
omatthews 1:4435d407d827 54
omatthews 1:4435d407d827 55
omatthews 2:7f15386fcc90 56
omatthews 2:7f15386fcc90 57 //Getters and setters
omatthews 25:09a315a59956 58 void Set_ref(float R);
omatthews 15:e7838491c104 59 void Set_D(float D);
omatthews 18:f5d26d3d532f 60 int Get_i() const;
omatthews 18:f5d26d3d532f 61 int Get_v() const;
omatthews 18:f5d26d3d532f 62 float Get_R() const;
omatthews 7:59ece353eea2 63
omatthews 0:4e33cc8171f4 64
omatthews 18:f5d26d3d532f 65
omatthews 0:4e33cc8171f4 66
omatthews 0:4e33cc8171f4 67
omatthews 0:4e33cc8171f4 68
omatthews 0:4e33cc8171f4 69 protected:
omatthews 0:4e33cc8171f4 70
omatthews 0:4e33cc8171f4 71
omatthews 18:f5d26d3d532f 72 int curr; //Latest current reading from ADC
omatthews 18:f5d26d3d532f 73 int v; //Latest voltage reading from ADC
omatthews 18:f5d26d3d532f 74 float R; //Latest resistance calculated from ADC current and voltage
omatthews 18:f5d26d3d532f 75 float R_ref; //Current referance for resistance
omatthews 18:f5d26d3d532f 76 float error; //R_ref - R
omatthews 18:f5d26d3d532f 77 //float error_diff; //Differential error
omatthews 18:f5d26d3d532f 78 float error_integrated; //Integrated error
omatthews 1:4435d407d827 79
omatthews 18:f5d26d3d532f 80 const int i_port; //ADC port which corresponds to current measurements
omatthews 18:f5d26d3d532f 81 const int v_port; //ADC port which corresponds to voltage measurements
omatthews 18:f5d26d3d532f 82 FastPWM * drive; //Pointer to the driver
omatthews 20:2d34a03ae57e 83 FastPWM * guard; //Pointer to the guard
omatthews 16:cd837b230b09 84
omatthews 7:59ece353eea2 85 //Heater correlations give temperature for a given resistance (assume linear relationship)
omatthews 18:f5d26d3d532f 86 const float corr_grad;
omatthews 18:f5d26d3d532f 87 const float corr_int;
omatthews 25:09a315a59956 88 int log_count;
omatthews 0:4e33cc8171f4 89
omatthews 0:4e33cc8171f4 90 };
omatthews 0:4e33cc8171f4 91
omatthews 19:fccdd7127f94 92 #endif