Sets ticks directly for heater test

Committer:
seoirsem
Date:
Mon Aug 12 10:41:37 2019 +0000
Revision:
23:65a9f9d85a3a
Parent:
22:2d34a03ae57e
V2 heater set PWM ticks directly;

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 22: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
seoirsem 23:65a9f9d85a3a 19 #define Kp 0.1f //proportional gain
seoirsem 23:65a9f9d85a3a 20 #define Ti 0.2f //Integration time
omatthews 22:2d34a03ae57e 21 #define Kd 0.1f //Differentiator gain
omatthews 22:2d34a03ae57e 22 #define WIND_UP_LIMIT 0.1f //The change in error which turns off the integral term
seoirsem 23:65a9f9d85a3a 23 #define TICK_CYCLE 1000 //the number of tics per duty cycle
omatthews 22:2d34a03ae57e 24 #define LOG_LIM 30 //Number of reads before the result is logged
seoirsem 23:65a9f9d85a3a 25
seoirsem 23:65a9f9d85a3a 26 #define GUARD_PWM_RATIO 21.0/82.0 //Ratio of guard duty cycle to heater duty cycle
omatthews 18:f5d26d3d532f 27
omatthews 0:4e33cc8171f4 28
omatthews 0:4e33cc8171f4 29 class Heater
omatthews 0:4e33cc8171f4 30 {
omatthews 7:59ece353eea2 31 //This class provides the interface through which each heater can be controlled
omatthews 0:4e33cc8171f4 32 public:
omatthews 0:4e33cc8171f4 33 /** Constructor
omatthews 18:f5d26d3d532f 34 * @param i_port, the current port in the ADC
omatthews 18:f5d26d3d532f 35 * @param v_port, the voltage port in the ADC
omatthews 19:fccdd7127f94 36 * @param * drive, a pointer to the heater drive
seoirsem 23:65a9f9d85a3a 37 * @param * guard, a pointer to the guard
seoirsem 23:65a9f9d85a3a 38 * @param * intercept, the gradient of the linear relationship between resistance and temperature
seoirsem 23:65a9f9d85a3a 39 * @param * slope, the intercept of the linear relationship between resistance and temperature
omatthews 18:f5d26d3d532f 40 * @param R_ref (default value 1), optional parameter sets the target value for R
omatthews 18:f5d26d3d532f 41 **/
seoirsem 23:65a9f9d85a3a 42 Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float intercept, const float slope, float R_ref = 1);
omatthews 0:4e33cc8171f4 43
omatthews 0:4e33cc8171f4 44 //Public member functions
omatthews 0:4e33cc8171f4 45
omatthews 18:f5d26d3d532f 46 void read(); //Updates the resistance and error values for the heater
omatthews 18:f5d26d3d532f 47 void hold(const int hold_time); //Holds R_ref for hold_time miliseconds
omatthews 18:f5d26d3d532f 48 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 49 void output() const; //Prints the current state of the heater
omatthews 18:f5d26d3d532f 50 void turn_off(); //Turns the heater off
omatthews 1:4435d407d827 51
omatthews 1:4435d407d827 52
omatthews 2:7f15386fcc90 53 //Getters and setters
omatthews 7:59ece353eea2 54 void Set_R_ref(float R);
omatthews 18:f5d26d3d532f 55 float Get_R() const;
omatthews 7:59ece353eea2 56
omatthews 0:4e33cc8171f4 57
omatthews 0:4e33cc8171f4 58 protected:
omatthews 0:4e33cc8171f4 59
omatthews 0:4e33cc8171f4 60
omatthews 18:f5d26d3d532f 61 int curr; //Latest current reading from ADC
omatthews 18:f5d26d3d532f 62 int v; //Latest voltage reading from ADC
omatthews 18:f5d26d3d532f 63 float R; //Latest resistance calculated from ADC current and voltage
omatthews 18:f5d26d3d532f 64 float R_ref; //Current referance for resistance
omatthews 18:f5d26d3d532f 65 float error; //R_ref - R
seoirsem 23:65a9f9d85a3a 66
seoirsem 23:65a9f9d85a3a 67
omatthews 18:f5d26d3d532f 68 //float error_diff; //Differential error
omatthews 18:f5d26d3d532f 69 float error_integrated; //Integrated error
omatthews 1:4435d407d827 70
omatthews 18:f5d26d3d532f 71 const int i_port; //ADC port which corresponds to current measurements
omatthews 18:f5d26d3d532f 72 const int v_port; //ADC port which corresponds to voltage measurements
seoirsem 23:65a9f9d85a3a 73 const float intercept;
seoirsem 23:65a9f9d85a3a 74 const float slope;
seoirsem 23:65a9f9d85a3a 75
omatthews 18:f5d26d3d532f 76 FastPWM * drive; //Pointer to the driver
omatthews 22:2d34a03ae57e 77 FastPWM * guard; //Pointer to the guard
omatthews 0:4e33cc8171f4 78 };
omatthews 0:4e33cc8171f4 79
omatthews 19:fccdd7127f94 80 #endif