Heater for threaded program
Dependents: LEX_Threaded_Programming_V3
Diff: Heater.cpp
- Revision:
- 35:5acf01897ed6
- Parent:
- 34:294adcc3e4b2
- Child:
- 36:a8130bd29349
--- a/Heater.cpp Fri Sep 20 14:53:54 2019 +0000 +++ b/Heater.cpp Mon Sep 23 15:41:15 2019 +0000 @@ -9,8 +9,8 @@ #include "Heater.h" #include "ADS8568_ADC.h" -Heater::Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, ADS8568_ADC * adc, DigitalIn adc_busy, const memspcr_ThermalConfiguration & thermal) - :thermal(thermal), i_port(i_port), v_port(v_port), drive(drive), guard(guard), adc(adc), adc_busy(adc_busy) +Heater::Heater(const int i_port, const int v_port, const float cal_a, const float cal_b, FastPWM * drive, FastPWM * guard, ADS8568_ADC * adc, DigitalIn adc_busy, const memspcr_ThermalConfiguration & thermal) + :thermal(thermal), i_port(i_port), v_port(v_port), cal_a(cal_a), cal_b(cal_b), drive(drive), guard(guard), adc(adc), adc_busy(adc_busy) { drive->prescaler(1); guard->prescaler(1); @@ -22,8 +22,8 @@ { //Reads R and then resets the drive back to its previous value int i = 0; - float drive_cal[2] = {0.0, 10.0}; // replace with drive cal passed via Heater class double drive_prev = drive->read(); //Store previous value of drive + *drive = 1.0f; //Turn the driver on for the measurement wait_us(thermal.settling_time_us); //Wait for ADC to settle adc->start_conversion(ADC_CONV_ALL_CH); @@ -41,11 +41,12 @@ curr = adc->read_channel_result(i_port); v = adc->read_channel_result(v_port); - if (curr > 0) { - R = (float)v/curr; //Avoid dividing by 0 - R = drive_cal[0] + drive_cal[1]*R; //Convert to Ohms + if (curr > 0) { //Avoid dividing by 0 + R = (float)v/curr; + R = cal_a + cal_b*R; //Convert to Ohms } - + + //R = cal_b; // for debugging //Get error values error = R_ref - R;