diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 9a49661a5..7f928891e 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -170,18 +170,18 @@ void pwmEnableMotors(void) void pwmCompleteOneshotMotorUpdate(uint8_t motorCount) { - uint8_t index; - TIM_TypeDef *lastTimerPtr = NULL; - - for(index = 0; index < motorCount; index++){ - - // Force the timer to overflow if it's the first motor to output, or if we change timers - if(motors[index]->tim != lastTimerPtr){ - lastTimerPtr = motors[index]->tim; - - timerForceOverflow(motors[index]->tim); + for (int index = 0; index < motorCount; index++) { + bool overflowed = false; + // If we have not already overflowed this timer + for (int j = 0; j < index; j++) { + if (motors[j]->tim == motors[index]->tim) { + overflowed = true; + break; + } + } + if (!overflowed) { + timerForceOverflow(motors[index]->tim); } - // Set the compare register to 0, which stops the output pulsing if the timer overflows before the main loop completes again. // This compare register will be set to the output value on the next main loop. *motors[index]->ccr = 0;