From 465a801076735a0b5702392b722c1df58b9e5d65 Mon Sep 17 00:00:00 2001 From: Benjamin Vedder Date: Mon, 23 May 2022 11:32:55 +0200 Subject: [PATCH] Include integrator in current control output one cycle earlier --- motor/mcpwm_foc.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/motor/mcpwm_foc.c b/motor/mcpwm_foc.c index b456e83e..b61236c4 100644 --- a/motor/mcpwm_foc.c +++ b/motor/mcpwm_foc.c @@ -3776,9 +3776,6 @@ static void control_current(motor_all_state_t *motor, float dt) { float Ierr_d = state_m->id_target - state_m->id; float Ierr_q = state_m->iq_target - state_m->iq; - state_m->vd = state_m->vd_int + Ierr_d * conf_now->foc_current_kp * d_gain_scale; //Feedback (PI controller). No D action needed because the plant is a first order system (tf = 1/(Ls+R)) - state_m->vq = state_m->vq_int + Ierr_q * conf_now->foc_current_kp; - float ki = conf_now->foc_current_ki; if (conf_now->foc_temp_comp) { ki = motor->m_current_ki_temp_comp; @@ -3787,6 +3784,10 @@ static void control_current(motor_all_state_t *motor, float dt) { state_m->vd_int += Ierr_d * (ki * d_gain_scale * dt); state_m->vq_int += Ierr_q * (ki * dt); + // Feedback (PI controller). No D action needed because the plant is a first order system (tf = 1/(Ls+R)) + state_m->vd = state_m->vd_int + Ierr_d * conf_now->foc_current_kp * d_gain_scale; + state_m->vq = state_m->vq_int + Ierr_q * conf_now->foc_current_kp; + // Decoupling. Using feedforward this compensates for the fact that the equations of a PMSM // are not really decoupled (the d axis current has impact on q axis voltage and visa-versa): // Resistance Inductance Cross terms Back-EMF (see www.mathworks.com/help/physmod/sps/ref/pmsm.html)