Introduction
OwnTech Power API Library PID provides a simple PID control for buck and boost in voltage mode.
This library automatically configures the driver modules required for the OwnTech Power Converter to work.
How to use
Enable the library
To enable the library, just uncomment the pid_voltage
library in src/owntech.ini
.
Then, include the library header in main.cpp
:
Memo: the standalone PID library configuration is as follows:
pid_voltage=https://gitlab.laas.fr/owntech/power-api/opalib-pid.git
Using OPALIB PID Voltage
- Add the following line to your main:
#include "opalib_pid_voltage.h"
. - Configure the core modules, e.g. using OPALIB Quick Start's init voltage function at the beginning of your
main()
. - Initialize the pid peripheral with
opalib_pid_voltage_init_buck()
oropalib_pid_voltage_init_boost()
depending on the converter topology. - Run the PID calculation with
opalib_pid_voltage_calculation_and_pwm_update()
in order to update the duty cycle in the PWM.
/**
* @brief This function Initialize all the parameters
* needed for the PID calculation for the buck topoligy
*
* @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] task_period_us Period of the 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
*
* @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] task_period_us Period of the 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
*/
void opalib_pid_voltage_calculation_and_pwm_update();
Depending on the chosen conversion topology, the controlled switch will be different.
Requirement
- The value of
task_period_us
must be the same value as the user task period used foropalib_quick_start
.
Example of library use in combination with Library Quick start
#include "opalib_quick_start.h"
#include "opalib_pid_voltage.h"
void main(void)
{
opalib_quick_start_init_voltage(opalib_pid_voltage_calculation_and_pwm_update, 50);
opalib_pid_voltage_init_buck(12, 0.000215, 2.86, 0, 50);
opalib_quick_start_launch_task();
}
How to tweak the pid configuration ?
- Open the
opalib_pid_voltage.c
file$(PROJECTDIR)/src/
- Modify
GainADC1
,offsetADC1
,GainADC2
andoffsetADC2
to change and calibrate the conversion of the ADC if the values converted are not coherent.
Library structure
$(PROJECTDIR)/src/
opalib_pid_voltage.c
Main source fileopalib_pid_voltage.h
List of public functions implemented in librarydata_conversion.c
Internal use onlydata_conversion.h
Internal use only