diff options
| author | Damien George | 2014-09-29 14:15:01 +0100 |
|---|---|---|
| committer | Damien George | 2014-09-29 14:15:01 +0100 |
| commit | f042d7a4d7197d87798bc9727e9df094a3edd7c1 (patch) | |
| tree | 1bd316e2f4911a4c7ae49df2906c08a5e74dbadc /teensy | |
| parent | 853708738eee3437c3cb10e4bedf2760c541766b (diff) | |
stmhal: Fix edge case for timer PWM of 100%.
Also improve precision of calculating PWM percent in integer mode.
Also update teensy with edge case fix.
Diffstat (limited to 'teensy')
| -rw-r--r-- | teensy/timer.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/teensy/timer.c b/teensy/timer.c index d7892039a..81450698b 100644 --- a/teensy/timer.c +++ b/teensy/timer.c @@ -175,7 +175,7 @@ STATIC uint32_t compute_pwm_value_from_percent(uint32_t period, mp_obj_t percent STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) { #if MICROPY_PY_BUILTINS_FLOAT float percent = (float)cmp * 100.0 / (float)period; - if (cmp > period) { + if (cmp >= period) { percent = 100.0; } else { percent = (float)cmp * 100.0 / (float)period; @@ -183,7 +183,7 @@ STATIC mp_obj_t compute_percent_from_pwm_value(uint32_t period, uint32_t cmp) { return mp_obj_new_float(percent); #else mp_int_t percent; - if (cmp > period) { + if (cmp >= period) { percent = 100; } else { percent = cmp * 100 / period; |
