diff --git a/foc_math.c b/foc_math.c index c24f1b08d..25ab59151 100644 --- a/foc_math.c +++ b/foc_math.c @@ -613,7 +613,7 @@ 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_inv_lo_current_max = 1.0 / conf_now->lo_current_max; diff --git a/foc_math.h b/foc_math.h index 8e1d2cd8a..6d1e1f9bd 100644 --- a/foc_math.h +++ b/foc_math.h @@ -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) float p_inv_lo_current_max; } motor_all_state_t; diff --git a/mcpwm_foc.c b/mcpwm_foc.c index ae68270ca..8d2f914ed 100644 --- a/mcpwm_foc.c +++ b/mcpwm_foc.c @@ -3848,7 +3848,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 ); } @@ -3900,7 +3900,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 ); }