Heater for threaded program
Dependents: LEX_Threaded_Programming
Diff: Heater.cpp
- Revision:
- 26:f6c98b05ee85
- Parent:
- 25:09a315a59956
- Child:
- 27:bb97231d1be9
--- a/Heater.cpp Mon Aug 19 07:55:38 2019 +0000 +++ b/Heater.cpp Tue Aug 27 07:51:30 2019 +0000 @@ -9,18 +9,41 @@ #include "Heater.h" #include "ADS8568_ADC.h" +extern Timer timer; extern ADS8568_ADC adc; -extern Timer timer; extern DigitalIn adc_busy; extern MODSERIAL pc; extern DigitalOut led_0; - +extern FastPWM drive_1; +extern FastPWM drive_2; +extern FastPWM guard_1; +extern FastPWM guard_2; -Heater::Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float corr_grad, const float corr_int, float R_ref) - :R_ref(R_ref),i_port(i_port),v_port(v_port),drive(drive),guard(guard),corr_grad(corr_grad),corr_int(corr_int) {} +Heater::Heater(const memspcr_ThermalConfiguration & thermal) + :thermal(thermal) + { + if (thermal.selected_heater == memspcr_ThermalConfiguration_Heater_MAIN) + { + i_port = 0; + v_port = 1; + drive = & drive_1; + guard = & guard_1; + } + else if (thermal.selected_heater == memspcr_ThermalConfiguration_Heater_LYSIS) + { + i_port = 2; + v_port = 3; + drive = & drive_2; + guard = & guard_2; + } + else pc.printf("Please select the desired heater channel"); + drive->period_ticks(1000); + guard->period_ticks(1000); + } + -void Heater::output()const +void Heater::log()const { //Prints the current state to the terminal pc.printf("%d,%f,%f,%f,%f,%f\n",timer.read_ms(),R_ref,R,error,error_integrated,drive->read()); @@ -29,14 +52,10 @@ void Heater::read() { //Reads R and then resets the drive back to its previous value - - int i = 0; - //float error_prev = error; - + int i = 0; double drive_prev = drive->read(); //Store previous value of drive *drive = 1.0f; //Turn the driver on for the measurement - wait_us(MEAS_DELAY); //Wait for ADC to settle - + wait_us(thermal.adc_settling_time_us); //Wait for ADC to settle adc.start_conversion(15); //Incremental back off until ADC is free @@ -64,6 +83,7 @@ if (abs(error) < WIND_UP_LIMIT) {error_integrated += error;} if (error_integrated < 0.0) {error_integrated = 0.0;} + pc.printf("%f\n",R); } @@ -73,15 +93,8 @@ void Heater::update() { //Update PWM from setpoint and resistance - read(); - drive->write((double) (Kp * (error + error_integrated/Ti))); - guard->write((double) (Kp * GUARD_PWM_RATIO * (error + error_integrated/Ti))); - log_count++; - if (log_count >= LOG_LIM) - { - log_count = 0; - output(); - } + drive->write((double) (thermal.adc_settling_time_us * (error + error_integrated/thermal.pid_integral_time))); + guard->write((double) (thermal.adc_settling_time_us * thermal.guard_drive_ratio * (error + error_integrated/thermal.pid_integral_time))); } @@ -93,7 +106,7 @@ } void Heater::Set_D(float D) { drive->write(D); - guard->write(D*GUARD_PWM_RATIO); + guard->write(D*thermal.guard_drive_ratio); } int Heater::Get_i() const {return curr;} @@ -104,7 +117,7 @@ void Heater::turn_on () { *drive = 1; - *guard = GUARD_PWM_RATIO; + *guard = thermal.guard_drive_ratio; } void Heater::turn_off ()