From 3fda1294d76d271389d7a0b63444ac7685156e22 Mon Sep 17 00:00:00 2001 From: raiden00pl Date: Sat, 4 Dec 2021 17:34:58 +0100 Subject: [PATCH] examples/foc: move setpoint and vbus configuration from foc_adc.h to foc_cfg.h --- examples/foc/foc_adc.h | 49 ------------------------------------ examples/foc/foc_cfg.h | 49 ++++++++++++++++++++++++++++++++++++ examples/foc/foc_main.c | 2 +- examples/foc/foc_motor_b16.c | 1 - examples/foc/foc_motor_f32.c | 1 - 5 files changed, 50 insertions(+), 52 deletions(-) diff --git a/examples/foc/foc_adc.h b/examples/foc/foc_adc.h index 28fcc0434..deafd8ca2 100644 --- a/examples/foc/foc_adc.h +++ b/examples/foc/foc_adc.h @@ -31,55 +31,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* VBUS source must be specified */ - -#if defined(CONFIG_EXAMPLES_FOC_VBUS_CONST) && \ - defined(CONFIG_EXAMPLES_FOC_VBUS_ADC) -# error -#endif - -/* Velocity source must be specified */ - -#if defined(CONFIG_EXAMPLES_FOC_SETPOINT_CONST) && \ - defined(CONFIG_EXAMPLES_FOC_SETPOINT_ADC) -# error -#endif - -/* VBUS ADC scale factor */ - -#ifdef CONFIG_EXAMPLES_FOC_VBUS_ADC -# define VBUS_ADC_SCALE (CONFIG_EXAMPLES_FOC_ADC_VREF * \ - CONFIG_EXAMPLES_FOC_VBUS_SCALE / \ - CONFIG_EXAMPLES_FOC_ADC_MAX / \ - 1000.0f / \ - 1000.0f) -#endif - -/* Velocity ADC scale factor */ - -#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_ADC -# define SETPOINT_ADC_SCALE (1.0f / CONFIG_EXAMPLES_FOC_ADC_MAX) -#endif - -/* If constant velocity is selected, velocity value must be provided */ - -#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST -# define SETPOINT_ADC_SCALE (1) -# if CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE == 0 -# error -# endif -#endif - -/* If constant VBUS is selected, VBUS value must be provided */ - -#ifdef CONFIG_EXAMPLES_FOC_VBUS_CONST -# define VBUS_ADC_SCALE (1) -# define VBUS_CONST_VALUE (CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE / 1000.0f) -# if CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE == 0 -# error -# endif -#endif - /* Additional configuration if ADC support is required */ #ifdef CONFIG_EXAMPLES_FOC_HAVE_ADC diff --git a/examples/foc/foc_cfg.h b/examples/foc/foc_cfg.h index cf6476d32..25cee0ee4 100644 --- a/examples/foc/foc_cfg.h +++ b/examples/foc/foc_cfg.h @@ -128,4 +128,53 @@ # endif #endif +/* Setpoint source must be specified */ + +#if !defined(CONFIG_EXAMPLES_FOC_SETPOINT_CONST) && \ + !defined(CONFIG_EXAMPLES_FOC_SETPOINT_ADC) +# error +#endif + +/* Setpoint ADC scale factor */ + +#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_ADC +# define SETPOINT_ADC_SCALE (1.0f / CONFIG_EXAMPLES_FOC_ADC_MAX) +#endif + +/* If constant setpoint is selected, setpoint value must be provided */ + +#ifdef CONFIG_EXAMPLES_FOC_SETPOINT_CONST +# define SETPOINT_ADC_SCALE (1) +# if CONFIG_EXAMPLES_FOC_SETPOINT_CONST_VALUE == 0 +# error +# endif +#endif + +/* VBUS source must be specified */ + +#if !defined(CONFIG_EXAMPLES_FOC_VBUS_CONST) && \ + !defined(CONFIG_EXAMPLES_FOC_VBUS_ADC) +# error +#endif + +/* VBUS ADC scale factor */ + +#ifdef CONFIG_EXAMPLES_FOC_VBUS_ADC +# define VBUS_ADC_SCALE (CONFIG_EXAMPLES_FOC_ADC_VREF * \ + CONFIG_EXAMPLES_FOC_VBUS_SCALE / \ + CONFIG_EXAMPLES_FOC_ADC_MAX / \ + 1000.0f / \ + 1000.0f) +#endif + +/* If constant VBUS is selected, VBUS value must be provided */ + +#ifdef CONFIG_EXAMPLES_FOC_VBUS_CONST +# define VBUS_ADC_SCALE (1) +# define VBUS_CONST_VALUE (CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE / 1000.0f) +# if CONFIG_EXAMPLES_FOC_VBUS_CONST_VALUE == 0 +# error +# endif +#endif + #endif /* __EXAMPLES_FOC_FOC_CFG_H */ diff --git a/examples/foc/foc_main.c b/examples/foc/foc_main.c index a0a835948..134774cc8 100644 --- a/examples/foc/foc_main.c +++ b/examples/foc/foc_main.c @@ -41,7 +41,7 @@ #include "foc_mq.h" #include "foc_thr.h" -#include "foc_adc.h" +#include "foc_cfg.h" #include "foc_debug.h" #include "foc_device.h" #include "foc_parseargs.h" diff --git a/examples/foc/foc_motor_b16.c b/examples/foc/foc_motor_b16.c index 0cee3acab..6c7ef65cd 100644 --- a/examples/foc/foc_motor_b16.c +++ b/examples/foc/foc_motor_b16.c @@ -29,7 +29,6 @@ #include "foc_motor_b16.h" #include "foc_cfg.h" -#include "foc_adc.h" #include "foc_debug.h" /**************************************************************************** diff --git a/examples/foc/foc_motor_f32.c b/examples/foc/foc_motor_f32.c index 32d3a6075..fa839a175 100644 --- a/examples/foc/foc_motor_f32.c +++ b/examples/foc/foc_motor_f32.c @@ -29,7 +29,6 @@ #include "foc_motor_f32.h" #include "foc_cfg.h" -#include "foc_adc.h" #include "foc_debug.h" /****************************************************************************