
89
CHAPTER 5 APPLICATIONS OF 16-BIT TIMER/EVENT COUNTER
5.2 PWM Output
When using the 16-bit timer/event counter in the PWM output mode, set the PWM mode by the 16-bit timer mode
control register (TMC0) and enables the output of the 16-bit timer/event counter by the 16-bit timer output control
register (TOC0).
The pulse width (active level) of PWM is determined by the value set to the compare register 00 (CR00). Because
the PWM of the 78K/0 series has a resolution of 14 bits, however, bits 2 through 15 of CR00 are valid (clear bits 0
and 1 of CR00 to ‘0, 0’).
In the example below, the basic cycle of the PWM mode is set to 61.0
μ
s (2/f
X
×
2
8
) and the low level is selected
as the active level. The high-order 4 bits of the pulse width are rewritten depending on the value of the parameter
(00H to FFH). Therefore, in the following application example, PWM output can be performed in 16 steps (CR00 =
0FFCH to FFFCH).
(1) Description of package
<Public declaration symbol>
PWM
: PWM output subroutine name
PWMOUT: input parameter of PWM active level
<Registers used>
AX
<RAM used>
Name
Usage
Attribute
Bytes
PWMOUT
Sets PWM active level
SADDR
1
<Nesting>
1 level 2 bytes
<Hardware units used>
16-bit timer/event counter
P30/TO0
<Initial setting>
Setting of 16-bit timer/event counter
PWM output mode
PWM basic cycle: 61.0
μ
s
Low-active output
P30 output mode
P30 output latch
TMC0 = #00000010B
TCL0 = #00100000B
TOC0 = #00000011B
PM30 = 0
P30 = 0
<Starting>
After setting data to PWMOUT in RAM, call subroutine PWM.