Repository navigation
Commit 60b3b30
fix(HardwareTimer): use ARR+1 in getCaptureCompare percent/resolution
getCaptureCompare() divided by LL_TIM_GetAutoReload() (ARR) for
PERCENT_COMPARE_FORMAT and all RESOLUTION_xB_COMPARE_FORMAT cases,
while its counterpart setCaptureCompare() multiplies by ARR+1, per
the code's own comment: "PWM reach 100% with CCRx value strictly
greater than ARR (So ARR+1 in our case)".
This makes get/set inconsistent: reading back a duty cycle written
via setCaptureCompare(ch, 100, PERCENT_COMPARE_FORMAT) does not
return 100, and overshoots more as ARR gets smaller (e.g. ARR=9
reads back 111, ARR=1 reads back 200). When ARR is 0 (a reachable
state, e.g. after setOverflow(1, TICK_FORMAT)), the getter performs
a division by zero.
Use ARR+1 in the getter too, matching the setter and its own
documented rationale.
Signed-off-by: 94xhn <87560781+94xhn@users.noreply.github.com>1 parent 594ee29 commit 60b3b30
1 file changed
Lines changed: 5 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1205 | 1205 | | |
1206 | 1206 | | |
1207 | 1207 | | |
| 1208 | + | |
| 1209 | + | |
| 1210 | + | |
1208 | 1211 | | |
1209 | | - | |
| 1212 | + | |
1210 | 1213 | | |
1211 | 1214 | | |
1212 | 1215 | | |
| |||
1224 | 1227 | | |
1225 | 1228 | | |
1226 | 1229 | | |
1227 | | - | |
| 1230 | + | |
1228 | 1231 | | |
1229 | 1232 | | |
1230 | 1233 | | |
| |||
0 commit comments