
Pulse width modulation module
UM0404
DocID13284 Rev 2
Up/down counters PTx
Each counter PTx of a PWM channel is clocked either directly by the CPU clock or by the
CPU clock divided by 64. Bit PTIx in register PWMCON0 selects the respective clock
source. A PWM counter counts up or down (controlled by hardware), while its respective run
control bit PTRx is set. A timer is started (PTRx = ‘1’) via software and is stopped
(PTRx = ‘0’) either via hardware or software, depending on its operating mode. Control bit
PTRx enables or disables the clock input of counter PTx rather than controlling the PWM
output signal.
summarizes the PWM frequencies that result from various combinations of
operating mode, counter resolution (input clock) and pulse width resolution.
Period registers PPx
The 16-bit period register PPx of a PWM channel determines the period of a PWM cycle and
the frequency of the PWM signal. This register is buffered with a shadow register.
The shadow register is loaded from the respective PPx register at the beginning of every
new PWM cycle, or upon a write access to PPx, while the timer is stopped. The CPU
accesses the PPx register while the hardware compares the contents of the shadow register
with the contents of the associated counter PTx.
When a match is found between counter and PPx shadow register, the counter is either
reset to 0000h, or the count direction is switched from counting up to counting down,
depending on the selected operating mode of that PWM channel. For the register locations
refer to the
.
Pulse width registers PWx
This 16-bit register holds the actual PWM pulse width value which corresponds to the duty
cycle of the PWM signal. This register is buffered with a shadow register.
The CPU accesses the PWx register while the hardware compares the contents of the
shadow register with the contents of the associated counter PTx. The shadow register is
loaded from the respective PWx register at the beginning of every new PWM cycle, or upon
a write access to PWx, while the timer is stopped.
When the counter value is greater than or equal to the shadow register value, the PWM
signal is set, otherwise it is reset. The output of the comparators may be described by the
boolean formula:
PWM output signal = [PTx] > [PWx shadow latch].
Table 52. PWM frequencies
Input Clock and
Mode (Counter
resolution)
8-bit PWM
resolution
10-bit PWM
resolution
12-bit PWM
resolution
14-bit PWM
resolution
16-bit PWM
resolution
f
CPU
Mode 0
f
CPU
/2
8
f
CPU
/2
10
f
CPU
/2
12
f
CPU
/2
14
f
CPU
/2
16
f
CPU
/ 64 Mode 0
f
CPU
/64x2
8
f
CPU
/64x2
10
f
CPU
/64x2
12
f
CPU
/64x2
14
f
CPU
/64x2
16
f
CPU
Mode 1
f
CPU
/2x2
8
f
CPU
/2x2
10
f
CPU
/2x2
12
f
CPU
/2x2
14
f
CPU
/2x2
16
f
CPU
/ 64 Mode 1
f
CPU
/2x64x2
8
f
CPU
/2x64x2
10
f
CPU
/2x64x2
12
f
CPU
/2x64x2
14
f
CPU
/2x64x2
16