Specifications

General-Purpose (GP) Timers
6-36
PWM Operation
To generate a PWM output with a GP timer, a continuous up- or up-/down-
counting mode can be selected. Edge-triggered or asymmetric PWM wave-
forms are generated when a continuous-up count mode is selected. Centered
or symmetric PWM waveforms are generated when a continuous-up/-down
mode is selected. To set up the GP timer for the PWM operation, do the follow-
ing:
- Set up TxPR according to the desired PWM (carrier) period.
- Set up TxCON to specify the counting mode and clock source, and start
the operation.
- Load TxCMPR with values corresponding to the on-line calculated widths
(duty cycles) of PWM pulses.
The period value is obtained by dividing the desired PWM period by the period
of the GP timer input clock, and subtracting one from the resulting number
when the continuous up-counting mode is selected to generate asymmetric
PWM waveforms. When the continuous up-/down-counting mode is selected
to generate symmetric PWM waveforms, this value is obtained by dividing the
desired PWM period by two times the period of the GP timer input clock.
The GP timer can be initialized the same way as in the previous example. Dur-
ing run time, the GP timer compare register is constantly updated with newly
determined compare values corresponding to the newly determined duty
cycles.
6.3.5 GP Timer Reset
When any RESET event occurs, the following happens:
- All GP timer register bits, except for the counting direction indication bits
in GPTCONA/B, are reset to 0; thus, the operation of all GP timers is dis-
abled. The counting direction indication bits are all set to 1.
- All timer interrupt flags are reset to 0.
- All timer interrupt mask bits are reset to 0, except for PDPINTx; thus, all
GP timer interrupts are masked, except for PDPINTx
.
- All GP timer compare outputs are put in the high-impedance state.