Heater for threaded program

Dependents:   LEX_Threaded_Programming

Heater.h

Committer:
omatthews
Date:
2019-07-25
Revision:
17:0bfed0e96927
Parent:
16:cd837b230b09
Child:
18:f5d26d3d532f

File content as of revision 17:0bfed0e96927:

/*------------------------------------------------------------------------------
Library header file for heater operations
Date: 16/07/2018


------------------------------------------------------------------------------*/

#ifndef Heater_H
#define Heater_H
#include "mbed.h"
#include "ADS8568_ADC.h"
#include "FastPWM.h"

#define MEAS_DELAY          50     // measurement delay for ADC
#define WAIT_DELAY          5      // wait delay for ADC

#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                  2       //Integration time
#define Kd                  0.0f   //Differentiator gain
#define WIND_UP_LIMIT       0.006f //Avoids integral windup on a sharp drop in T_ref
#define PWM_PERIOD          50     

class Heater
{
    //This class provides the interface through which each heater can be controlled
    public:
        /** Constructor
                 * @param i_port, the port for the current in the ADC
                 * @param v_port, the port for the voltage in the ADC
                 * @param drive, the motor drive
                 * @param R_ref, the target value for R
                 */
        Heater(int i_port, int v_port, FastPWM * drive, float corr_grad, float corr_int, float R_ref = 1);
        
        //Public member functions

        void read();
        void hold(int hold_time);
        void ramp_R(int ramp_time, float R_final, float R_start);
        void ramp_T(int ramp_time, float T_final, float T_start);
        void output();
        
        //Conversions between temperature and resistance
        float R_to_T(float R);
        float T_to_R(float T);

        
        
        //Getters and setters
        void Set_T_ref(float T);
        void Set_R_ref(float R);
        void Set_D(float D);
        int Get_i();
        int Get_v();
        float Get_R();
        float Get_T();
        
        
        void turn_on();
        void turn_off();

        
    
    protected:
        

        int curr;
        int v;
        float R;
        float R_ref;
        float error;
        float error_diff;
        float error_integrated;
        
        int i_port;
        int v_port;
        FastPWM * drive;

        //Heater correlations give temperature for a given resistance (assume linear relationship)
        float corr_grad;
        float corr_int;
      
};
    
#endif