drivers/foc: return scaling factor for phase currents and BEMF via ioctl
These values are board-specific properties that must be known on the application side. Until now, these values had to be hardcoded on the application side.
This commit is contained in:
parent
7d99f01cf7
commit
99513ac23e
@ -390,7 +390,7 @@ static struct stm32_foc_board_data_s g_stm32_foc_board_data =
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
.vadc_cfg = &g_vadc_cfg,
|
||||
#endif
|
||||
.pwm_dt = (PWM_DEADTIME),
|
||||
.pwm_dt = PWM_DEADTIME
|
||||
};
|
||||
|
||||
/* Board specific configuration */
|
||||
@ -599,6 +599,17 @@ static int board_foc_info_get(struct foc_dev_s *dev, struct foc_info_s *info)
|
||||
info->hw_cfg.pwm_dt_ns = PWM_DEADTIME_NS;
|
||||
info->hw_cfg.pwm_max = MAX_DUTY_B16;
|
||||
|
||||
/* ADC BEMF */
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
info->hw_cfg.bemf_scale = 0; /* TODO */
|
||||
#endif
|
||||
|
||||
/* ADC Current - dynamic current scale not supported */
|
||||
|
||||
info->hw_cfg.iphase_max = 40000;
|
||||
info->hw_cfg.iphase_scale = -2939;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -146,7 +146,7 @@ static struct stm32_foc_board_ops_s g_stm32_foc_board_ops =
|
||||
static struct stm32_foc_board_data_s g_stm32_foc_board_data =
|
||||
{
|
||||
.adc_cfg = NULL, /* board-specific */
|
||||
.pwm_dt = (PWM_DEADTIME)
|
||||
.pwm_dt = PWM_DEADTIME
|
||||
};
|
||||
|
||||
/* Board specific configuration */
|
||||
@ -307,6 +307,17 @@ static int board_foc_info_get(struct foc_dev_s *dev,
|
||||
info->hw_cfg.pwm_dt_ns = PWM_DEADTIME_NS;
|
||||
info->hw_cfg.pwm_max = MAX_DUTY_B16;
|
||||
|
||||
/* ADC BEMF */
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
info->hw_cfg.bemf_scale = 0; /* TODO */
|
||||
#endif
|
||||
|
||||
/* ADC Current - dynamic current scale not supported */
|
||||
|
||||
info->hw_cfg.iphase_max = 1400;
|
||||
info->hw_cfg.iphase_scale = -160;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -154,7 +154,7 @@ static struct stm32_foc_board_ops_s g_stm32_foc_board_ops =
|
||||
static struct stm32_foc_board_data_s g_stm32_foc_board_data =
|
||||
{
|
||||
.adc_cfg = NULL, /* board-specific */
|
||||
.pwm_dt = (PWM_DEADTIME)
|
||||
.pwm_dt = PWM_DEADTIME
|
||||
};
|
||||
|
||||
/* Board specific configuration */
|
||||
@ -276,6 +276,17 @@ static int board_foc_info_get(struct foc_dev_s *dev,
|
||||
info->hw_cfg.pwm_dt_ns = PWM_DEADTIME_NS;
|
||||
info->hw_cfg.pwm_max = MAX_DUTY_B16;
|
||||
|
||||
/* ADC BEMF */
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
info->hw_cfg.bemf_scale = 0; /* TODO */
|
||||
#endif
|
||||
|
||||
/* ADC Current - dynamic current scale not supported */
|
||||
|
||||
info->hw_cfg.iphase_max = 15000;
|
||||
info->hw_cfg.iphase_scale = -1555;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -144,7 +144,7 @@ static struct stm32_foc_board_ops_s g_stm32_foc_board_ops =
|
||||
static struct stm32_foc_board_data_s g_stm32_foc_board_data =
|
||||
{
|
||||
.adc_cfg = NULL, /* board-specific */
|
||||
.pwm_dt = (PWM_DEADTIME)
|
||||
.pwm_dt = PWM_DEADTIME
|
||||
};
|
||||
|
||||
/* Board specific configuration */
|
||||
@ -284,6 +284,17 @@ static int board_foc_info_get(struct foc_dev_s *dev,
|
||||
info->hw_cfg.pwm_dt_ns = PWM_DEADTIME_NS;
|
||||
info->hw_cfg.pwm_max = MAX_DUTY_B16;
|
||||
|
||||
/* ADC BEMF */
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
info->hw_cfg.bemf_scale = 0; /* TODO */
|
||||
#endif
|
||||
|
||||
/* ADC Current - dynamic current scale not supported */
|
||||
|
||||
info->hw_cfg.iphase_max = 1500;
|
||||
info->hw_cfg.iphase_scale = -160;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ static struct stm32_foc_board_ops_s g_stm32_foc_board_ops =
|
||||
static struct stm32_foc_board_data_s g_stm32_foc_board_data =
|
||||
{
|
||||
.adc_cfg = &g_adc_cfg,
|
||||
.pwm_dt = (PWM_DEADTIME),
|
||||
.pwm_dt = PWM_DEADTIME,
|
||||
};
|
||||
|
||||
/* Board specific configuration */
|
||||
@ -382,6 +382,17 @@ static int board_foc_info_get(struct foc_dev_s *dev,
|
||||
info->hw_cfg.pwm_dt_ns = PWM_DEADTIME_NS;
|
||||
info->hw_cfg.pwm_max = MAX_DUTY_B16;
|
||||
|
||||
/* ADC BEMF */
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
info->hw_cfg.bemf_scale = 0; /* TODO */
|
||||
#endif
|
||||
|
||||
/* ADC Current - dynamic current scale not supported */
|
||||
|
||||
info->hw_cfg.iphase_max = 40000;
|
||||
info->hw_cfg.iphase_scale = -2287;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -44,8 +44,11 @@
|
||||
|
||||
/* Board HW configuration */
|
||||
|
||||
#define FOC_DUMMY_HW_PWM_NS (500)
|
||||
#define FOC_DUMMY_HW_PWM_MAX (0.95f)
|
||||
#define FOC_DUMMY_HW_PWM_NS (500)
|
||||
#define FOC_DUMMY_HW_PWM_MAX (0.95f)
|
||||
#define FOC_DUMMY_HW_BEMF_SCALE (1000)
|
||||
#define FOC_DUMMY_HW_IPHASE_SCALE (1000)
|
||||
#define FOC_DUMMY_HW_IPHASE_MAX (40000)
|
||||
|
||||
/* Helper macros ************************************************************/
|
||||
|
||||
@ -546,8 +549,13 @@ static int foc_dummy_info_get(FAR struct foc_dev_s *dev,
|
||||
{
|
||||
/* Get HW configuration */
|
||||
|
||||
info->hw_cfg.pwm_dt_ns = FOC_DUMMY_HW_PWM_NS;
|
||||
info->hw_cfg.pwm_max = ftob16(FOC_DUMMY_HW_PWM_MAX);
|
||||
info->hw_cfg.pwm_dt_ns = FOC_DUMMY_HW_PWM_NS;
|
||||
info->hw_cfg.pwm_max = ftob16(FOC_DUMMY_HW_PWM_MAX);
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
info->hw_cfg.bemf_scale = FOC_DUMMY_HW_IPHASE_SCALE;
|
||||
#endif
|
||||
info->hw_cfg.iphase_max = FOC_DUMMY_HW_IPHASE_MAX;
|
||||
info->hw_cfg.iphase_scale = FOC_DUMMY_HW_IPHASE_SCALE;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -102,8 +102,28 @@ struct foc_params_s
|
||||
|
||||
struct foc_info_hw_s
|
||||
{
|
||||
/* PWM configuration */
|
||||
|
||||
uint32_t pwm_dt_ns; /* PWM dead-time in nano seconds */
|
||||
foc_duty_t pwm_max; /* Maximum PWM duty cycle */
|
||||
|
||||
/* ADC configuration for phase current sampling
|
||||
*
|
||||
* In most cases it will be:
|
||||
*
|
||||
* iphase_scale = iphase_ratio * adc_to_volt
|
||||
* adc_to_volt = adc_ref_volt / adc_val_max
|
||||
* for shunt sensors iphase_ratio = 1 / (R_shunt * gain)
|
||||
*/
|
||||
|
||||
int32_t iphase_scale; /* Current phase scale [x100000] */
|
||||
int32_t iphase_max; /* Maximum phase curretn [x1000] */
|
||||
|
||||
/* ADC configuration for BEMF sampling */
|
||||
|
||||
#ifdef CONFIG_MOTOR_FOC_BEMF_SENSE
|
||||
int32_t bemf_scale; /* BEMF sampling scale [x1000] */
|
||||
#endif
|
||||
};
|
||||
|
||||
/* FOC driver info */
|
||||
|
Loading…
Reference in New Issue
Block a user