From 36c3fdb57671a10bdd1c59fa5eb0c93718c14b2a Mon Sep 17 00:00:00 2001 From: Andrey Mironov Date: Sun, 4 Mar 2018 01:48:22 +0300 Subject: [PATCH] Simplified PID rate counter code (#5350) --- src/main/fc/fc_core.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/fc/fc_core.c b/src/main/fc/fc_core.c index 996384a973..f919d17286 100644 --- a/src/main/fc/fc_core.c +++ b/src/main/fc/fc_core.c @@ -929,7 +929,7 @@ static void subTaskMotorUpdate(timeUs_t currentTimeUs) // Function for loop trigger void taskMainPidLoop(timeUs_t currentTimeUs) { - static uint8_t pidUpdateCountdown = 0; + static uint32_t pidUpdateCounter = 0; #if defined(SIMULATOR_BUILD) && defined(SIMULATOR_GYROPID_SYNC) if (lockMainPID() != 0) return; @@ -937,16 +937,13 @@ void taskMainPidLoop(timeUs_t currentTimeUs) // DEBUG_PIDLOOP, timings for: // 0 - gyroUpdate() - // 1 - pidController() + // 1 - subTaskPidController() // 2 - subTaskMotorUpdate() // 3 - subTaskMainSubprocesses() gyroUpdate(currentTimeUs); DEBUG_SET(DEBUG_PIDLOOP, 0, micros() - currentTimeUs); - if (pidUpdateCountdown) { - pidUpdateCountdown--; - } else { - pidUpdateCountdown = pidConfig()->pid_process_denom - 1; + if (pidUpdateCounter++ % pidConfig()->pid_process_denom == 0) { subTaskPidController(currentTimeUs); subTaskMotorUpdate(currentTimeUs); subTaskMainSubprocesses(currentTimeUs);