W77IE58
- 52 -
When configured as a "Timer", the timer counts clock cycles. The timer clock can be programmed to
be thought of as 1/12 of the system clock or 1/4 of the system clock. In the "Counter" mode, the
register is incremented on the falling edge of the external input pin, T0 in case of Timer 0, and T1 for
Timer 1. The T0 and T1 inputs are sampled in every machine cycle at C4. If the sampled value is high
in one machine cycle and low in the next, then a valid high to low transition on the pin is recognized
and the count register is incremented. Since it takes two machine cycles to recognize a negative
transition on the pin, the maximum rate at which counting will take place is 1/24 of the master clock
frequency. In either the "Timer" or "Counter" mode, the count register will be updated at C3.
Therefore, in the "Timer" mode, the recognized negative transition on pin T0 and T1 can cause the
count register value to be updated only in the machine cycle following the one in which the negative
edge was detected.
The "Timer" or "Counter" function is selected by the "
CT/ " bit in the TMOD Special Function
Register. Each Timer/Counter has one selection bit for its own; bit 2 of TMOD selects the function for
Timer/Counter 0 and bit 6 of TMOD selects the function for Timer/Counter 1. In addition each
Timer/Counter can be set to operate in any one of four possible modes. The mode selection is done
by bits M0 and M1 in the TMOD SFR.
8.1.1 Time-Base Selection
The W77IE58 gives the user two modes of operation for the timer. The timers can be programmed to
operate like the standard 8051 family, counting at the rate of 1/12 of the clock speed. This will ensure
that timing loops on the W77IE58 and the standard 8051 can be matched. This is the default mode of
operation of the W77IE58 timers. The user also has the option to count in the turbo mode, where the
timers will increment at the rate of 1/4 clock speed. This will straight-away increase the counting
speed three times. This selection is done by the T0M and T1M bits in CKCON SFR. A reset sets these
bits to 0, and the timers then operate in the standard 8051 mode. The user should set these bits to 1 if
the timers are to operate in turbo mode.
MODE 0
In Mode 0, the timer/counters act as a 8 bit counter with a 5 bit, divide by 32 pre-scale. In this mode
we have a 13 bit timer/counter. The 13 bit counter consists of 8 bits of THx and 5 lower bits of TLx.
The upper 3 bits of TLx are ignored.
The negative edge of the clock increments the count in the TLx register. When the fifth bit in TLx
moves from 1 to 0, then the count in the THx register is incremented. When the count in THx moves
from FFh to 00h, then the overflow flag TFx in TCON SFR is set. The counted input is enabled only if
TRx is set and either GATE = 0 or
INTx = 1. When CT/ is set to 0, then it will count clock cycles,
and if
CT/ is set to 1, then it will count 1 to 0 transitions on T0 (P3.4) for timer 0 and T1 (P3.5) for
timer 1. When the 13 bit count reaches 1FFFh the next count will cause it to roll-over to 0000h. The
timer overflow flag TFx of the relevant timer is set and if enabled an interrupts will occur. Note that
when used as a timer, the time-base may be either clock cycles/12 or clock cycles/4 as selected by
the bits TxM of the CKCON SFR.
W77IE58
Publication Release Date: October 20, 2005
- 53 - Revision A5
1/4
1/12
C/T = TMOD.2
(C/T = TMOD.6)
T0M = CKCON.3
(T1M = CKCON.4)
M1, M0 = TMOD.1, TMOD.0
(M1, M0 = TMOD.5, TMOD.4)
Interrupt
T0 = P3.4
(T1 = P3.5)
TH0
(TH1)
TL0
(TL1)
TF0
(TF1)
TR0 = TCON.4
(TR1 = TCON.6)
GATE = TMOD.3
(GATE = TMOD.7)
INT0 = P3.2
(INT1 = P3.3)
70
TFx
4 70
Timer 1 functions are shown in brackets
1
00
0
0
1
01
Clock Source
Mode input
div. by 4 osc/1
div. by 64 osc/16
div. by 1024 osc/256
Figure 11. Timer/Counter Mode 0 & Mode 1
MODE 1
Mode 1 is similar to Mode 0 except that the counting register forms a 16 bit counter, rather than a 13
bit counter. This means that all the bits of THx and TLx are used. Roll-over occurs when the timer
moves from a count of FFFFh to 0000h. The timer overflow flag TFx of the relevant timer is set and if
enabled an interrupt will occur. The selection of the time-base in the timer mode is similar to that in
Mode 0. The gate function operates similarly to that in Mode 0.
MODE 2
In Mode 2, the timer/counter is in the Auto Reload Mode. In this mode, TLx acts as a 8 bit count
register, while THx holds the reload value. When the TLx register overflows from FFh to 00h, the TFx
bit in TCON is set and TLx is reloaded with the contents of THx, and the counting process continues
from here. The reload operation leaves the contents of the THx register unchanged. Counting is
enabled by the TRx bit and proper setting of GATE and
INTx pins. As in the other two modes 0 and
1 mode 2 allows counting of either clock cycles (clock/12 or clock/4) or pulses on pin Tn.
W77IE58
- 54 -
1/4
1/12
T0M = CKCON.3
(T1M = CKCON.4)
C/T = TMOD.2
(C/T = TMOD.6)
Interrupt
T0 = P3.4
(T1 = P3.5)
TH0
(TH1)
TL0
(TL1)
TF0
(TF1)
TR0 = TCON.4
(TR1 = TCON.6)
GATE = TMOD.3
(GATE = TMOD.7)
INT0 = P3.2
(INT1 = P3.3)
70
TFx
70
Timer 1 functions are shown in brackets
1
0
0
1
Clock Source
Mode input
div. by 4 osc/1
div. by 64 osc/16
div. by 1024 osc/256
Figure 12. Timer/Counter Mode 2.
MODE 3
Mode 3 has different operating methods for the two timer/counters. For timer/counter 1, mode 3 simply
freezes the counter. Timer/Counter 0, however, configures TL0 and TH0 as two separate 8 bit count
registers in this mode. The logic for this mode is shown in the figure. TL0 uses the Timer/Counter 0
control bits
CT/ , GATE, TR0, INT0 and TF0. The TL0 can be used to count clock cycles (clock/12
or clock/4) or 1-to-0 transitions on pin T0 as determined by C/T (TMOD.2). TH0 is forced as a clock
cycle counter (clock/12 or clock/4) and takes over the use of TR1 and TF1 from Timer/Counter 1.
Mode 3 is used in cases where an extra 8 bit timer is needed. With Timer 0 in Mode 3, Timer 1 can
still be used in Modes 0, 1 and 2., but its flexibility is somewhat limited. While its basic functionality is
maintained, it no longer has control over its overflow flag TF1 and the enable bit TR1. Timer 1 can still
be used as a timer/counter and retains the use of GATE and INT1 pin. In this condition it can be
turned on and off by switching it out of and into its own Mode 3. It can also be used as a baud rate
generator for the serial port.
8.1.2 Timer/Counter 2
Timer/Counter 2 is a 16 bit up/down counter which is configured by the T2MOD register and controlled
by the T2CON register. Timer/Counter 2 is equipped with a capture/reload capability. As with the
Timer 0 and Timer 1 counters, there exists considerable flexibility in selecting and controlling the
clock, and in defining the operating mode. The clock source for Timer/Counter 2 may be selected for
either the external T2 pin (C/T2 = 1) or the crystal oscillator, which is divided by 12 or 4 (C/T2 = 0).
The clock is then enabled when TR2 is a 1, and disabled when TR2 is a 0.
Timer/Counter2 Setting
MODE R
CLK+TCLK CP/RL2 T2OE
Auto-reload 0 0 0
Capture 0 1 x
Baud Rate Generator 1 x 0
Clock Out Mode x 0 1

W77I058A25PL

Mfr. #:
Manufacturer:
Description:
IC MCU 8BIT 32KB FLASH 44PLCC
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet