Commit eade9bb6 authored by Clément Foucher's avatar Clément Foucher Committed by Clément Foucher
Browse files

Parameters Kp, Ki and Kd as parameters.

Corrected indentation and comments.
parent e7d6de84
......@@ -39,16 +39,16 @@
/////
// Local variables
//ADC convertions variable
// ADC convertions variable
//ADC1
// ADC1
static float32_t raw_values_adc1[4];
static float32_t raw_values_offset_removed_adc1[4];
static float32_t converted_values_adc1[4];
static float32_t gain_adc1[4] = {0.0125, 0.0107, 0.0125, 0};
static float32_t offset_adc1[4] = {2030.88, 2029.065, 2017.68, 0};
//ADC2
// ADC2
static float32_t raw_values_adc2[3];
static float32_t raw_values_offset_removed_adc2[3];
static float32_t converted_values_adc2[3];
......@@ -59,7 +59,7 @@ static float32_t offset_adc2_triple_linearization[3] = {2036.583, 1834.98, 2160.
/////
// Public Functions
// Private Functions
/**
* This function select the right conversion equation
......@@ -103,7 +103,7 @@ void data_conversion()
(data_dispatch_get_values_available_in_adc2_channel(1)!=0) &&
(data_dispatch_get_values_available_in_adc2_channel(2)!=0) )
{
//Data gathering from the buffer and conversion to float for PID calculation
// Data gathering from the buffer and conversion to float for PID calculation
raw_values_adc1[0] = (float32_t)data_dispatch_get_next_value_from_adc1_channel(0);
raw_values_adc1[1] = (float32_t)data_dispatch_get_next_value_from_adc1_channel(1);
raw_values_adc1[2] = (float32_t)data_dispatch_get_next_value_from_adc1_channel(2);
......@@ -111,16 +111,16 @@ void data_conversion()
raw_values_adc2[1] = (float32_t)data_dispatch_get_next_value_from_adc2_channel(1);
raw_values_adc2[2] = (float32_t)data_dispatch_get_next_value_from_adc2_channel(2);
//Update of the linearization depending of the value
triple_linerarization(raw_values_adc2[0], 0);
triple_linerarization(raw_values_adc2[1], 1);
// Update of the linearization depending of the value
triple_linerarization(raw_values_adc2[0], 0);
triple_linerarization(raw_values_adc2[1], 1);
//Conversion of the raw ADC value in volt and ampere
// Conversion of the raw ADC value in volt and ampere
arm_sub_f32(raw_values_adc1, offset_adc1, raw_values_offset_removed_adc1, 4);
arm_sub_f32(raw_values_adc2, offset_adc2, raw_values_offset_removed_adc2, 3);
arm_mult_f32(raw_values_offset_removed_adc1, gain_adc1, converted_values_adc1, 4);
arm_mult_f32(raw_values_offset_removed_adc2, gain_adc2, converted_values_adc2, 3);
}
}
}
/**
......@@ -128,13 +128,13 @@ void data_conversion()
*/
float32_t get_value_converted(uint8_t adc_number, uint8_t adc_channel)
{
if (adc_number == 1)
{
return converted_values_adc1[adc_channel];
}
else if (adc_number == 2)
{
return converted_values_adc2[adc_channel];
}
}
\ No newline at end of file
if (adc_number == 1)
{
return converted_values_adc1[adc_channel];
}
else if (adc_number == 2)
{
return converted_values_adc2[adc_channel];
}
}
......@@ -58,17 +58,14 @@
/////
// Local variables
//PID variables
static float32_t Vref = 10;
// PID variables
static float32_t Vref;
static float32_t V1_value;
static float32_t error_pid;
static float32_t Kpgain; //Buck application gains calculated via matlab
static float32_t Kigain;
static float32_t Kdgain;
static arm_pid_instance_f32 PID_variables;
//PWM variables
static float32_t pwm_duty_cycle = 0.1; // pwm initialization value
// PWM variables
static float32_t pwm_duty_cycle = 0.1; // PWM initialization value
static uint16_t pwm_pulse_width;
static uint16_t pwm_period, pwm_phase_shift, pwm_low_pulse_width, pwm_high_pulse_width;
......@@ -77,45 +74,42 @@ static uint16_t pwm_period, pwm_phase_shift, pwm_low_pulse_width, pwm_high_pulse
// Public Functions
/**
* This function Initialize all the parameters
* This function initializes all the parameters
* needed for the PID calculation for the buck topoligy
*/
void pid_init_buck()
void pid_init_buck(float32_t vref, float32_t kp, float32_t ki, float32_t kd)
{
pwm_period = leg_period();
pwm_phase_shift = pwm_period / 2;
pwm_low_pulse_width = pwm_period * LOW_DUTY;
pwm_high_pulse_width = pwm_period * HIGH_DUTY;
Kpgain = -0.00000235; //Buck application gains calculated via matlab
Kigain = -0.117;
Kdgain = 0;
Vref = vref;
PID_variables.Kp = Kpgain;
PID_variables.Ki = Kigain;
PID_variables.Kd = Kdgain;
arm_pid_init_f32(&PID_variables,1);
PID_variables.Kp = kp;
PID_variables.Ki = ki;
PID_variables.Kd = kd;
arm_pid_init_f32(&PID_variables, 1);
}
/**
* This function Initialize all the parameters
* This function initializes all the parameters
* needed for the PID calculation for the boost topoligy
*/
//NOTE: all the gain are set for the buck topology, they must be changed
void pid_init_boost()
void pid_init_boost(float32_t vref, float32_t kp, float32_t ki, float32_t kd)
{
pwm_phase_shift = pwm_period / 2;
pwm_low_pulse_width = pwm_period * LOW_DUTY;
pwm_high_pulse_width = pwm_period * HIGH_DUTY;
Kpgain = 0; //Boost application gains to be calculated
Kigain = 0;
Kdgain = 0;
Vref = vref;
PID_variables.Kp = kp;
PID_variables.Ki = ki;
PID_variables.Kd = kd;
PID_variables.Kp = Kpgain;
PID_variables.Ki = Kigain;
PID_variables.Kd = Kdgain;
arm_pid_init_f32(&PID_variables,1);
arm_pid_init_f32(&PID_variables, 1);
}
......@@ -125,20 +119,20 @@ void pid_init_boost()
*/
void pid_calculation_and_pwm_update()
{
//PID CALCUALTIONS
// PID CALCUALTIONS
V1_value = get_value_converted(2 , 0);
arm_sub_f32(&V1_value, &Vref, &error_pid,1); //CALCULATING THE ERROR BASED ON THE REFERENCE
pwm_duty_cycle = arm_pid_f32(&PID_variables, 0.01*error_pid); //PID CALCULATIONS
arm_sub_f32(&V1_value, &Vref, &error_pid, 1); // CALCULATING THE ERROR BASED ON THE REFERENCE
pwm_duty_cycle = arm_pid_f32(&PID_variables, 0.01*error_pid); // PID CALCULATIONS
//TESTING PWM VALUE TO AVOID OVERFLOW AND PWM UPDATE//
if (pwm_duty_cycle > HIGH_DUTY) //SATURATION CONDITIONS TO AVOID DIVERGENCE.
// TESTING PWM VALUE TO AVOID OVERFLOW AND PWM UPDATE//
if (pwm_duty_cycle > HIGH_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE.
{
pwm_pulse_width = pwm_high_pulse_width;
leg_set(TIMA, pwm_pulse_width, 0);
leg_set(TIMB, pwm_pulse_width, pwm_phase_shift);
}
else if (pwm_duty_cycle < LOW_DUTY) //SATURATION CONDITIONS TO AVOID DIVERGENCE.
else if (pwm_duty_cycle < LOW_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE.
{
pwm_pulse_width = pwm_low_pulse_width;
leg_set(TIMA, pwm_pulse_width, 0);
......@@ -151,4 +145,4 @@ void pid_calculation_and_pwm_update()
leg_set(TIMA, pwm_pulse_width, 0);
leg_set(TIMB, pwm_pulse_width, pwm_phase_shift);
}
}
\ No newline at end of file
}
......@@ -35,13 +35,13 @@ extern "C" {
* @brief This function Initialize all the parameters
* needed for the PID calculation for the buck topoligy
*/
void pid_init_buck();
void pid_init_buck(float32_t Kp, float32_t Ki, float32_t Kd);
/**
* @brief This function Initialize all the parameters
* needed for the PID calculation for the buck topoligy
*/
void pid_init_boost();
void pid_init_boost(float32_t Kp, float32_t Ki, float32_t Kd);
/**
* @brief This function calculation of the PID for the chosen
......
Markdown is supported
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