Heater files
Dependents: LEX-Demo-Firmware-Logging LEX-Demo-Firmware-Logging
Revision 22:2d34a03ae57e, committed 2019-08-07
- Comitter:
- omatthews
- Date:
- Wed Aug 07 16:03:27 2019 +0000
- Parent:
- 19:fccdd7127f94
- Commit message:
- Switching over to ticks
Changed in this revision
Heater.cpp | Show annotated file Show diff for this revision Revisions of this file |
Heater.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/Heater.cpp Tue Jul 30 21:32:49 2019 +0000 +++ b/Heater.cpp Wed Aug 07 16:03:27 2019 +0000 @@ -15,7 +15,7 @@ extern MODSERIAL pc; extern int log_count; extern float R_avg; - +extern DigitalOut led_0; 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) @@ -40,9 +40,12 @@ //float error_prev = error; double drive_prev = drive->read(); //Store previous value of drive - drive->period_us(1); //Set period to 1us for the measurement + //drive->period_ticks(15); //Set period to 1us for the measurement + //guard->period_ticks(15); *drive = 1.0f; //Turn the driver on for the measurement + //led_0 = 1; wait_us(MEAS_DELAY); //Wait for ADC to settle + //led_0 = 0; adc.start_conversion(ALL_CH); //Incremental back off until ADC is free while(adc_busy == 1) @@ -50,8 +53,9 @@ wait_us(1); i++; } - drive->write(drive_prev); //Reset the duty cycle back to what it was - drive->period_us(PWM_PERIOD); //Reset the period to what it was + drive->write(0); //Reset the duty cycle back to what it was + //drive->period_ticks(1000); //Reset the period to what it was + //guard->period_ticks(1000); //Get voltage, current and R values from the ADC conversion @@ -69,16 +73,9 @@ //Avoid integral windup by limiting error past actuation saturation (actuator does saturate for any negative error, but to ensure integrated error can decrease, the limit has been set to the negative of the positive limit //if (error*Kp > WIND_UP_LIMIT) {error_integrated += WIND_UP_LIMIT/Kp;} //else if (error*Kp < -WIND_UP_LIMIT) {error_integrated -= WIND_UP_LIMIT/Kp;} - if (error < WIND_UP_LIMIT && error > -WIND_UP_LIMIT) {error_integrated += error;} - - - //Output the error every LOG_LIM reads - log_count++; - if (log_count >= LOG_LIM) - { - log_count = 0; - output(); - } + if (abs(error) < WIND_UP_LIMIT) {error_integrated += error;} + if (error_integrated < -0.0) {error_integrated = -0.0;} + } @@ -95,6 +92,14 @@ read(); drive->write((double) (Kp * (error + error_integrated/Ti))); guard->write((double) (Kp * GUARD_PWM_RATIO * (error + error_integrated/Ti))); + //Output the error every LOG_LIM reads + + log_count++; + if (log_count >= LOG_LIM) + { + log_count = 0; + output(); + } wait_ms(WAIT_DELAY); //Wait before reading again } }
--- a/Heater.h Tue Jul 30 21:32:49 2019 +0000 +++ b/Heater.h Wed Aug 07 16:03:27 2019 +0000 @@ -11,18 +11,18 @@ #include "ADS8568_ADC.h" #include "FastPWM.h" -#define MEAS_DELAY 50 // measurement delay for ADC in us +#define MEAS_DELAY 60 // measurement delay for ADC in us #define WAIT_DELAY 3 // wait delay for ADC in ms #define N_ROLL_AVG 1 // rolling average for R values #define ALL_CH 15 //value of convst bus to read all chanels simultaneosly -#define Kp 30.0f //proportional gain -#define Ti 0.75f //Integration time -#define Kd 0.0f //Differentiator gain -#define WIND_UP_LIMIT 0.01f //The change in error which turns off the integral term +#define Kp 0.2f //proportional gain +#define Ti 0.5f //Integration time +#define Kd 0.1f //Differentiator gain +#define WIND_UP_LIMIT 0.1f //The change in error which turns off the integral term #define PWM_PERIOD 5 //Period of Pwm for the motor in us -#define LOG_LIM 100 //Number of reads before the result is logged -#define GUARD_PWM_RATIO 0.25 //Ratio of guard duty cycle to heater duty cycle +#define LOG_LIM 30 //Number of reads before the result is logged +#define GUARD_PWM_RATIO 0.1 //Ratio of guard duty cycle to heater duty cycle class Heater @@ -85,7 +85,7 @@ const int i_port; //ADC port which corresponds to current measurements const int v_port; //ADC port which corresponds to voltage measurements FastPWM * drive; //Pointer to the driver - FastPWM * guard; //Pointer to the guard + FastPWM * guard; //Pointer to the guard //Heater correlations give temperature for a given resistance (assume linear relationship) const float corr_grad;