diff options
| author | Lucian Copeland <hierophect@gmail.com> | 2020-01-22 18:47:41 -0500 |
|---|---|---|
| committer | Lucian Copeland <hierophect@gmail.com> | 2020-01-22 18:47:41 -0500 |
| commit | e9f9cee4d66ccfb81b4a0b1e8503e2bbbdb57077 (patch) | |
| tree | f282a76ed45ca2b2ecaba5917ec96d801c55e724 | |
| parent | 36792926d24496860e021783c973a871076d7e76 (diff) | |
Invert duty cycle intensity
| -rw-r--r-- | ports/stm32f4/common-hal/pulseio/PWMOut.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/ports/stm32f4/common-hal/pulseio/PWMOut.c b/ports/stm32f4/common-hal/pulseio/PWMOut.c index 0a5d0cc85..000325be3 100644 --- a/ports/stm32f4/common-hal/pulseio/PWMOut.c +++ b/ports/stm32f4/common-hal/pulseio/PWMOut.c @@ -68,8 +68,9 @@ STATIC uint32_t timer_get_source_freq(uint32_t tim_id) { } STATIC uint32_t timer_get_internal_duty(uint16_t duty, uint32_t period) { - //duty cycle is duty/0xFFFF fraction x (number of pulses per period) - 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 + return ((0xFFFF - duty)*period) / ((1 << 16) - 1); } STATIC void timer_get_optimal_divisors(uint32_t*period, uint32_t*prescaler, |
