Skip to content

Commit

Permalink
Fix setting PWM to 0 issue
Browse files Browse the repository at this point in the history
Timer resets cnt register to 0x1 when timer period end. Setting pwm
register to 0 causes problem because cnt register never be equal to pwm
register and output signal never toggle its state. To fix this problem
set pwm register to 1 instead of 0 for 0 pwm value.

Signed-off-by: Furkan Akkiz <[email protected]>
  • Loading branch information
hfakkiz committed Dec 14, 2023
1 parent 56e58ce commit 2d2a6b7
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Libraries/PeriphDrivers/Source/TMR/tmr_revb.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,12 +278,12 @@ int MXC_TMR_RevB_SetPWM(mxc_tmr_revb_regs_t *tmr, uint32_t pwm)
MXC_TMR_RevB_ClearFlags(tmr); // Clear flags so we can catch the next one
while (!MXC_TMR_RevB_GetFlags(tmr)) {} // Wait for next PWM transition
MXC_TMR_RevB_Stop(tmr); // Pause timer
MXC_TMR_RevB_SetCount(tmr, 0); // Reset the count
MXC_TMR_RevB_SetCount(tmr, 1); // Reset the count
MXC_TMR_RevB_ClearFlags(
tmr); // Clear flags since app code wants the new PWM transitions set by this function
}

tmr->pwm = pwm;
tmr->pwm = pwm ? pwm : 1;
while (!(tmr->intfl & MXC_F_TMR_REVB_INTFL_WRDONE_A)) {}

if (timera_is_running) {
Expand Down

0 comments on commit 2d2a6b7

Please sign in to comment.