Sets ticks directly for heater test
Diff: Heater.cpp
- Revision:
- 0:4e33cc8171f4
- Child:
- 1:4435d407d827
diff -r 000000000000 -r 4e33cc8171f4 Heater.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Heater.cpp Wed Jul 17 07:54:07 2019 +0000 @@ -0,0 +1,50 @@ +/*------------------------------------------------------------------------------ +Library code file for interface to Heater +Date: 16/07/2018 + + +------------------------------------------------------------------------------*/ + +#include "Heater.h" +#include "ADS8568_ADC.h" + +extern ADS8568_ADC adc; +extern float scale_factors[8]; +extern Timer timer; +extern int MEAS_DELAY; +extern int N_ROLL_AVG; + + +Heater::Heater(int i_port, int v_port, DigitalOut drive, float R_set) + :i_port(i_port),v_port(v_port),drive(drive), R_set(R_set){} + + +void Heater::read_R() +{ + adc.read_channels(); + i = adc.read_channel_result(i_port)/scale_factors[i_port]; + v = adc.read_channel_result(v_port)/scale_factors[v_port]; + if (i != 0) R = v/i; +} + +void Heater::hold(int hold_time) +{ + int end_time = timer.read_ms() + hold_time; + while (int time = timer.read_ms() < end_time) + { + drive = 1; + wait_us(MEAS_DELAY); + read_R(); + while (float R_avg = ((N_ROLL_AVG-1)*R_avg + R)/N_ROLL_AVG > R_set) + { + drive = 0; + wait_us(MEAS_DELAY); + read_R(); + } + } +} + +void Heater::Set_R_set(float R) {R_set = R;} + +float Heater::Get_R() {return R;} +