Heater for threaded program

Dependents:   LEX_Threaded_Programming

Committer:
omatthews
Date:
Thu Jul 25 16:20:01 2019 +0000
Revision:
17:0bfed0e96927
Parent:
16:cd837b230b09
Child:
18:f5d26d3d532f
Working pretty well

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 12:8a048f111140 15 #define WAIT_DELAY 5 // 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 17:0bfed0e96927 20 #define Ti 2 //Integration time
omatthews 17:0bfed0e96927 21 #define Kd 0.0f //Differentiator gain
omatthews 17:0bfed0e96927 22 #define WIND_UP_LIMIT 0.006f //Avoids integral windup on a sharp drop in T_ref
omatthews 17:0bfed0e96927 23 #define PWM_PERIOD 50
omatthews 0:4e33cc8171f4 24
omatthews 0:4e33cc8171f4 25 class Heater
omatthews 0:4e33cc8171f4 26 {
omatthews 7:59ece353eea2 27 //This class provides the interface through which each heater can be controlled
omatthews 0:4e33cc8171f4 28 public:
omatthews 0:4e33cc8171f4 29 /** Constructor
omatthews 7:59ece353eea2 30 * @param i_port, the port for the current in the ADC
omatthews 7:59ece353eea2 31 * @param v_port, the port for the voltage in the ADC
omatthews 7:59ece353eea2 32 * @param drive, the motor drive
omatthews 7:59ece353eea2 33 * @param R_ref, the target value for R
omatthews 0:4e33cc8171f4 34 */
omatthews 17:0bfed0e96927 35 Heater(int i_port, int v_port, FastPWM * drive, float corr_grad, float corr_int, float R_ref = 1);
omatthews 0:4e33cc8171f4 36
omatthews 0:4e33cc8171f4 37 //Public member functions
omatthews 0:4e33cc8171f4 38
omatthews 2:7f15386fcc90 39 void read();
omatthews 0:4e33cc8171f4 40 void hold(int hold_time);
omatthews 7:59ece353eea2 41 void ramp_R(int ramp_time, float R_final, float R_start);
omatthews 7:59ece353eea2 42 void ramp_T(int ramp_time, float T_final, float T_start);
omatthews 11:785a0329f802 43 void output();
omatthews 7:59ece353eea2 44
omatthews 7:59ece353eea2 45 //Conversions between temperature and resistance
omatthews 7:59ece353eea2 46 float R_to_T(float R);
omatthews 7:59ece353eea2 47 float T_to_R(float T);
omatthews 1:4435d407d827 48
omatthews 1:4435d407d827 49
omatthews 2:7f15386fcc90 50
omatthews 2:7f15386fcc90 51 //Getters and setters
omatthews 7:59ece353eea2 52 void Set_T_ref(float T);
omatthews 7:59ece353eea2 53 void Set_R_ref(float R);
omatthews 15:e7838491c104 54 void Set_D(float D);
omatthews 2:7f15386fcc90 55 int Get_i();
omatthews 2:7f15386fcc90 56 int Get_v();
omatthews 0:4e33cc8171f4 57 float Get_R();
omatthews 7:59ece353eea2 58 float Get_T();
omatthews 7:59ece353eea2 59
omatthews 0:4e33cc8171f4 60
omatthews 1:4435d407d827 61 void turn_on();
omatthews 1:4435d407d827 62 void turn_off();
omatthews 0:4e33cc8171f4 63
omatthews 0:4e33cc8171f4 64
omatthews 0:4e33cc8171f4 65
omatthews 0:4e33cc8171f4 66 protected:
omatthews 0:4e33cc8171f4 67
omatthews 0:4e33cc8171f4 68
omatthews 2:7f15386fcc90 69 int curr;
omatthews 2:7f15386fcc90 70 int v;
omatthews 0:4e33cc8171f4 71 float R;
omatthews 7:59ece353eea2 72 float R_ref;
omatthews 12:8a048f111140 73 float error;
omatthews 17:0bfed0e96927 74 float error_diff;
omatthews 12:8a048f111140 75 float error_integrated;
omatthews 1:4435d407d827 76
omatthews 0:4e33cc8171f4 77 int i_port;
omatthews 0:4e33cc8171f4 78 int v_port;
omatthews 17:0bfed0e96927 79 FastPWM * drive;
omatthews 16:cd837b230b09 80
omatthews 7:59ece353eea2 81 //Heater correlations give temperature for a given resistance (assume linear relationship)
omatthews 7:59ece353eea2 82 float corr_grad;
omatthews 7:59ece353eea2 83 float corr_int;
omatthews 0:4e33cc8171f4 84
omatthews 0:4e33cc8171f4 85 };
omatthews 0:4e33cc8171f4 86
omatthews 8:5da71ae16115 87 #endif
omatthews 8:5da71ae16115 88