Heater files
Dependents: LEX-Demo-Firmware-Logging LEX-Demo-Firmware-Logging
Heater.cpp
- Committer:
- omatthews
- Date:
- 2019-07-17
- Revision:
- 0:4e33cc8171f4
- Child:
- 1:4435d407d827
File content as of revision 0:4e33cc8171f4:
/*------------------------------------------------------------------------------ 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;}