mirror of
https://github.com/apache/nuttx.git
synced 2026-06-08 01:42:58 +08:00
drivers/foc: support for BEMF sensing
This commit is contained in:
committed by
Petro Karashchenko
parent
6d16792d33
commit
91d43edffd
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user