Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OwnTech
Power API
OPALIB PID Voltage mode
Commits
d7c4fb39
Commit
d7c4fb39
authored
Oct 27, 2021
by
Jean Alinei
Browse files
Corrected multiple typos in comment lines.
parent
a8639c6c
Changes
2
Hide whitespace changes
Inline
Side-by-side
src/opalib_pid_voltage.c
View file @
d7c4fb39
...
...
@@ -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
floa
t32_t
error_pid
;
static
arm_pid_instance_f32
PID_variables
;
static
uin
t32_t
p
id_period_us
;
//The period whe
re the p
id 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
;
//
s
tores 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
uin
t32_t
pid_period_us
;
// Period duration of the PID calculation loop in µs (used for Ki calculation)
static
floa
t32_t
p
rev_pid_out
=
0
.
1
;
// Sto
re
s
the p
revious 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
;
//
S
tores 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
);
// H
RTIM
// H
igh resolution timer initialization
hrtim_init_voltage
();
// D
AC
// D
igital 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 topol
i
gy
* needed for the PID calculation for the buck topol
o
gy
*/
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 topol
i
gy
* needed for the PID calculation for the boost topol
o
gy
*/
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 CALCU
A
LTIONS
// PID CALCUL
A
TIONS
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
;
...
...
src/opalib_pid_voltage.h
View file @
d7c4fb39
...
...
@@ -32,30 +32,30 @@ extern "C" {
#endif
/**
* @brief This function
I
nitialize all the parameters
* needed for the PID calculation for the buck topol
i
gy
* @brief This function
i
nitialize all the parameters
* needed for the PID calculation for the buck topol
o
gy
*
* @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
I
nitialize all the parameters
* needed for the PID calculation for the b
uck
topol
i
gy
* @brief This function
i
nitialize all the parameters
* needed for the PID calculation for the b
oost
topol
o
gy
*
* @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 h
rtim PWM
* @brief This function
does the PID
calculation for the chosen
* topology and set the new duty cycle
value
in the h
igh resolution timer register
*/
void
opalib_pid_voltage_calculation_and_pwm_update
();
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment