From 0da65bf6b07d0fc1f47867426d9572f32242ac73 Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Wed, 13 Feb 2019 18:18:12 -0500 Subject: [PATCH] atsam: Fix hard pwm cycle divider calculation Signed-off-by: Kevin O'Connor --- src/atsam/hard_pwm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atsam/hard_pwm.c b/src/atsam/hard_pwm.c index 8bfd6305..7d1881a6 100644 --- a/src/atsam/hard_pwm.c +++ b/src/atsam/hard_pwm.c @@ -71,7 +71,7 @@ gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val) // Map cycle_time to pwm clock divisor uint32_t div; for (div=0; div<10; div++) - if (cycle_time < (MAX_PWM << div) / 2) + if (cycle_time < ((MAX_PWM << (div + 1)) + (MAX_PWM << div)) / 2) break; // Enable clock