8.6.2
Setup Example
PWM Output Setup Example
The PWM output waveform with the 1/4 duty cycle and 19.53 kHz is output from TM0IO output pin of Timer 0.
The oscillation of SYSCLK/2 is 5 MHz.
The setup procedure and the description of each step are shown below.
TM0IO output
Step
Setting
1
Disable the timer counter
2
Select the timer output pin
3
Set the timer mode register
4
5
Set the prescaler
6
Set the "High" period of PWM
7
8
Enable the timer counter
19.53 kHz
Figure:8.6.4 Output Waveform of TM0IO Output Pin
Register
TM0MD.TM0EN = 0
TMIOEN0.TM0OEN = 1
P0DIR.P0DIR5 = 1
TM0MD.TM0PWM = 1
TM0MD.TM0MOD = 0
TM0MD.TM0POP = 0
TM0MD.TM0CK1-0 = 01
CK0MD.TM0PSC1-0 = X0
CK0MD.TM0BAS = 1
TM0OC = 0x40
TM0MD.TM0EN = 1
Description
Disable the timer count operation.
Select the timer output pin.
[Chapter 7 I/O Port]
Select the PWM operation.
Select the prescaler as the clock source.
Select SYSCLK/2.
Set the "High" period of PWM output.
Setup value: 256/4 = 64 (0x40)
Enable the timer count operation.
Chapter 8
8-bit Timer
8-bit PWM Output
VIII - 27