I am using one of the FTM timers in a K60 as a PWM signal to control the dimming of the backlighting on a display. It all works correctly but I am confused about the optimal way to disable the FTM and guarantee that the output of the FTM is low before entering one of the K60 sleep modes. I have tried a number of approaches but haven't come up with an optimal solution that works every time before sleep mode is entered. I hate to just throw in arbitrary delays without understanding the underlying considerations. I was hoping that stopping the clock and setting the initialization bit would work but it doesn't work reliably.
// Stop the clock
FTM0_SC = (FTM_SC_CLKS(0x00) | FTM_SC_PS(0x00));
// Set output initialization to be low
FTM0_OUTINIT &= ~FTM_OUTINIT_CH2OI_MASK;
// Force initialization
FTM0_MODE = FTM_MODE_FAULT(0x00) | FTM_MODE_WPDIS_MASK | FTM_MODE_INIT_MASK);
I've also tried resetting the count and setting the offset register to equal the period and using the SYNC register to force the buffer values to the registers but that didn't work either.
I would appreciate any help on this!
Thanks,
Elizabeth