Commit d7c4fb39 authored by Jean Alinei's avatar Jean Alinei
Browse files

Corrected multiple typos in comment lines.

parent a8639c6c
......@@ -48,34 +48,36 @@
/////
// Defines
// block of values used with the PWM
// Saturation values used for the PWM duty cycle
#define LOW_DUTY 0.1
#define HIGH_DUTY 0.9
/////
// Local variables
static float32_t Vref; // Reference voltage to be tracked
static float32_t V1_value, Vhigh_value; // Measurments variables
static float32_t Vsat; // Represent the minimum voltage required for the entry to suit the Vref
// PID variables
static float32_t Vref;
static float32_t V1_value, Vhigh_value;
static float32_t error_pid;
static arm_pid_instance_f32 PID_variables;
static uint32_t pid_period_us; //The period where the pid is calculated (used for Ki calculation)
static float32_t WindUp_sub, WindUp_mult; // Transition variables for arm calculation of the WindUp
static uint32_t Count_pid_reset; // Counter to reset the PID when calculation is off
static float32_t Vsat; // Represent the minimum voltage required for the entry to suit the Vref
static float32_t pid_out_windUp = 0.1; // stores the current pid output after anti windup and before saturation
static float32_t prev_pid_out = 0.1; // stores the previous unsaturated output
static float32_t pid_out; // stores the current pid_output after saturation and anti windUp (the effective duty cycle)
float32_t Kw = 0.000143; // WindUp Parameter
static arm_pid_instance_f32 PID_variables; // PID structure
static float32_t error_pid; // PID error
static uint32_t pid_period_us; // Period duration of the PID calculation loop in µs (used for Ki calculation)
static float32_t prev_pid_out = 0.1; // Stores the previous unsaturated output
static float32_t pid_out; // Stores the current pid_output after saturation and anti windUp (the effective duty cycle)
static uint32_t Count_pid_reset; // Counter to reset the PID when calculation is off
// Anti-Windup variables
static float32_t pid_out_windUp = 0.1; // Stores the current pid output after anti windup and before saturation
static float32_t WindUp_sub, WindUp_mult; // Transition variables for arm calculation of the WindUp
float32_t Kw = 0.000143; // WindUp Parameter
// PWM variables
static float32_t pwm_duty_cycle = 0.1; // PWM initialization value
static float32_t pwm_duty_cycle = 0.1; // PWM initialization duty cycle value
static uint16_t pwm_pulse_width;
static uint16_t pwm_period, pwm_phase_shift, pwm_low_pulse_width, pwm_high_pulse_width;
/////
// Private functions
......@@ -97,10 +99,10 @@ static void _opalib_pid_init_modules()
data_acquisition_configure_adc_trigger_source(1, LL_ADC_REG_TRIG_EXT_HRTIM_TRG1);
// HRTIM
// High resolution timer initialization
hrtim_init_voltage();
// DAC
// Digital to analog converter initialization (used as a 2.048V voltage reference)
owntech_dac_dac2_constant_init();
}
......@@ -110,7 +112,7 @@ static void _opalib_pid_init_modules()
/**
* This function initializes all the parameters
* needed for the PID calculation for the buck topoligy
* needed for the PID calculation for the buck topology
*/
void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us)
{
......@@ -123,10 +125,11 @@ void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, fl
pid_period_us = task_period_us;
Vref = vref;
Vsat = Vref/0.9; // Calculation of the minimum voltage required for the entry to suit the Vref
Vsat = Vref / HIGH_DUTY; // Calculation of the minimum voltage required for the entry to suit the Vref
float32_t million = 1000000;
PID_variables.Kp = kp;
PID_variables.Ki = ki*pid_period_us/1000000.;
PID_variables.Ki = ki * (pid_period_us / million);
PID_variables.Kd = kd;
arm_pid_init_f32(&PID_variables, 1);
......@@ -137,7 +140,7 @@ void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, fl
/**
* This function initializes all the parameters
* needed for the PID calculation for the boost topoligy
* needed for the PID calculation for the boost topology
*/
void opalib_pid_voltage_init_boost(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us)
{
......@@ -149,10 +152,11 @@ void opalib_pid_voltage_init_boost(float32_t vref, float32_t kp, float32_t ki, f
pid_period_us = task_period_us;
Vref = vref;
Vsat = Vref/(1-0.9); // Calculation of the minimum voltage required for the entry to suit the Vref
Vsat = Vref / (1 - HIGH_DUTY); // Calculation of the minimum voltage required for the entry to suit the Vref
float32_t million = 1000000;
PID_variables.Kp = kp;
PID_variables.Ki = ki*pid_period_us/1000000.;
PID_variables.Ki = ki * (pid_period_us / million);
PID_variables.Kd = kd;
arm_pid_init_f32(&PID_variables, 1);
......@@ -177,7 +181,7 @@ void opalib_pid_voltage_calculation_and_pwm_update()
if (v1_low_count > 0)
{
uint32_t raw_value = v1_low_buffer[v1_low_count-1];
uint32_t raw_value = v1_low_buffer[v1_low_count - 1];
V1_value = data_conversion_convert_v1_low(raw_value);
}
else
......@@ -187,7 +191,7 @@ void opalib_pid_voltage_calculation_and_pwm_update()
if (v_high_count > 0)
{
uint32_t raw_value = v_high_buffer[v_high_count-1];
uint32_t raw_value = v_high_buffer[v_high_count - 1];
Vhigh_value = data_conversion_convert_v_high(raw_value);
}
else
......@@ -195,7 +199,7 @@ void opalib_pid_voltage_calculation_and_pwm_update()
Vhigh_value = 0;
}
// PID CALCUALTIONS
// PID CALCULATIONS
arm_sub_f32(&Vref, &V1_value, &error_pid, 1); // CALCULATING THE ERROR BASED ON THE REFERENCE
if (Vhigh_value > Vsat)
......@@ -206,6 +210,7 @@ void opalib_pid_voltage_calculation_and_pwm_update()
arm_sub_f32(&pwm_duty_cycle, &prev_pid_out, &WindUp_sub, 1);
arm_mult_f32(&WindUp_sub, &Kw, &WindUp_mult, 1);
arm_add_f32(&WindUp_mult, &pid_out, &pid_out_windUp, 1);
PID_variables.state[2] = pid_out_windUp;
pwm_duty_cycle = pid_out_windUp;
prev_pid_out = pid_out;
......
......@@ -32,30 +32,30 @@ extern "C" {
#endif
/**
* @brief This function Initialize all the parameters
* needed for the PID calculation for the buck topoligy
* @brief This function initialize all the parameters
* needed for the PID calculation for the buck topology
*
* @param[in] vref Reference voltage for the PID
* @param[in] kp kp for PID
* @param[in] ki ki for PID
* @param[in] kd kd for PID
* @param[in] kp Proportional gain for PID calculation
* @param[in] ki Integral gain for PID calculation
* @param[in] kd Derivative gain for PID calculation
*/
void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us);
/**
* @brief This function Initialize all the parameters
* needed for the PID calculation for the buck topoligy
* @brief This function initialize all the parameters
* needed for the PID calculation for the boost topology
*
* @param[in] vref Reference voltage for the PID
* @param[in] kp kp for PID
* @param[in] ki ki for PID
* @param[in] kd kd for PID
* @param[in] kp Proportional gain for PID calculation
* @param[in] ki Integral gain for PID calculation
* @param[in] kd Derivative gain for PID calculation
*/
void opalib_pid_voltage_init_boost(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us);
/**
* @brief This function calculation of the PID for the chosen
* topology and set the new duty cycle in the hrtim PWM
* @brief This function does the PID calculation for the chosen
* topology and set the new duty cycle value in the high resolution timer register
*/
void opalib_pid_voltage_calculation_and_pwm_update();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment