diff --git a/configs/stm32f334-disco/buckboost/defconfig b/configs/stm32f334-disco/buckboost/defconfig index 6910e821216..3276eb9880d 100644 --- a/configs/stm32f334-disco/buckboost/defconfig +++ b/configs/stm32f334-disco/buckboost/defconfig @@ -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 diff --git a/configs/stm32f334-disco/src/stm32_smps.c b/configs/stm32f334-disco/src/stm32_smps.c index 7fa0fe24369..3d42c766928 100644 --- a/configs/stm32f334-disco/src/stm32_smps.c +++ b/configs/stm32f334-disco/src/stm32_smps.c @@ -47,6 +47,7 @@ #include #include #include +#include #include #include @@ -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; } /****************************************************************************