Sets ticks directly for heater test

Files at this revision

API Documentation at this revision

Comitter:
seoirsem
Date:
Mon Aug 12 10:41:37 2019 +0000
Parent:
22:2d34a03ae57e
Commit message:
V2 heater set PWM ticks directly;

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 Aug 07 16:03:27 2019 +0000
+++ b/Heater.cpp	Mon Aug 12 10:41:37 2019 +0000
@@ -18,13 +18,8 @@
 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)
-    :R_ref(R_ref),i_port(i_port),v_port(v_port),drive(drive),guard(guard),corr_grad(corr_grad),corr_int(corr_int) {}
-
-
-// Convert from R to T using the linear relationship - T = R * corr_grad + corr_int
-float Heater::R_to_T(const float R) const {return R*corr_grad + corr_int;}
-float Heater::T_to_R(const float T) const {return (T - corr_int)/corr_grad;}
+Heater::Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float intercept, const float slope, float R_ref)
+    :i_port(i_port),v_port(v_port),drive(drive),guard(guard),intercept(intercept),slope(slope) {}
 
 void Heater::output()const
 {
@@ -79,8 +74,6 @@
 }
 
 
-
-
 void Heater::hold(const int hold_time)
 {
     //Holds the heater at R_ref for the given hold time
@@ -90,8 +83,8 @@
     while (timer.read_ms() < end_time)
     {
         read();
-        drive->write((double) (Kp * (error + error_integrated/Ti)));
-        guard->write((double) (Kp * GUARD_PWM_RATIO * (error + error_integrated/Ti)));
+        drive->period_ticks(floor((double) (Kp * (error + error_integrated/Ti))));
+        guard->period_ticks((double) (Kp * GUARD_PWM_RATIO * (error + error_integrated/Ti)));
         //Output the error every LOG_LIM reads
 
         log_count++;
@@ -125,37 +118,16 @@
     }
     
 }
-    
-void Heater::ramp_T(const int ramp_time, const float T_final, const float T_start) 
-{
-    //Ramps the heater from T_start to T_final for the given hold time
-    //  in: int hold_time - is the time in ms to hold the reference
-    //      float T_final - is the final T_ref value
-    //      float T_start - is the initial T_ref value
-    ramp_R(ramp_time, T_to_R(T_final), T_to_R(T_start));
-}
 
 
-
-void Heater::Set_R_ref(float R) 
+void Heater::Set_R_ref(float R)
 {
     R_ref = R;
     error_integrated = 0;
 }
-void Heater::Set_T_ref(float T_ref) {R_ref = T_to_R(T_ref);}
-void Heater::Set_D(float D) {drive->write(D);}
-
-int Heater::Get_i() const {return curr;}
-int Heater::Get_v() const {return v;}
-
+   
 float Heater::Get_R() const {return R;}
-float Heater::Get_T() const {return R_to_T(R);}
 
-void Heater::turn_on () 
-{
-    *drive = 1;
-    *guard = GUARD_PWM_RATIO;
-}
 
 void Heater::turn_off () 
 {
--- a/Heater.h	Wed Aug 07 16:03:27 2019 +0000
+++ b/Heater.h	Mon Aug 12 10:41:37 2019 +0000
@@ -16,13 +16,14 @@
 
 #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                  0.2f   //proportional gain
-#define Ti                  0.5f       //Integration time
+#define Kp                  0.1f   //proportional gain
+#define Ti                  0.2f       //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 TICK_CYCLE          1000 //the number of tics per 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
+
+#define GUARD_PWM_RATIO     21.0/82.0    //Ratio of guard duty cycle to heater duty cycle
 
 
 class Heater
@@ -33,44 +34,27 @@
                  * @param i_port, the current port in the ADC
                  * @param v_port, the voltage port in the ADC
                  * @param * drive, a pointer to the heater drive
-         * @param * guard, a pointer to the guard
-                 * @param * corr_grad, the gradient of the linear relationship between resistance and temperature
-                 * @param * corr_int, the intercept of the linear relationship between resistance and temperature
+                 * @param * guard, a pointer to the guard
+                 * @param * intercept, the gradient of the linear relationship between resistance and temperature
+                 * @param * slope, the intercept of the linear relationship between resistance and temperature
                  * @param R_ref (default value 1), optional parameter sets the target value for R                 
         **/         
-        Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float corr_grad, const float corr_int, float R_ref = 1);
+        Heater(const int i_port, const int v_port, FastPWM * drive, FastPWM * guard, const float intercept, const float slope, float R_ref = 1);
         
         //Public member functions
 
         void read();            //Updates the resistance and error values for the heater
         void hold(const int hold_time);  //Holds R_ref for hold_time miliseconds
         void ramp_R(const int ramp_time, const float R_final, const float R_start);   //Ramps for ramp_time miliseconds from R_start to R_final
-        void ramp_T(const int ramp_time, const float T_final, const float T_start);   //Same as above but with T (T is in degrees celcius)
         void output() const;  //Prints the current state of the heater
-        void turn_on();     //Turns the heater on
         void turn_off();    //Turns the heater off
-        
-                
-        //Linear conversions between temperature and resistance. Note that temperature is always in celcius
-        float R_to_T(const float R) const;
-        float T_to_R(const float T) const;
 
         
-        
         //Getters and setters
-        void Set_T_ref(float T);
         void Set_R_ref(float R);
-        void Set_D(float D);
-        int Get_i() const;
-        int Get_v() const;
         float Get_R() const;
-        float Get_T() const;
         
         
-
-
-        
-    
     protected:
         
 
@@ -79,18 +63,18 @@
         float R;        //Latest resistance calculated from ADC current and voltage
         float R_ref;    //Current referance for resistance
         float error;    //R_ref - R
+        
+        
         //float error_diff; //Differential error
         float error_integrated; //Integrated error
         
         const int i_port;     //ADC port which corresponds to current measurements
         const int v_port;     //ADC port which corresponds to voltage measurements
+        const float intercept;
+        const float slope;
+        
         FastPWM * drive;    //Pointer to the driver
         FastPWM * guard;    //Pointer to the guard
-
-        //Heater correlations give temperature for a given resistance (assume linear relationship)
-        const float corr_grad;
-        const float corr_int;
-      
 };
     
 #endif
\ No newline at end of file