Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 never become bigger than pwm so that added tolerance

Signed-off-by: Sadik Ozer <sadik.ozer@analog.com>
ozersa committed Dec 6, 2023
1 parent 7fe9ab5 commit 87e1bad
Showing 2 changed files with 20 additions and 2 deletions.
11 changes: 10 additions & 1 deletion Libraries/PeriphDrivers/Source/TMR/tmr_revb.c
Original file line number Diff line number Diff line change
@@ -269,7 +269,16 @@ 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 at least +2 shall be added.
* But there should be a tolerance too, to it be catched
* So that +8 added as toleransa value.
*/
while (tmr->cnt >= (pwm + 8)) {}

tmr->pwm = pwm;
while (!(tmr->intfl & MXC_F_TMR_REVB_INTFL_WRDONE_A)) {}
11 changes: 10 additions & 1 deletion Libraries/PeriphDrivers/Source/TMR/tmr_revc.c
Original file line number Diff line number Diff line change
@@ -188,7 +188,16 @@ 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 at least +2 shall be added.
* But there should be a tolerance too, to it be catched
* So that +8 added as toleransa value.
*/
while (tmr->cnt >= (pwm + 8)) {}

tmr->pwm = pwm;

0 comments on commit 87e1bad

Please sign in to comment.