1 parent 3679292 commit e9f9ceeCopy full SHA for e9f9cee
1 file changed
ports/stm32f4/common-hal/pulseio/PWMOut.c
@@ -68,8 +68,9 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
68
}
69
70
STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) {
71
- //duty cycle is duty/0xFFFF fraction x (number of pulses per period)
72
- return (duty*period) / ((1 << 16) - 1);
+ //duty cycle is (0xFFFF - duty)/0xFFFF fraction x (number of pulses per period)
+ //Note that pulses are inverted, so duty cycle is inverted
73
+ return ((0xFFFF - duty)*period) / ((1 << 16) - 1);
74
75
76
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,
0 commit comments