From f0bdc93a25f1c9d154c4ec95f91f19339ce63f61 Mon Sep 17 00:00:00 2001 From: blckmn Date: Sat, 15 Jul 2017 14:51:59 +1000 Subject: [PATCH] Fix motor twitch when unarmed and using synced protocols. --- src/main/drivers/pwm_output.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/drivers/pwm_output.c b/src/main/drivers/pwm_output.c index 9c05608fb7..01c0eb8e9f 100644 --- a/src/main/drivers/pwm_output.c +++ b/src/main/drivers/pwm_output.c @@ -311,13 +311,14 @@ void motorDevInit(const motorDevConfig_t *motorConfig, uint16_t idlePulse, uint8 #endif /* standard PWM outputs */ - const unsigned pwmRateHz = useUnsyncedPwm ? motorConfig->motorPwmRate : ceilf(1 / (sMin + sLen * 2)); + // margin of safety is 4 periods when unsynced + const unsigned pwmRateHz = useUnsyncedPwm ? motorConfig->motorPwmRate : ceilf(1 / ((sMin + sLen) * 4)); const uint32_t clock = timerClock(timerHardware->tim); /* used to find the desired timer frequency for max resolution */ const unsigned prescaler = ((clock / pwmRateHz) + 0xffff) / 0x10000; /* rounding up */ const uint32_t hz = clock / prescaler; - const unsigned period = hz / pwmRateHz; + const unsigned period = useUnsyncedPwm ? hz / pwmRateHz : 0xffff; /* if brushed then it is the entire length of the period.