Файл: The quintessential PIC microcontroller (S. Katzen, 2000).pdf
ВУЗ: Не указан
Категория: Не указан
Дисциплина: Не указана
Добавлен: 15.06.2025
Просмотров: 5284
Скачиваний: 0
CHAPTER 2
Logic Circuitry
We have noted that digital processing is all about transmission, manipulation and storage of binary word patterns. Here we will extend the concepts introduced in the last chapter as a lead into the architecture of the computer and microprocessor. We will look at some relevant logic functions, their commercial implementations and some practical considerations.
After reading this chapter you will:
•Understand the properties and use of active pull-up, open-collector and 3-state output structures.
•Appreciate the logic structure and function of the natural decoder.
•See how a MSI implementation of an array of ENOR gates can compare two words for equality.
•Understand how a 1-bit adder can be constructed from gates, and can be extended to deal with the addition of two n-bit words.
•Appreciate how the function of an ALU is so important to a programmable system.
•Be aware of the structure and utility of a read-only memory (ROM).
•Understand how two cross-coupled gates can implement a R S latch.
•Appreciate the di erence between a D latch and D flip flop.
•Understand how an array of D flip flops or latches can implement a register.
•See how a serial connection of D flip flops can perform a shifting function.
•Understand how a D flip flop can act as a frequency divide by two, and how a cascade of these can implement a binary count.
•See how an ALU/PIPO register can implement an accumulator processor unit.
•Appreciate the function of a RAM.
The first integrated circuits, available at the end of the 1960s, were mainly NAND, NOR and NOT gates. The most popular family of logic functions was, and still is, the 74 series transistor transistor logic (TTL); introduced by Texas Instruments and soon copied by all the major major semiconductor manufacturers.
18 The Quintessential PIC Microcontroller
[74LS00] |
1A |
(1) |
||||||
& |
(3) |
1Y |
||||||
3Y |
8 |
7 |
Vcc |
1B |
(2) |
|||
3A |
9 |
6 |
2Y |
2A |
(4) |
|||
(6) |
2Y |
|||||||
3B |
10 |
5 |
2B |
2B |
(5) |
|||
4Y |
11 |
4 |
2A |
3A |
(9) |
|||
(8) |
3Y |
|||||||
4A |
12 |
3 |
1Y |
3B |
(10) |
|||
4B |
13 |
2 |
1B |
4A |
(12) |
(11) |
4Y |
|
GND 14 |
1 |
1A |
4B |
(13) |
||||
(a) |
DIL package |
(b) |
ANSI/IEC logic symbol |
|||||
Fig. 2.1 The 74LS00 quad 2-I/P NAND package.
The 74LS001 comprises four 2-input NAND gates in a 14-pin package. The integrated circuit (IC) is powered with a 5 ± 0.25 V supply between VCC2 (usually about 5 V) and GND.The logic outputs are 2.4 – 5 V High and 0 – 0.4 V for Low. Most IC logic families require a 5 V supply, but 3 V versions are becoming available, and some CMOS implementations can operate with a range of supplies between 3 V and 15 V.
The 74LS00 IC is shown in Fig. 2.1(a) in its Dual In-Line (DIL) package. Strictly it should be described as a positive-logic quad 2-I/P NAND, as the electrical equivalent for the two logic levels 0 and 1 are Low (L is around ground potential) and High (H is around Vcc,3 usually about 5 V). If the relationship 0 → H; 1 → L is used (negative logic) then the 74LS00 is actually a quad 2-I/P NOR gate. The ANSI/IEC4 logic symbol of Fig. 2.1(b) denotes a Low electrical potential by using the polarity symbol. The ANSI/IEC NAND symbol shown is thus based on the real electrical operation of the circuit. In this case the logic coincides with a
1The LS stands for “Low-power Schottky transistor”. There are very many other versions, such as ALS (Advanced LS), AS (Advanced Schottky) and HC (High-speed Complementary metal-oxide transistor – CMOS). These family variants di er in speed and power consumption, but for a given number designation have the same logic function and pinout.
2For historical reasons the positive supply on logic ICs are usually designated as VCC; the C referring to a bipolar’s transistor Collector supply. Similarily field-e ect circuitry sometimes use the designation VDD for Drain voltage. The zero reference pin is normally designated as the ground point (GND), but sometimes the VEE (for emitter) or VSS (for Drain) label is employed.
3For historical reasons the positive supply on logic ICs are usually designated as VCC; the C referring to a bipolar’s transistor Collector supply. Similarily field-e ect circuitry sometimes use the designation VDD for Drain voltage. The zero reference pin is normally designated as the ground point (GND), but sometimes the VEE (for emitter) or VSS (for Drain) label is employed.
4The American National Standards Institution/International Electrotechnical Commission.
2. Logic Circuitry 19
positive-logic NAND function. The & operator shown in the top block is assumed applicable to the three lower gates.
The output structure of a 74LS00 NAND gate is active pull-up. Here both the High and Low states are generated by connection via a lowresistance switch to Vcc or GND respectively. In Fig. 2.2(a) these switches are shown for simplicity as metallic contacts, but they are of course transistor derived.
+Vcc |
+Vcc |
||
Phase splitter |
Phase splitter |
EN |
|
High/Low |
Off/Low |
High/Low/Off |
|
Internal logic state |
Internal logic state |
Internal logic state |
|
(a) Push/pull (Totem-pole) |
(b) Open-collector (open-drain) |
(c) Three-state |
Fig. 2.2 Output structures.
Logic circuits, such as the 74LS00, change output state in around 10 nanoseconds.5 To be able to do this, the capacitance of any interconnecting conductors and other logic circuits’ inputs must be rapidly discharged. Mainly for this reason, active pull-up (sometimes called totem-pole) outputs are used by most logic circuits. There are certain circumstances where alternative output structures have some advantages. The open-collector (or open-drain) configuration of Fig. 2.2(b) provides a ‘hard’ Low state, but the High state is in fact an open-circuit. The Highstate voltage can be generated by connecting an external resistor to either Vcc or indeed to a di erent power rail. Non-orthodox devices, such as relays, lamps or light-emitting diodes, can replace this pull-up resistor. The output transistor is often rated with a higher than usual current and/or voltage rating for such purposes.
The application of most interest to us here is illustrated in Fig. 2.3. Here four open-collector gates share a single pull-up resistor. Note the use of the symbol to denote an open-collector output. Assume that there are four peripheral devices, any of which may wish to attract the attention of the processor (eg. computer or microprocessor). If this processor has only one Attention pin, then the four Signal lines must be wire-ORed together as shown. With all Signals inactive (logic 0) the outputs of all bu er NOT gates are o (state H), and the party line is pulled up to +V by RL. If any Signal line is activated (logic 1), as in Sig_1, then the output of the corresponding bu er gate goes hard Low. This pulls
5A nanosecond is 10−9 s, so 100,000,000 transitions each second is possible.
20 The Quintessential PIC Microcontroller
|
3Sig |
2Sig |
1Sig |
0 |
||
1 |
|||||
0 |
0 |
||||
0 |
|||||
+V
RL
Off |
Off |
Off/0/Off |
0_Sig
0
Off
To processor
Fig. 2.3 Open-collector bu ers driving a party line.
the party line Low, irrespective of the state of the other signal lines, and thus interrupts the processor.
From master controller
Select_0 |
Select_1 |
Select_2 |
|||||||||
0 |
1 |
0 |
|||||||||
EN |
EN |
EN |
|||||||||
OFF |
Thing 0 |
ON |
Thing 1 |
OFF |
Thing 2 |
||||||
Data bus
d00 d01 d02 d03 |
d10 d11 d12 d13 |
d20 d21 d22 d23 |
d10
d11
d12
d13
master To
Fig. 2.4 Sharing a bus.
The three-state structure of Fig. 2.2(c) has the properties of both the preceeding output structures. When enabled, the two logic states are represented in the usual way by high and low voltages. When disabled, the output is open circuit irrespective of the activities of the internal logic circuitry and any change in input state. A logic output with this three-state is indicated by the symbol.
As an example of the use of this structure, consider the situation depicted in Fig. 2.4. Here a master controller wishes to read one of several devices, all connected to this master over a set of party lines. As this data highway or Data bus is a common resource, so only the selected device can be allowed access to the bus at any one time. The access has to be withdrawn immediately the data has been read, so that another device
2. Logic Circuitry 21
can use the resource. As shown in the diagram, each Thing connected to the bus outputs, designated by the symbol. When selected, only the active logic levels will drive the bus lines. The 74LS244 octal (×8) 3- state (sometimes called tri-state or TRIS) bu er has high-current outputs (designated by the symbol) specifically designed to charge/discharge the capacitance associated with long bus lines.
Integrated circuits with a complexity of up to 12 gates are categorised as Small-Scale Integration (SSI). Gate counts upwards to 100 on a single IC are Medium-Scale Integration (MSI), up to 1000 are known as LargeScale Integration (LSI) and over this, Very Large-Scale Integration (VLSI). Memory chips and microprocessors are examples of this latter category.
X/Y |
|||||||||||
B |
[1/2 x 74LS139] |
||||||||||
G |
(1,15) |
(9,7) |
Y |
||||||||
EN |
|||||||||||
3 |
3 |
||||||||||
(6,10) Y |
|||||||||||
2 |
2 |
||||||||||
A |
1 |
(5,11) Y |
|||||||||
1 |
|||||||||||
G |
B |
(3,13) |
1 |
0 |
(4,12) Y |
||||||
0 |
|||||||||||
A |
(2,14) |
0 |
|||||||||
G B A Y0 Y1 Y2 Y3 |
|||||||||||
Y0 |
Y1 |
Y2 |
Y3 |
0 |
0 0 |
0 |
1 |
1 |
1 |
||
0 0 1 1 0 1 1 |
|||||||||||
(a) The 74LS139 dual 2- to 4-line decoder. |
0 |
1 0 |
1 |
1 |
0 |
1 |
|||||
0 |
1 1 |
1 |
1 |
1 |
0 |
||||||
1 |
X X |
1 |
1 |
1 |
1 |
||||||
X/Y |
||||||||||||||||||||||
[74LS138] |
7 |
(7) |
Y7 |
EN C B A |
Y0 Y1 Y2 Y3 Y4 Y5 Y6 Y7 |
|||||||||||||||||
(5) |
& |
(9) |
Y |
|||||||||||||||||||
G2B |
6 |
0 |
0 0 0 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
|||||||||||
6 |
||||||||||||||||||||||
(4) |
||||||||||||||||||||||
(10) Y5 |
0 |
0 0 1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
1 |
||||||||||||
G2A |
EN |
5 |
||||||||||||||||||||
G1 |
(6) |
4 |
(11) |
Y |
0 |
0 1 0 |
1 |
1 |
0 |
1 |
1 |
1 |
1 |
1 |
||||||||
4 |
0 |
0 1 1 |
1 1 1 0 1 1 1 1 |
|||||||||||||||||||
3 |
(12) Y |
|||||||||||||||||||||
3 |
0 |
1 0 0 |
1 1 1 1 0 1 1 1 |
|||||||||||||||||||
(3) |
(13) Y |
|||||||||||||||||||||
C |
2 |
2 |
0 |
1 0 1 |
1 1 1 1 1 0 1 1 |
|||||||||||||||||
2 |
||||||||||||||||||||||
B |
(2) |
1 |
1 |
(14) |
Y |
0 |
1 1 0 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
1 |
|||||||
1 |
0 |
1 1 1 |
1 |
1 |
1 |
1 |
1 |
1 |
1 |
0 |
||||||||||||
A |
(1) |
0 |
0 |
(15) |
Y |
|||||||||||||||||
0 |
1 |
X X X |
1 1 1 1 1 1 1 1 |
|||||||||||||||||||
(b) The 74LS138 3- to 8-line decoder
Fig. 2.5 The 74LS138 and ’139 MSI natural decoders.
22 The Quintessential PIC Microcontroller
The NAND gate networks shown in Fig. 2.5 are typical MSI-complexity ICs. Remembering that the output of a NAND gate is logic 0 only when all its inputs are logic 1 (see Fig. 1.2(c) on page 13) then we see that for any combination of the Select inputs B A (21 20) in Fig. 2.5(a) only one gate will go to logic 0. Thus output Y2 will be activated when B A = 10. The associated truth table shows the circuit decodes the binary address B A so that address n selects output Yn. The 74LS139 is described as a dual 2 to 4-line natural decoder. Dual because there are two such circuits in the one chip. The symbol X/Y denotes converting code X (natural binary) to code Y (unary – one of n). The Enable input G is connected to all gates in parallel. Thus the decoder function only operates if G is Low (logic 0). If G is High, then irrespective of the state of B A (the X entries in the truth table denote a ‘don’t care’ situation) all outputs remain deselected – logic 1. An example of the use of the 74LS139 is given in Fig. 2.23.
The 74LS138 of Fig. 2.5(b) is similar, but implements a 3 to 8-line decoder function. The state of the three address lines C B A (22 21 20) n selects one only of the eight outputs Yn. The 74LS138 has three Gate inputs which generate an internal Enable signal G2B · G2A · G1. Only if both G2A and G2B are Low and G1 is High will the device be enabled. The 74LS138 is used in Fig 11.10 on page 287 to decode microcontroller port lines to enable several devices to communicate to the one port.
A large class of ICs implement arithmetic operations. The gate array illustrated in Fig. 2.6 detects when the 8-bit byte P7…P0 is identical to the byte Q7…Q0. Eight ENOR gates each give a logic 1 when its two input bits Pn, Qn are identical, as described on page 14. Only if all eight bit pairs are the same, will the output NAND gate go Low. The 74LS688 Equality comparator also has a direct input G into this NAND gate, acting as an overall Enable signal.
The ANSI/IEC logic symbol, shown in Fig. 2.6(b) uses the COMP label to denote the arithmetic comparator function. The output is prefixed with the numeral 1, indicating that its operation P=Q is dependent on any input qualifying the same numeral; that is G1. Thus the active-Low Enable input G1 gates the active-Low output, 1P=Q.
One of the first functions beyond simple gates to be integrated into a single IC was that of addition. The truth table of Fig. 2.7(a) shows the Sum (S) and Carry-Out (C1) resulting from the addition of the two bits A and B and any Carry-In (C0). For instance row 6 states that adding two 1s with a Carry-In of 0 gives a Sum of 0 and a Carry-Out of 1 (1 + 1 + 0 =10). To im- plement this row we require to detect the pattern 1 1 0; that is A · B · C0; which is gate 6 in the logic diagram. Thus we have by ORing all applicable patterns together for each output:
S= (A · B · C0) + (A · B · C0) + (A · B · C0) + (A · B · C0)
C1 = (A · B · C0) + (A · B · C0) + (A · B · C0) + (A · B · C0)
2. |
Logic Circuitry |
23 |
|||||
P7 |
(17) |
P7=Q7 |
|||||
[74LS688] |
|||||||
Q7 |
(18) |
||||||
1 |
|||||||
P6 |
(15) |
P6=Q6 |
G1 |
||||
(16) |
|||||||
Q6 |
|||||||
P5 |
(13) |
P5=Q5 |
17 |
7 |
|||
15 |
|||||||
(14) |
|||||||
Q5 |
|||||||
13 |
|||||||
P4 |
(11) |
P4=Q4 |
11 |
||||
(12) |
8 |
P |
|||||
Q4 |
|||||||
(19) |
P=Q |
||||||
6 |
|||||||
(8) |
|||||||
P3 |
P3=Q3 |
4 |
|||||
(9) |
|||||||
Q3 |
2 |
||||||
0 |
19 |
||||||
1P=Q |
|||||||
P2 |
(6) |
P2=Q2 |
|||||
(7) |
18 |
||||||
Q2 |
7 |
||||||
16 |
|||||||
P1 |
(4) |
P1=Q1 |
14 |
||||
(5) |
|||||||
Q1 |
12 |
||||||
P0 |
(2) |
P0=Q0 |
9 |
Q |
|||
(3) |
7 |
||||||
Q0 |
|||||||
5 |
|||||||
G |
(1) |
Enable |
3 |
0 |
|||
(a) Logic function |
(b) ANSI/IEC logic symbol |
Fig. 2.6 The 74LS688 octal equality detector.
Using such a circuit for each column of a binary addition, with the Carry-Out from column k−1 feeding the Carry-In of column k means that the addition of any two n-bit words can be simultaneously implemented. As shown in Fig. 2.7(b), the 74LS283 adds two 4-bit nybbles in 25 ns. In practice the final Carry-Out C4 is generated using additional circuitry to avoid the delays inherent on the carries rippling though each stage from the least to the most significant digit. n 74LS283s can be cascaded to implement addition for words of 4 × n width. Thus two 74LS283s perform a 16-bit addition in 45 ns; the extra time being accounted for by the carry propagation between the two units.
Adders can of course be coaxed into subtraction by inverting the minuend and adding one, that is 2’s complementation. An Adder/Subtractor circuit could be constructed by feeding the minuend word through an array of XOR gates acting as programmable inverters (see page 14). The Mode line Add/Sub in Fig. 2.8 that controls these inverters also feeds the Carry-In, e ectively adding one when in the Subtract mode.
Extending this line of argument leads to the Arithmetic Logic Unit (ALU). An ALU is a circuit which can undertake a selection of arithmetic and logic processes on input data as controlled by Mode inputs. The 74LS382 in Fig. 2.9 processes two 4-bit operands in eight ways, as controlled by the three Select bits S2 S1 S0 and tabulated in Fig. 2.9(a). Besides