Skip to content

Commit

Permalink
[FOC] Eliminate a few divisions by introducing p_inv_inv_ld_lq
Browse files Browse the repository at this point in the history
  • Loading branch information
kubark42 committed Apr 11, 2022
1 parent 702706e commit 0e17cef
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion foc_math.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,6 @@ void foc_precalc_values(motor_all_state_t *motor) {
const mc_configuration *conf_now = motor->m_conf;
motor->p_lq = conf_now->foc_motor_l + conf_now->foc_motor_ld_lq_diff * 0.5;
motor->p_ld = conf_now->foc_motor_l - conf_now->foc_motor_ld_lq_diff * 0.5;
motor->p_inv_ld_lq = (1.0 / motor->p_lq - 1.0 / motor->p_ld);
motor->p_inv_inv_ld_lq = 1.0 / (1.0 / motor->p_lq - 1.0 / motor->p_ld);
motor->p_v2_v3_inv_avg_half = (0.5 / motor->p_lq + 0.5 / motor->p_ld) * IND_SCALE_FACTOR; // With the `* IND_SCALE_FACTOR` we undo the adjustment from the detection
}
2 changes: 1 addition & 1 deletion foc_math.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ typedef struct {
// Pre-calculated values
float p_lq;
float p_ld;
float p_inv_ld_lq; // (1.0/lq - 1.0/ld)
float p_inv_inv_ld_lq; // 1.0 / (1.0/lq - 1.0/ld)
float p_v2_v3_inv_avg_half; // (0.5/ld + 0.5/lq)
} motor_all_state_t;

Expand Down
4 changes: 2 additions & 2 deletions mcpwm_foc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3847,7 +3847,7 @@ static void control_current(motor_all_state_t *motor, float dt) {
}
#endif
foc_hfi_adjust_angle(
(di * conf_now->foc_f_zv) / (hfi_voltage * motor->p_inv_ld_lq),
((di * conf_now->foc_f_zv) / hfi_voltage) * motor->p_inv_inv_ld_lq,
motor, hfi_dt
);
}
Expand Down Expand Up @@ -3899,7 +3899,7 @@ static void control_current(motor_all_state_t *motor, float dt) {
#endif
foc_hfi_adjust_angle(
motor->m_hfi.sign_last_sample * ((conf_now->foc_f_zv * di) /
hfi_voltage - motor->p_v2_v3_inv_avg_half) / motor->p_inv_ld_lq,
hfi_voltage - motor->p_v2_v3_inv_avg_half) * motor->p_inv_inv_ld_lq,
motor, hfi_dt
);
}
Expand Down

0 comments on commit 0e17cef

Please sign in to comment.