Skip to content

Commit e9f9cee

Browse files
committed
Invert duty cycle intensity
1 parent 3679292 commit e9f9cee

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

  • ports/stm32f4/common-hal/pulseio

ports/stm32f4/common-hal/pulseio/PWMOut.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) {
6868
}
6969

7070
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);
71+
//duty cycle is (0xFFFF - duty)/0xFFFF fraction x (number of pulses per period)
72+
//Note that pulses are inverted, so duty cycle is inverted
73+
return ((0xFFFF - duty)*period) / ((1 << 16) - 1);
7374
}
7475

7576
STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler,

0 commit comments

Comments
 (0)