Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LEX-Demo-Firmware-Logging LEX-Demo-Firmware-Logging
Revision 16:cd837b230b09, committed 2019-07-24
- Comitter:
- omatthews
- Date:
- Wed Jul 24 14:29:44 2019 +0000
- Parent:
- 15:e7838491c104
- Child:
- 17:0bfed0e96927
- Commit message:
- Works quite well - needed to pass by pointer to change duty cycle!
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 Wed Jul 24 09:47:45 2019 +0000
+++ b/Heater.cpp Wed Jul 24 14:29:44 2019 +0000
@@ -19,7 +19,7 @@
-Heater::Heater(int i_port, int v_port, PwmOut drive, float corr_grad, float corr_int, float R_ref)
+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) {}
float Heater::R_to_T(float R) {return R*corr_grad + corr_int;}
@@ -27,7 +27,7 @@
void Heater::output()
{
- pc.printf("%d,%f,%f,%f,%f\n",timer.read_ms(),R_ref,R,R_avg,drive.read());
+ pc.printf("%d,%f,%f,%f,%f\n",timer.read_ms(),R_ref,R,R_avg,drive->read());
}
void Heater::read()
@@ -35,8 +35,8 @@
//Reads R and then resets the drive back to its previous value
int i = 0;
- float drive_prev = drive.read(); //Store previous value of drive
- drive = 1;
+ float drive_prev = drive->read(); //Store previous value of drive
+ *drive = 1;
wait_us(MEAS_DELAY); //Wait for ADC to settle
adc.start_conversion(ALL_CH);
while(adc_busy == 1)
@@ -44,7 +44,7 @@
wait_us(1);
i++;
}
- drive.write(drive_prev);
+ drive->write(drive_prev);
adc.read_channels();
@@ -88,7 +88,7 @@
{
read();
- drive.write(Kd * error + Ki * error_integrated);
+ drive->write(Kd * error + Ki * error_integrated);
wait_ms(WAIT_DELAY); //Minimum duty cycle of 1%
//pc.printf("%f,%f,%f\n",error,error_integrated,drive.read());
@@ -119,7 +119,8 @@
}
void Heater::Set_R_ref(float R) {R_ref = R;}
void Heater::Set_T_ref(float T_ref) {R_ref = T_to_R(T_ref);}
-void Heater::Set_D(float D) {drive.write(D);}
+
+void Heater::Set_D(float D) {drive->write(D);}
int Heater::Get_i() {return curr;}
int Heater::Get_v() {return v;}
@@ -127,6 +128,6 @@
float Heater::Get_R() {return R;}
float Heater::Get_T() {return R_to_T(R);}
-void Heater::turn_on () {drive = 1;}
+void Heater::turn_on () {*drive = 1;}
-void Heater::turn_off () {drive = 0;}
+void Heater::turn_off () {*drive = 0;}
--- a/Heater.h Wed Jul 24 09:47:45 2019 +0000
+++ b/Heater.h Wed Jul 24 14:29:44 2019 +0000
@@ -13,7 +13,7 @@
#define MEAS_DELAY 80 // measurement delay for ADC
#define WAIT_DELAY 5 // wait delay for ADC
-#define N_ROLL_AVG 3 // rolling average for R values
+#define N_ROLL_AVG 1 // rolling average for R values
#define ALL_CH 15 //value of convst bus to read all chanels simultaneosly
#define Kd 0.5f //proportional gain
#define Ki 1.0f //Integrator gain
@@ -28,7 +28,7 @@
* @param drive, the motor drive
* @param R_ref, the target value for R
*/
- Heater(int i_port, int v_port, PwmOut drive, float corr_grad, float corr_int, float R_ref = 1);
+ Heater(int i_port, int v_port, PwmOut * drive, float corr_grad, float corr_int, float R_ref = 1);
//Public member functions
@@ -71,8 +71,8 @@
int i_port;
int v_port;
- PwmOut drive;
-
+ PwmOut * drive;
+
//Heater correlations give temperature for a given resistance (assume linear relationship)
float corr_grad;
float corr_int;