
CHAPTER 7 8-BIT TIMER/EVENT COUNTERS 00 TO 02
126
User’s Manual U13952EJ3V1UD
7.4.3 Operation as square-wave output (timer 02 only)
The 8-bit timer can generate a square-wave output of any frequency at intervals specified by the count value
preset to 8-bit compare register 02 (CR02).
To operate 8-bit timer 02 as a square-wave output, make the settings in the following order.
<1> Set P23 to output mode (PM23 = 0), and set the output latch of P23 to 0
<2> Disable 8-bit timer counter 02 (TM02) operation (TCE02 (bit 0 of 8-bit timer mode control register 02
(TMC02)) = 1)
<3> Set the count clock of 8-bit timer 02 (see Table 7-9), and enable TO2 to output (TOE02 (bit 0 of TMC02) = 1)
<4> Set the count value to CR02
<5> Enable TM02 operation (TCE02 = 1)
When the count value of 8-bit timer counter 02 (TM02) matches the value set in CR02, the TO2/P23/CMPTOUT0
pin output is inverted. Through application of this mechanism, square waves of any frequency can be output. As
soon as a match occurs, the TM02 value is cleared to 00H, then counting continues count and an interrupt request
signal (INTTM02) is generated.
Setting bit 7 of TMC02 (TCE02) to 0 clears the square-wave output to 0.
Table 7-9 lists the square-wave output range, and Figure 7-11 shows the timing of square-wave output.
Caution
When the setting of the count clock using TMC02 and the setting of the TM02 to operation-
enable using an 8-bit memory manipulation instruction are performed at the same time, an error
of one clock or more may occur in the first cycle after the timer is started. Because of this,
when the 8-bit timer operates as a square-wave output, be sure to make the settings in the order
described above.
Table 7-9. Square-Wave Output Range of 8-Bit Timer 02
TCL021
TCL020
Minimum Pulse Width
Maximum Pulse Width
Resolution
0
2
3/fX (1.6
s)
2
11/fX (409.6
s)
2
3/fX (1.6
s)
0
1
2
7/fX (25.6
s)
2
15/fX (6.55 ms)
2
7/fX (25.6
s)
1
0
1/fXT (30.5
s)
2
8/fXT (7.81 ms)
1/fXT (30.5
s)
1
Setting prohibited
Remarks 1. fX:
Main system clock oscillation frequency
2. fXT: Subsystem clock oscillation frequency
3. The parenthesized values apply to operation at fX = 5.0 MHz or fXT = 32.768 kHz.