Commit a5f30c1d authored by Jacques Labaisse's avatar Jacques Labaisse
Browse files

add changing adc trig at each pid computing

parent dbbfda61
......@@ -45,8 +45,8 @@
static float32_t raw_values_adc1[4]={0};
static float32_t raw_values_mult_by_gain_adc1[4]={0};
static float32_t converted_values_adc1[4]={0};
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};
static float32_t gain_adc1[4] = {0.0127, 0.0126, 0.0125, 0}; // These values were measured on N1
static float32_t offset_adc1[4] = {26.35, 25.64, 2017.68, 0};
// ADC2
static float32_t raw_values_adc2[3]={0};
......
......@@ -34,6 +34,7 @@
// Drivers
#include "leg.h" // PWM management layer by inverter leg interface
#include "hrtim.h"
// Application
#include "data_conversion.h"
......@@ -54,14 +55,18 @@
// Local variables
// PID variables
static float32_t Vref;
static float32_t V1_value, Vhigh_value;
static float32_t Iref;
float32_t I1_value, I2_value, Ilow_value;
// float32_t I1_corrected, I2_corrected;
static float32_t Vhigh_value;
float32_t ripple = 0;
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 uint32_t Count_pid_reset; // Counter to reset the PID when calculation is off
static float32_t Load; // The value in ohm of the load to which is the converter connected
static float32_t Vsat; // Represents the minimum input voltage for the entry to suit Iref
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)
......@@ -80,7 +85,7 @@ static uint16_t pwm_period, pwm_phase_shift, pwm_low_pulse_width, pwm_high_pulse
* This function initializes all the parameters
* needed for the PID calculation for the buck topoligy
*/
void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us)
void opalib_pid_voltage_init_buck(float32_t iref, float32_t load, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us)
{
pwm_period = leg_period();
pwm_phase_shift = pwm_period / 2;
......@@ -88,8 +93,10 @@ void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, fl
pwm_high_pulse_width = pwm_period * HIGH_DUTY;
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
Load = load;
Iref = iref;
Vsat = Iref * Load / 0.9;
PID_variables.Kp = kp;
PID_variables.Ki = ki*pid_period_us/1000000.;
......@@ -102,7 +109,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
*/
void opalib_pid_voltage_init_boost(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us)
/*void opalib_pid_voltage_init_boost(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us)
{
pwm_phase_shift = pwm_period / 2;
pwm_low_pulse_width = pwm_period * LOW_DUTY;
......@@ -117,7 +124,7 @@ void opalib_pid_voltage_init_boost(float32_t vref, float32_t kp, float32_t ki, f
PID_variables.Kd = kd;
arm_pid_init_f32(&PID_variables, 1);
}
}*/
/**
......@@ -130,9 +137,22 @@ void opalib_pid_voltage_calculation_and_pwm_update()
data_conversion();
// PID CALCUALTIONS
V1_value = get_value_converted(2 , 0);
I1_value = get_value_converted(1 , 0);
I2_value = get_value_converted(1 , 1);
Vhigh_value = get_value_converted(2 , 2);
arm_sub_f32(&Vref, &V1_value, &error_pid, 1); // CALCULATING THE ERROR BASED ON THE REFERENCE
/*// Ripple estimation
ripple = pid_out * (1 - pid_out) * Vhigh_value * 46 / 100000;
*/
/*// Correct the current values
I1_corrected = I1_value + ripple;
I2_corrected = I2_value + ripple;
*/
arm_add_f32(&I1_value, &I2_value, &Ilow_value, 1);
arm_sub_f32(&Iref, &Ilow_value, &error_pid, 1); // CALCULATING THE ERROR BASED ON THE REFERENCE
if (Vhigh_value > Vsat)
{
......@@ -143,7 +163,7 @@ void opalib_pid_voltage_calculation_and_pwm_update()
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;
pwm_duty_cycle = 0.3;
prev_pid_out = pid_out;
......@@ -154,6 +174,7 @@ void opalib_pid_voltage_calculation_and_pwm_update()
pwm_pulse_width = pwm_high_pulse_width;
leg_set(TIMA, pwm_pulse_width, 0);
leg_set(TIMB, pwm_pulse_width, pwm_phase_shift);
hrtim_update_adc_trig(pwm_pulse_width);
}
else if (pwm_duty_cycle < LOW_DUTY) // SATURATION CONDITIONS TO AVOID DIVERGENCE.
......@@ -162,13 +183,15 @@ void opalib_pid_voltage_calculation_and_pwm_update()
pwm_pulse_width = pwm_low_pulse_width;
leg_set(TIMA, pwm_pulse_width, 0);
leg_set(TIMB, pwm_pulse_width, pwm_phase_shift);
hrtim_update_adc_trig(pwm_pulse_width);
}
else
{
pwm_pulse_width = (pwm_duty_cycle * pwm_period);
leg_set(TIMA, pwm_pulse_width, 0);
leg_set(TIMB, pwm_pulse_width, pwm_phase_shift);
leg_set(TIMB, pwm_pulse_width, pwm_phase_shift);
hrtim_update_adc_trig(pwm_pulse_width);
}
Count_pid_reset = 0;
......
......@@ -40,7 +40,7 @@ extern "C" {
* @param[in] ki ki for PID
* @param[in] kd kd for PID
*/
void opalib_pid_voltage_init_buck(float32_t vref, float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us);
void opalib_pid_voltage_init_buck(float32_t vref, float32_t load,float32_t kp, float32_t ki, float32_t kd, uint32_t task_period_us);
/**
* @brief This function Initialize all the parameters
......
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