8253 54-1
8253 54-1
8253 54-1
8254
1. Operating frequency 0 - 10 MHz. 2. Uses H-MOS technology. 3. Read-Back command available. 4. Reads and writes of the same counter can be interleaved.
In this chapter, where the things are common 8253/54 is mentioned and 8254 is mentioned specifically for giving only information about 8254.
9.2 Features
1) Three independent 16-bit down counters. 2) 8254 can handle inputs from DC to 10 MHz (5MHz 8254-5 10MHz 8254-2) where as 8253 can operate upto 2.6 MHz. (224) 8MHz 8254
Microprocessors
225
3) Three counters are identical presettable, and can be programmed for either binary or BCD count. 4) Counter can be programmed in six different modes. 5) Compatible with all Intel and most other microprocessors. 6) 8254 has powerful command called READ BACK command which allows the user to check the count value, programmed mode and current mode and current status of the counter.
D7 D6 D5 D4 D3 D2 D1 D0 CLK0 OUT0 GATE0 GND 1 2 3 4 5 6 7 8 9 10 11 12 8254 24 23 22 21 20 19 18 17 16 15 14 13 VCC WR RD CS A1 A0 CLK2 OUT2 GATE2 CLK1 OUT1 GATE1
RD WR A0 A1 CS
Counter 1
Counter 2
Microprocessors
226
Fig. 9.2 shows the block diagram of 8253/54. It includes three counters, a data bus buffer, Read/Write control logic, and a control register. Each counter has two input signals CLOCK and GATE and one output signal OUT. Data Bus Buffer : This tri-state, bi-directional, 8-bit buffer is used to interface the 8253/54 to the system data bus. The Data bus buffer has three basic functions. 1. Programming the modes of 8253/54. 2. Loading the count registers. 3. Reading the count values. Read/Write Logic : The Read/Write logic has five signals : RD, WR, CS and the address lines A0 and A1. In the peripheral I/O mode, the RD, and WR signals are connected to IOR and IOW, respectively. In memory-mapped I/O, these are connected to MEMR and MEMW. Address lines A0 and A1 of the CPU are usually connected to lines A0 and A1 of the 8253/54, and CS is tied to a decoded address. The control word register and counters are selected according to the signals on lines A0 and A1.
A1
0 0 1 1
A0
0 1 0 1
Selection
Counter 0 Counter 1 Counter 2 Control word Register
Control Word Register : This register is accessed when lines A0 and A1 are at logic 1. It is used to write a command word which specifies the counter to be used (binary or BCD), its mode, and either a read or write operation. Counters : These three functional blocks are identical in operation. Each counter consists of a single, 16 bit, pre-settable, down counter. The counter can operate in either binary or BCD and its input, gate and output are configured by the selection of modes stored in the control word register. The counters are fully independent. The programmer can read the contents of any of the three counters without disturbing the actual count in process.
Microprocessors
227
WRITE Operation : 1. Write a control word into control register. 2. Load the low-order byte of a count in the counter register. 3. Load the high-order byte of count in the counter register.
D7 SC1 D6 SC0 D5 RW1 D4 RW0 D3 M2 D2 M1 D1 M0 M - Mode M2 0 0 M1 0 0 1 1 0 0 M0 0 1 0 1 0 1 Mode 0 Mode 1 Mode 2 Mode 3 Mode 4 Mode 5 D0 BCD
SC - Select counter SC1 SC0 0 0 1 1 0 1 0 1 Select counter 0 Select counter 1 Select counter 2 Illegal for 8253 Read -Back command for 8254 (See Read operations)
x x
1 1
RW - Read /Write RW1 RW0 0 0 1 1 0 1 0 1 Counter latch command (See Read operations) Read / Write least significant byte only Read / Write most significant byte only Read / write least significant byte first, then most significant byte BCD : 0 1 Binary counter 16 - bits Binary coded decimal (BCD) Counter (4 Decades)
Note : Don't care bits (x) should be 0 to ensure compatibility with future Intel products
Fig. 9.3 Control word format READ Operation : In some applications, especially in event counters, it is necessary to read the value of the count in process. This can be done by three possible methods: 1. Simple Read : It involves reading a count after inhibiting the counter by controlling the gate input or the clock input of the selected counter, and two I/O read operations are performed by the CPU. The first I/O operation reads the low-order byte, and the second I/O operation reads the high order byte. 2. Counter Latch Command : In the second method, an appropriate control word is written into the control register to latch a count in the output latch, and two I/O read operations are performed by the CPU. The first I/O operation reads the low-order byte, and the second I/O operation reads the high order byte. 3. Read-Back Command (Available only for 8254) : The third method uses the Read-Back command. This command allows the user to check the count value, programmed Mode, and current status of the OUT pin and Null count flag of the selected counter(s). Fig. 9.4 shows the format of the control word register for Read-Back command.
Microprocessors
228
A0, A1 = 11 CS = 0 RD = 1 WR = 0
D7
1
D6
1
D5
D4
D3
CNT2
D2
CNT1
D1
CNT0
D0
0
COUNT STATUS
D5 D4 D3 D2 D1 D0
: : : : : :
0 = Latch count of selected counter(s) 0 = Latch status of selected counter(s) 1 = Select counter 2 1 = Select counter 1 1 = Select counter 0 Reserved for future expansion : must be 0.
Fig. 9.4 Control word register for read-back command The Read-Back command may be used to latch multiple counter output latches by setting the COUNT bit D5 = 0 and selecting the desired counter (s). Each counters latch count in held until it is read (or the counter is reprogrammed). That counter is automatically unlatched when read. Other Features of Read - Back Command (Available only for 8254) : The Read-Back command may also be used to latch status information of selected counter(s) by setting STATUS bit D4 = 0. The contents of the counter must be latched before reading. The status of a counter is then accessed by a read from that counter. The Fig. 9.5 shows the counter status format.
D7 OUTPUT
D6 NULL COUNT
D5 RW1
D4 RW0
D3 M2
D2 M1
D1 M0
D0 BCD
D7 D6 D5-D0
1 0 1 0
= OUT pin is 1. = OUT pin is 0. = NULL count. = Count available for reading. = Counter programmed mode. (see Fig. 9.3)
Fig. 9.5 Counter status format Bit D5 - D0 contains the counters programmed mode exactly as written in the last mode control word. Bit D7 contains the current status of the output pin. In 8254, it is not possible to read count from the counter, if the count is not loaded into the counting element (CE). The Bit D6 indicates whether the counting element has count or not. If D6 = 0, counting element has count otherwise null count. Interleaved Read and Write : Another feature of the 8254 is that reads and writes of the same counter may be interleaved. For example, if the counter is programmed for the two byte counts, the following sequence is valid.
Microprocessors
229
2. Write new least significant byte. 4. Write new most significant byte.
CLK GATE
OUT N N N N 0 4 0 3 0 2 0 1 0 0 FF FF FF FE
CW = 10 WR
LSB = 3
CLK
GATE
OUT N N N N 0 3 0 2 LSB = 2 0 2 0 2 0 1 0 0 FF FF
CW = 10 WR
LSB = 3
Microprocessors
230
Mode 0 : Interrupt on terminal count a) Normal Operation : 1) The output will be initially low after the mode set operation. 2) After the count is loaded into the selected count Register the output will remain low and the counter will count. 3) When the terminal count is reached the output will go high and remain high until the selected count is reloaded. b) Gate Disable 1) Gate = 1 enables counting. 2) Gate = 0 disables counting. Note : Gate has no effect on OUT.
CW = 12 WR LSB = 3 (a) Normal operation
CW = 12 WR
LSB = 2
(b) Retriggering
CLK
GATE
OUT N N N N N 0 3 LSB = 4 0 2 0 1 0 3 0 2 0 1 0 0
CW = 12 WR
LSB = 3
CLK
GATE
OUT N N N N N 0 2 0 1 0 0 FF FF FF FE 0 4 0 3
Microprocessors
231
c) New Count If a new count is written to the counter, it will be loaded on the next CLK pulse and counting will continue from the new count In case of two byte count : 1) Writing the first byte disables counting. 2) Writing the second byte loads the new count on the next CLK pulse and counting will continue from the new count. MODE 1 : Hardware Retriggerable One-shot a) Normal operation 1) The output will be initially high 2) The output will go low on the CLK pulse following the rising edge at the gate input. 3) The output will go high on the terminal count and remain high until the next rising edge at the gate input. b) Retriggering The one shot is retriggerable, hence the output will remain low for the full count after any rising edge of the gate input. c) New count If the counter is loaded during one shot pulse, the current one shot is not affected unless the counter is retriggered. If retriggered, the counter is loaded with the new count and the one-shot pulse continues until the new count expires. MODE 2 : Rate generator This mode functions like a divide by-N counter. a) Normal Operation 1) The output will be initially high. 2) The output will go low for one clock pulse before the terminal count. 3) The output then goes high, the counter reloads the initial count and the process is repeated. 4) The period from one output pulse to the next equals the number of input counts in the count register. b) Gate Disable 1) If Gate = 1 it enables a counting otherwise it disables counting (Gate = 0 ). 2) If Gate goes low during an low output pulse, output is set immediately high. A trigger reloads the count and the normal sequence is repeated.
Microprocessors
CW = 14 WR LSB = 3
232
CW = 14 WR
CLK
GATE
CW = 14 WR
CLK GATE
OUT N N N N 0 4 0 3 0 2 0 1 0 5 0 4 0 3
Note : A GATE transition should not occur one clock prior to terminal count.
Fig. 9.8 Mode 2 rate generator c) New count The current counting sequence does not affect when the new count is written. If a trigger is received after writing a new count but before the end of the current period, the new count will be loaded with the new count on the next CLK pulse and counting will continue from the new count. Otherwise, the new count will be loaded at the end of the current counting cycle. Note : In mode 2, a count of 1 is illegal.
Microprocessors
233
CW = 16 WR
CW = 16 WR
CLK GATE
OUT N N N N 0 4 0 2 0 4 0 2 0 2 0 2 0 4 0 2 0 4 0 2
Note : A GATE transition should not occur one clock prior to terminal count.
Fig. 9.9 Mode 3 square wave mode a) Normal operation 1) Initially output is high. 2) For even count, counter is decremented by 2 on the falling edge of each clock pulse. When the counter reaches terminal count, the state of the output is changed and the counter is reloaded with the full count and the whole process is repeated. 3) If the count is odd and the output is high the first clock pulse (after the count is loaded) decrements the count by 1. Subsequent clock pulses decrement the clock by 2. After timeout, the output goes low and the full count is reloaded. The first clock pulse (following the reload) decrements the count by 3 and subsequent clock pulse decrement the count by two. Then the whole process is
Microprocessors
234
repeated. In this way, if the count is odd, the output will be high for (n+1)/2 counts and low for (n-1)/2 counts. b) Gate Disable If Gate is 1 counting is enabled otherwise it is disabled. If Gate goes low while output is low, output is set high immediately. After this, When Gate goes high, the counter is loaded with the initial count on the next clock pulse and the sequence is repeated. c) New Count The current counting sequence does not affect when the new count is written. If a trigger is received after writing a new count but before the end of the current half-cycle of the square wave, the counter will be loaded with the new count on the next CLK pulse and counting will continue from the new count. otherwise, the new count will be loaded at end of the current half-cycle. MODE 4 : Software Triggered Strobe. a) Normal operation 1) The output will be initially high 2) The output will go low for one CLK pulse after the terminal count (TC). b) Gate Disable If Gate is one the counting is enabled otherwise it is disabled. The Gate has no effect on the output. c) New count If a new count is written during counting, it will be loaded on the next CLK pulse and counting will continue from the new count. If the count is two byte then 1) Writing the first byte has no effect on counting. 2) Writing the second byte allows the new count to be loaded on the next CLK pulse. MODE 5 : Hardware triggered strobe (Retriggerable). a) Normal operation 1) The output will be initially high. 2) The counting is triggered by the rising edge of the Gate. 3) The output will go low for one CLK pulse after the terminal count (TC). b) Retriggering If the triggering occurs on the Gate input during the counting, the initial count is loaded on the next CLK pulse and the counting will be continued until the terminal count is reached. c) New count If a new count is written during counting, the current counting sequence will not be affected. If the trigger occurs after the new count is written but before the terminal
Microprocessors
235
CW = 18 WR
LSB = 3
CLK GATE
OUT N N N LSB = 3 N 0 3 0 2 0 1 0 0 FF FF FF FE FF FD
CW = 18 WR CLK
GATE
CW = 18 WR
Microprocessors
CW = 1A WR CLK LSB = 3
236
GATE OUT N N N N N 0 3 0 2 0 1 0 0 FF FF 0 3
CW = 1A WR CLK
LSB = 3
Retriggering
GATE OUT N N N N N N 0 3 0 2 0 3 0 2 0 1 0 0 FF FF
CW = 1A WR CLK
LSB = 3
LSB = 5
New count
GATE OUT N N N N N 0 3 0 2 0 1 0 0 FF FF FF FE 0 5 0 4
Microprocessors
237
count, the counter will be loaded with the new count on the next CLK pulse and counting will continue from there. Table 9.1 shows the gate pin operations.
Signal Status Modes 0 1 Low or Going Low Rising High
Disables counting
Enables counting
4 5
Disables counting
SC1
1
SC2
0
RW1 RW0
1 1
M2
0
M1
0
M0
0
BCD
0 = B0H