drivers/foc: support for BEMF sensing

This commit is contained in:
raiden00pl
2023-01-15 14:41:02 +01:00
committed by Petro Karashchenko
parent 6d16792d33
commit 91d43edffd
7 changed files with 52 additions and 10 deletions
+4
View File
@@ -22,6 +22,10 @@ config MOTOR_FOC_SHUNTS
Number of shunts supported (or other types of current sensors).
Any current reconstruction must be done on the lower-half side.
config MOTOR_FOC_BEMF_SENSE
bool "FOC support for Back-EMF sensing"
default n
config MOTOR_FOC_TRACE
bool "FOC trace support"
default n
+16 -2
View File
@@ -62,7 +62,8 @@ static int foc_info_get(FAR struct foc_dev_s *dev,
FAR struct foc_info_s *info);
static int foc_notifier(FAR struct foc_dev_s *dev,
FAR foc_current_t *current);
FAR foc_current_t *current,
FAR foc_voltage_t *voltage);
/****************************************************************************
* Private Data
@@ -726,7 +727,8 @@ static int foc_info_get(FAR struct foc_dev_s *dev,
****************************************************************************/
static int foc_notifier(FAR struct foc_dev_s *dev,
FAR foc_current_t *current)
FAR foc_current_t *current,
FAR foc_voltage_t *voltage)
{
int ret = OK;
int sval = 0;
@@ -743,6 +745,18 @@ static int foc_notifier(FAR struct foc_dev_s *dev,
current,
sizeof(foc_current_t) * CONFIG_MOTOR_FOC_PHASES);
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
/* Copy voltage */
memcpy(&dev->state.volt,
voltage,
sizeof(foc_voltage_t) * CONFIG_MOTOR_FOC_PHASES);
#else
/* If BEMF sampling is not enabled then voltage must be NULL */
DEBUGASSERT(voltage == NULL);
#endif
/* Check if the previous cycle was handled */
ret = nxsem_get_value(&dev->statesem, &sval);
+11 -1
View File
@@ -79,6 +79,12 @@ struct foc_dummy_data_s
foc_current_t current[CONFIG_MOTOR_FOC_PHASES];
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
/* BEMF voltage */
foc_voltage_t volt[CONFIG_MOTOR_FOC_PHASES];
#endif
/* FOC worker loop helpers */
bool state;
@@ -464,7 +470,11 @@ static void foc_dummy_notifier_handler(FAR struct foc_dev_s *dev)
{
/* Call FOC notifier */
sim->cb->notifier(dev, sim->current);
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
sim->cb->notifier(dev, sim->current, sim->voltage);
#else
sim->cb->notifier(dev, sim->current, NULL);
#endif
}
/* Increase counter */