From 4f1348882b2fe510537a0a80e3d050d2d33789cb Mon Sep 17 00:00:00 2001 From: EmanuelFeru Date: Mon, 1 Jul 2019 21:06:01 +0200 Subject: [PATCH] Add: Condition on motor control calculation - The motors control calculation is done only if the motor is enabled to correctly initialize the controller. --- Src/bldc.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/Src/bldc.c b/Src/bldc.c index e2677c1..faab39e 100644 --- a/Src/bldc.c +++ b/Src/bldc.c @@ -142,9 +142,11 @@ void DMA1_Channel1_IRQHandler(void) { rtU_Left.b_hallC = hall_wl; rtU_Left.r_DC = pwml; - /* Step the controller */ - BLDC_controller_step(rtM_Left); - + /* Step the controller if motor is enabled*/ + if (enable) { + BLDC_controller_step(rtM_Left); + } + /* Get motor outputs here */ ul = rtY_Left.DC_phaA; vl = rtY_Left.DC_phaB; @@ -171,8 +173,10 @@ void DMA1_Channel1_IRQHandler(void) { rtU_Right.b_hallC = hall_wr; rtU_Right.r_DC = pwmr; - /* Step the controller */ - BLDC_controller_step(rtM_Right); + /* Step the controller if motor is enabled*/ + if (enable) { + BLDC_controller_step(rtM_Right); + } /* Get motor outputs here */ ur = rtY_Right.DC_phaA;