Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples/foc: get iphase scale from the FOC device interface #2196

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/foc/foc_fixed16_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,10 @@ int foc_fixed16_thr(FAR struct foc_ctrl_env_s *envp)
goto errout;
}

/* Get PWM max duty */
/* Store data from device */

motor.pwm_duty_max = FOCDUTY_TO_FIXED16(dev.info.hw_cfg.pwm_max);
motor.iphase_adc = b16idiv(dev.info.hw_cfg.iphase_scale, 100000);

/* Start with motor free */

Expand Down
3 changes: 2 additions & 1 deletion examples/foc/foc_float_thr.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,10 @@ int foc_float_thr(FAR struct foc_ctrl_env_s *envp)
goto errout;
}

/* Get PWM max duty */
/* Store data from device */

motor.pwm_duty_max = FOCDUTY_TO_FLOAT(dev.info.hw_cfg.pwm_max);
motor.iphase_adc = dev.info.hw_cfg.iphase_scale / 100000.0f;

/* Start with motor free */

Expand Down
1 change: 0 additions & 1 deletion examples/foc/foc_motor_b16.c
Original file line number Diff line number Diff line change
Expand Up @@ -1346,7 +1346,6 @@ int foc_motor_init(FAR struct foc_motor_b16_s *motor,
/* Initialize motor data */

motor->per = b16divi(b16ONE, CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ);
motor->iphase_adc = ftob16((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f);
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS
motor->ol_thr = ftob16(motor->envp->cfg->ol_thr / 1.0f);
motor->ol_hys = ftob16(motor->envp->cfg->ol_hys / 1.0f);
Expand Down
7 changes: 5 additions & 2 deletions examples/foc/foc_motor_b16.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,17 @@ struct foc_motor_b16_s
int time; /* Helper counter */
b16_t vbus; /* Power bus voltage */
b16_t per; /* Controller period in seconds */
b16_t iphase_adc; /* Iphase ADC scaling factor */
b16_t pwm_duty_max; /* PWM duty max */
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS
b16_t ol_thr; /* Angle observer threshold velocity */
b16_t ol_hys; /* Angle observer hysteresis */
b16_t angle_step; /* Open-loop transition step */
#endif

/* Data from FOC device ***************************************************/

b16_t iphase_adc; /* Iphase ADC scaling factor */
b16_t pwm_duty_max; /* PWM duty max */

/* Velocity controller data ***********************************************/

struct foc_ramp_b16_s ramp; /* Velocity ramp data */
Expand Down
1 change: 0 additions & 1 deletion examples/foc/foc_motor_f32.c
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ int foc_motor_init(FAR struct foc_motor_f32_s *motor,
/* Initialize motor data */

motor->per = (float)(1.0f / CONFIG_EXAMPLES_FOC_NOTIFIER_FREQ);
motor->iphase_adc = ((CONFIG_EXAMPLES_FOC_IPHASE_ADC) / 100000.0f);
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS
motor->ol_thr = (motor->envp->cfg->ol_thr / 1.0f);
motor->ol_hys = (motor->envp->cfg->ol_hys / 1.0f);
Expand Down
7 changes: 5 additions & 2 deletions examples/foc/foc_motor_f32.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,16 @@ struct foc_motor_f32_s
int time; /* Helper counter */
float vbus; /* Power bus voltage */
float per; /* Controller period in seconds */
float iphase_adc; /* Iphase ADC scaling factor */
float pwm_duty_max; /* PWM duty max */
#ifdef CONFIG_EXAMPLES_FOC_ANGOBS
float ol_thr; /* Angle observer threshold velocity */
float ol_hys; /* Angle observer hysteresis */
#endif

/* Data from FOC device ***************************************************/

float iphase_adc; /* Iphase ADC scaling factor */
float pwm_duty_max; /* PWM duty max */

/* Velocity controller data ***********************************************/

struct foc_ramp_f32_s ramp; /* Velocity ramp data */
Expand Down