Merged in raiden00/nuttx (pull request #651)
stm32f334-disco/buckboost: use a PID controller from libdsp * libdsp: initial commit * libdsp: cosmetics * stm32f334-disco/buckboost: use a PID controller from libdsp Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
parent
e0aa6ed48c
commit
a002238898
@ -34,6 +34,7 @@ CONFIG_FDCLONE_STDIO=y
|
||||
CONFIG_INTELHEX_BINARY=y
|
||||
CONFIG_LIBC_FLOATINGPOINT=y
|
||||
CONFIG_LIBM=y
|
||||
CONFIG_LIBDSP=y
|
||||
CONFIG_MAX_TASKS=4
|
||||
CONFIG_MAX_WDOGPARMS=1
|
||||
CONFIG_NAME_MAX=16
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <debug.h>
|
||||
#include <dsp.h>
|
||||
|
||||
#include <sys/boardctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
@ -68,6 +69,10 @@
|
||||
|
||||
#if defined(CONFIG_EXAMPLES_SMPS) && defined(CONFIG_DRIVERS_SMPS)
|
||||
|
||||
#ifndef CONFIG_LIBDSP
|
||||
# error CONFIG_LIBDSP is required
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_ARCH_HIPRI_INTERRUPT
|
||||
# error CONFIG_ARCH_HIPRI_INTERRUPT is required
|
||||
#endif
|
||||
@ -211,14 +216,14 @@ struct smps_lower_dev_s
|
||||
|
||||
struct smps_priv_s
|
||||
{
|
||||
uint8_t conv_mode; /* Converter mode */
|
||||
uint16_t v_in_raw; /* Voltage input RAW value */
|
||||
uint16_t v_out_raw; /* Voltage output RAW value */
|
||||
float v_in; /* Voltage input real value in V */
|
||||
float v_out; /* Voltage output real value in V */
|
||||
bool running; /* Running flag */
|
||||
float state[3]; /* Controller state vartiables */
|
||||
float *c_limit_tab; /* Current limit tab */
|
||||
uint8_t conv_mode; /* Converter mode */
|
||||
uint16_t v_in_raw; /* Voltage input RAW value */
|
||||
uint16_t v_out_raw; /* Voltage output RAW value */
|
||||
float v_in; /* Voltage input real value in V */
|
||||
float v_out; /* Voltage output real value in V */
|
||||
bool running; /* Running flag */
|
||||
pid_controller_t pid; /* PID controller */
|
||||
float *c_limit_tab; /* Current limit tab */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
@ -404,6 +409,16 @@ static int smps_start(FAR struct smps_dev_s *dev)
|
||||
|
||||
memset(priv, 0, sizeof(struct smps_priv_s));
|
||||
|
||||
#ifdef SMPS_CONTROLLER_PID
|
||||
/* Initialize PID controller */
|
||||
|
||||
pid_controller_init(&priv->pid, PID_KP, PID_KI, PID_KD);
|
||||
|
||||
/* Set PID controller saturation */
|
||||
|
||||
pid_saturation_set(&priv->pid, 0.0, BOOST_VOLT_MAX);
|
||||
#endif
|
||||
|
||||
/* Get TIMA period value for given frequency */
|
||||
|
||||
fclk = HRTIM_FCLK_GET(hrtim, HRTIM_TIMER_TIMA);
|
||||
@ -659,41 +674,21 @@ static int smps_ioctl(FAR struct smps_dev_s *dev, int cmd, unsigned long arg)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: pid_controller
|
||||
****************************************************************************/
|
||||
|
||||
static float pid_controller(struct smps_priv_s *priv, float err)
|
||||
{
|
||||
float out;
|
||||
float A0 = PID_KP + PID_KD + PID_KI;
|
||||
float A1 = -PID_KP - 2.0*PID_KD;
|
||||
float A2 = PID_KD;
|
||||
|
||||
/* Get PID controller output */
|
||||
|
||||
out = (A0 * err) + (A1 * priv->state[0]) + (A2 * priv->state[1]) + priv->state[2];
|
||||
|
||||
/* Store PID contrroller variables */
|
||||
|
||||
priv->state[1] = priv->state[0];
|
||||
priv->state[0] = err;
|
||||
priv->state[2] = out;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: smps_controller
|
||||
****************************************************************************/
|
||||
|
||||
static float smps_controller(struct smps_priv_s *priv, float err)
|
||||
static float smps_controller(FAR struct smps_priv_s *priv, float err)
|
||||
{
|
||||
float out = 0.0;
|
||||
|
||||
#ifdef SMPS_CONTROLLER_PID
|
||||
return pid_controller(priv, err);
|
||||
out = pid_controller(&priv->pid, err);
|
||||
#else
|
||||
# error "At this time only PID controller implemented"
|
||||
#endif
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
Loading…
Reference in New Issue
Block a user