Heater files
Dependents: LEX-Demo-Firmware-Logging LEX-Demo-Firmware-Logging
Diff: Heater.cpp
- Revision:
- 5:21442d9d19c5
- Parent:
- 4:29ffcc7b410e
--- a/Heater.cpp Thu Jul 18 12:17:42 2019 +0000 +++ b/Heater.cpp Thu Jul 18 15:29:19 2019 +0000 @@ -17,8 +17,12 @@ -Heater::Heater(int i_port, int v_port, DigitalOut drive, float corr_grad, float corr_int, float R_ref) - :R_ref(R_ref),i_port(i_port),v_port(v_port),drive(drive),corr_grad(corr_grad),corr_int(corr_int) {} +Heater::Heater(int i_port, int v_port, PwmOut drive, float corr_grad, float corr_int, float R_ref) + :R_ref(R_ref),i_port(i_port),v_port(v_port),drive(drive),corr_grad(corr_grad),corr_int(corr_int) + { + drive.write(0.0f); + drive.period_ms(16); + } float Heater::R_to_T(float R) {return R*corr_grad + corr_int;} float Heater::T_to_R(float T) {return (T - corr_int)/corr_grad;} @@ -29,16 +33,16 @@ //Reads R and then resets the drive back to its previous value int i = 0; - int drive_prev = drive; //Store previous value of drive - drive = 1; - wait_us(50); //Wait for ADC to settle + float D_prev = drive.read(); + drive.write(1.0); + wait_us(MEAS_DELAY); //Wait for ADC to settle adc.start_conversion(ALL_CH); while(adc_busy == 1) { wait_us(1); i++; } - drive = drive_prev; + drive.write(D_prev); adc.read_channels(); //pc.printf("conversion took %d us\n", i ); @@ -59,20 +63,20 @@ // in: int hold_time - is the time in ms to hold the reference int end_time = timer.read_ms() + hold_time; - float R_avg = 0; + //float R_avg = 0; while (timer.read_ms() < end_time) { read(); - R_avg = ((N_ROLL_AVG-1)*R_avg + R)/N_ROLL_AVG; //Enable rolling average - if (R_avg > R_ref) + //R_avg = ((N_ROLL_AVG-1)*R_avg + R)/N_ROLL_AVG; //Enable rolling average + if (R > R_ref) { - drive = 0; - wait_us(100); //Minimum duty cycle of 10% + drive.write(0.0); + wait_us(400); //Minimum duty cycle of 10% } else { - drive = 1; - //wait_us(20); //Shorter wait time as there is no cost for checking + drive.write(0.0); + wait_us(400); //Shorter wait time as there is no cost for checking } }