Heater for threaded program

Dependents:   LEX_Threaded_Programming

Committer:
omatthews
Date:
Wed Jul 17 07:54:07 2019 +0000
Revision:
0:4e33cc8171f4
Child:
1:4435d407d827
First attempt to add in heater

Who changed what in which revision?

UserRevisionLine numberNew contents of line
omatthews 0:4e33cc8171f4 1 /*------------------------------------------------------------------------------
omatthews 0:4e33cc8171f4 2 Library code file for interface to Heater
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 #include "Heater.h"
omatthews 0:4e33cc8171f4 9 #include "ADS8568_ADC.h"
omatthews 0:4e33cc8171f4 10
omatthews 0:4e33cc8171f4 11 extern ADS8568_ADC adc;
omatthews 0:4e33cc8171f4 12 extern float scale_factors[8];
omatthews 0:4e33cc8171f4 13 extern Timer timer;
omatthews 0:4e33cc8171f4 14 extern int MEAS_DELAY;
omatthews 0:4e33cc8171f4 15 extern int N_ROLL_AVG;
omatthews 0:4e33cc8171f4 16
omatthews 0:4e33cc8171f4 17
omatthews 0:4e33cc8171f4 18 Heater::Heater(int i_port, int v_port, DigitalOut drive, float R_set)
omatthews 0:4e33cc8171f4 19 :i_port(i_port),v_port(v_port),drive(drive), R_set(R_set){}
omatthews 0:4e33cc8171f4 20
omatthews 0:4e33cc8171f4 21
omatthews 0:4e33cc8171f4 22 void Heater::read_R()
omatthews 0:4e33cc8171f4 23 {
omatthews 0:4e33cc8171f4 24 adc.read_channels();
omatthews 0:4e33cc8171f4 25 i = adc.read_channel_result(i_port)/scale_factors[i_port];
omatthews 0:4e33cc8171f4 26 v = adc.read_channel_result(v_port)/scale_factors[v_port];
omatthews 0:4e33cc8171f4 27 if (i != 0) R = v/i;
omatthews 0:4e33cc8171f4 28 }
omatthews 0:4e33cc8171f4 29
omatthews 0:4e33cc8171f4 30 void Heater::hold(int hold_time)
omatthews 0:4e33cc8171f4 31 {
omatthews 0:4e33cc8171f4 32 int end_time = timer.read_ms() + hold_time;
omatthews 0:4e33cc8171f4 33 while (int time = timer.read_ms() < end_time)
omatthews 0:4e33cc8171f4 34 {
omatthews 0:4e33cc8171f4 35 drive = 1;
omatthews 0:4e33cc8171f4 36 wait_us(MEAS_DELAY);
omatthews 0:4e33cc8171f4 37 read_R();
omatthews 0:4e33cc8171f4 38 while (float R_avg = ((N_ROLL_AVG-1)*R_avg + R)/N_ROLL_AVG > R_set)
omatthews 0:4e33cc8171f4 39 {
omatthews 0:4e33cc8171f4 40 drive = 0;
omatthews 0:4e33cc8171f4 41 wait_us(MEAS_DELAY);
omatthews 0:4e33cc8171f4 42 read_R();
omatthews 0:4e33cc8171f4 43 }
omatthews 0:4e33cc8171f4 44 }
omatthews 0:4e33cc8171f4 45 }
omatthews 0:4e33cc8171f4 46
omatthews 0:4e33cc8171f4 47 void Heater::Set_R_set(float R) {R_set = R;}
omatthews 0:4e33cc8171f4 48
omatthews 0:4e33cc8171f4 49 float Heater::Get_R() {return R;}
omatthews 0:4e33cc8171f4 50