18.4.5 PWM Mode
A timer is configured to PWM mode using the following sequence:
- Ensure the timer is disabled (the TnEN bit is cleared) before making any changes.
- Write the GPTM Configuration (GPTMCFG) register with a value of 0x0000.0004.
- In the GPTM Timer Mode (GPTMTnMR) register, set the TnAMS bit to 0x1, the TnCMR bit to 0x0, and the TnMR field to 0x2.
- Configure the output state of the PWM signal (whether or not it is inverted) in the TnPWML field of the GPTM Control (GPTMCTL) register.
- If a prescaler is to be used, write the prescale value to the GPTM Timer n Prescale Register (GPTMTnPR).
- If PWM interrupts are used, configure the interrupt condition in the TnEVENT field in the GPTMCTL register and enable the interrupts by setting the TnPWMIE bit in the GPTMTnMR register. Edge detect interrupt behavior is reversed when the PWM output is inverted (see Section 18.5.4).
- Load the timer start value into the GPTM Timer n Interval Load (GPTMTnILR) register.
- Load the GPTM Timer n Match (GPTMTnMATCHR) register with the match value.
- Set the TnEN bit in the GPTM Control (GPTMCTL) register to enable the timer and begin generation of the output PWM signal.
In PWM Time mode, the timer continues running after the PWM signal has been generated. The PWM period can be adjusted at any time by writing the GPTMTnILR register, and the change takes effect at the next cycle after the write.