Skip to content

Commit

Permalink
Fix issue: Timer PWM mode edge case issue fixed
Browse files Browse the repository at this point in the history
when timer period end the tmr->count is reset to 0x00000001
and the timer resumes counting. On edge case when pwm==0 flow stuck in while loop
tmr->cnt newer become bigger than pwm so that +2 added

Signed-off-by: Sadik Ozer <[email protected]>
  • Loading branch information
ozersa committed Dec 6, 2023
1 parent 7fe9ab5 commit b7a8d71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Libraries/PeriphDrivers/Source/TMR/tmr_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,14 @@ int MXC_TMR_RevB_SetPWM(mxc_tmr_revb_regs_t *tmr, uint32_t pwm)
return E_BAD_PARAM;
}

while (tmr->cnt >= pwm) {}
/*
* when timer period end the tmr->count is reset to 0x00000001
* and the timer resumes counting.
* On edge case when pwm==0 flow stuck in below code due to
* tmr->cnt newer become bigger than pwm.
* So that +2 added.
*/
while (tmr->cnt >= (pwm + 2)) {}

tmr->pwm = pwm;
while (!(tmr->intfl & MXC_F_TMR_REVB_INTFL_WRDONE_A)) {}
Expand Down
9 changes: 8 additions & 1 deletion Libraries/PeriphDrivers/Source/TMR/tmr_revc.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,14 @@ int MXC_TMR_RevC_SetPWM(mxc_tmr_regs_t *tmr, uint32_t pwm)
return E_BAD_PARAM;
}

while (tmr->cnt >= pwm) {}
/*
* when timer period end the tmr->count is reset to 0x00000001
* and the timer resumes counting.
* On edge case when pwm==0 flow stuck in below code due to
* tmr->cnt newer become bigger than pwm.
* So that +2 added.
*/
while (tmr->cnt >= (pwm + 2)) {}

tmr->pwm = pwm;

Expand Down

0 comments on commit b7a8d71

Please sign in to comment.