Skip to content

Commit e60fe3d

Browse files
committed
stm32: Fix off-by-one error in the prescaler calculation in hard_pwm.c
Signed-off-by: Kevin O'Connor <[email protected]>
1 parent 74a15f4 commit e60fe3d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/stm32/hard_pwm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "internal.h" // GPIO
1212
#include "sched.h" // sched_shutdown
1313

14-
#define MAX_PWM (256 + 1)
14+
#define MAX_PWM 256
1515
DECL_CONSTANT("PWM_MAX", MAX_PWM);
1616

1717
struct gpio_pwm_info {
@@ -327,7 +327,7 @@ gpio_timer_setup(uint8_t pin, uint32_t cycle_time, uint32_t val,
327327
// In normal mode, allow the pulse frequency (cycle_time) to change
328328
// in order to maintain the requested duty ratio (val/MAX_PWM).
329329
hwpwm_ticks = MAX_PWM;
330-
prescaler = pcycle_time / (hwpwm_ticks - 1);
330+
prescaler = pcycle_time / MAX_PWM;
331331
if (prescaler > UINT16_MAX + 1)
332332
prescaler = UINT16_MAX + 1;
333333
else if (prescaler < 1)

0 commit comments

Comments
 (0)