Professional Documents
Culture Documents
Logic circuits
Chapter summary
This chapter introduces electronic circuits and devices that are associated
with digital rather than analogue circuitry. These logic circuits are used
extensively in digital systems and form the basis of clocks, counters, shift
registers and timers.
The chapter starts by introducing the basic logic functions (AND, OR,
NAND, NOR, etc.) together with the symbols and truth tables that describe
the operation of the most common logic gates. We then show how these
gates can be used in simple combinational logic circuits before moving
on to introduce bistable devices, counters and shift registers. The chapter
concludes with a brief introduction to the two principal technologies used
in modern digital logic circuits, TTL and CMOS.
Solution
In order to operate the lamp, switch A and either
switch B or switch C must be operated. The truth
table is shown in Fig. 10.8.
Logic gates
Logic gates are circuits designed to produce the
basic logic functions, AND, OR, etc. These circuits
are designed to be interconnected into larger,
more complex, logic circuit arrangements. Since
these circuits form the basic building blocks of all
digital systems, we have summarized the action
of each of the gates in the next section. For each Figure 10.8 See Example 10.1
gate we have included its British Standard (BS)
symbol together with its American Standard (MIL/
ANSI) symbol. We have also included the truth
tables and Boolean expressions (using ‘ + ’ to
denote OR, ‘·’ to denote AND, and ‘−’ to denote
NOT). Note that, while inverters and buffers each
have only one input, exclusive-OR gates have two Figure 10.9 Symbols and truth table for a buffer
inputs and the other basic gates (AND, OR, NAND
and NOR) are commonly available with up to eight
inputs.
Buffers (Fig. 10.9)
Buffers do not affect the logical state of a digital
signal (i.e. a logic 1 input results in a logic 1 output Figure 10.10 Symbols and truth table for an
whereas a logic 0 input results in a logic 0 output). inverter
Buffers are normally used to provide extra current
drive at the output but can also be used to AND gates (Fig. 10.11)
regularize the logic levels present at an interface.
AND gates will only produce a logic 1 output
The Boolean expression for the output, Y, of a
when all inputs are simultaneously at logic 1. Any
buffer with an input, X, is:
other input combination results in a logic 0 output.
Y=X The Boolean expression for the output, Y, of an
AND gate with inputs, A and B, is:
Inverters (Fig. 10.10)
Y=A∙B
Inverters are used to complement the logical
state (i.e. a logic 1 input results in a logic 0 OR gates (Fig. 10.12)
output and vice versa). Inverters also provide
OR gates will produce a logic 1 output whenever
extra current drive and, like buffers, are used
any one, or more, inputs are at logic 1. Putting
in interfacing applications where they provide a
this another way, an OR gate will only produce
means of regularizing logic levels present at the
a logic 0 output whenever all of its inputs are
input or output of a digital system. The Boolean
simultaneously at logic 0. The Boolean expression
expression for the output, Y, of a buffer with an
for the output, Y, of an OR gate with inputs A and
input, X, is:
B is:
Y=X
Y=A+B
190
Figure 10.11 Symbols and truth table for an AND Figure 10.13 Symbols and truth table for a NAND
gate gate
Figure 10.12 Symbols and truth table for an OR Figure 10.14 Symbols and truth table for a NOR
gate gate
NAND gates (Fig. 10.13)
NAND (i.e. NOT-AND) gates will only produce a
logic 0 output when all inputs are simultaneously
at logic 1. Any other input combination will
produce a logic 1 output. A NAND gate, therefore,
is nothing more than an AND gate with its output
inverted! The circle shown at the output denotes Figure 10.15 Symbols and truth table for an
this inversion. The Boolean expression for the exclusive-OR gate
output, Y, of a NAND gate with inputs A and B is:
Y=A∙B
Combinational logic
NOR gates (Fig. 10.14) By using a standard range of logic levels (i.e.
NOR (i.e. NOT-OR) gates will only produce a logic voltage levels used to represent the logic 1 and
1 output when all inputs are simultaneously at logic 0 states) logic circuits can be combined in
logic 0. Any other input combination will produce order to solve complex logic functions.
a logic 0 output. A NOR gate, therefore, is simply
an OR gate with its output inverted. A circle is Example 10.2
again used to indicate inversion. The Boolean A logic circuit is to be constructed that will
expression for the output, Y, of a NOR gate with produce a logic 1 output whenever two or more
inputs, A and B, is: of its three inputs are at logic 1.
Y=A+B
Solution
Exclusive-OR gates (Fig. 10.15) This circuit could be more aptly referred to as a
Exclusive-OR gates will produce a logic 1 output majority vote circuit. Its truth table is shown in
whenever either one of the inputs is at logic 1 and Fig. 10.16. Fig. 10.17 shows the logic circuitry
the other is at logic 0. Exclusive-OR gates produce required.
a logic 0 output whenever both inputs have the
Example 10.3
same logical state (i.e. when both are at logic 0 or
both are at logic 1). The Boolean expression for Show how an arrangement of basic logic gates
the output, Y, of an exclusive-OR gate with inputs (AND, OR and NOT) can be used to produce the
A and B is: exclusive-OR function.
Y=A∙B+B∙A
191
R-S bistables
The simplest form of bistable is the R-S bistable.
This device has two inputs, SET and RESET,
and complementary outputs, Q and Q . A logic 1
applied to the SET input will cause the Q output
to become (or remain at) logic 1 while a logic
1 applied to the RESET input will cause the Q
output to become (or remain at) logic 0. In either
Figure 10.16 See Example 10.2 case, the bistable will remain in its SET or RESET
state until an input is applied in such a sense as to
change the state.
Two simple forms of R-S bistable based on cross-
coupled logic gates are shown in Fig. 10.19.
Fig. 10.19(a) is based on NAND gates while
Fig. 10.19(b) is based on NOR gates.
Solution
In order to solve this problem, consider the
Boolean expression for the exclusive-OR function: Figure 10.18 See Example 10.3
Y = A ⋅B +B ⋅ A
Bistables
The output of a bistable has two stable states
(logic 0 or logic 1) and, once set in one or other
of these states, the device will remain at a
particular logic level for an indefinite period until
reset. A bistable thus constitutes a simple form
of ‘memory cell’ because it will remain in its
Figure 10.19 R-S bistables using cross-coupled
latched state (whether set or reset) until a signal
NAND and NOR gates
192
0 0 QN No change in state of
the Q output on the next
clock transition
0 1 0 Q output changes to 0
(i.e. Q is reset) on the
next clock transition
1 0 1 Q output changes to 1
(i.e. Q is set) on the next
clock transition
1 1 QN Q output changes to the
opposite state on the
next clock transition
Figure 10.21 Timing diagram for the D-type Note: QN+1 means ‘Q after next clock transition’ while QN
bistable means ‘Q in whatever state it was before’
193
J-K bistables are the most sophisticated and the next stage. Note that all data transfer occurs
flexible of the bistable types and they can be on the falling edge of the clock pulse.
configured in various ways including binary
dividers, shift registers and latches. Example 10.4
Fig. 10.22 shows the arrangement of a four-stage A logic arrangement has to be designed so that
binary counter based on J-K bistables. The timing it produces the pulse train shown in Fig. 10.27.
diagram for this circuit is shown in Fig. 10.23. Devise a logic circuit arrangement that will
Each stage successively divides the clock input generate this pulse train from a regular square
signal by a factor of two. Note that a logic 1 input wave input.
is transferred to the respective Q-output on the
Solution
falling edge of the clock pulse and all J and K
inputs must be taken to logic 1 to enable binary A two-stage binary divider (based on J-K bistables)
counting. can be used together with a two-input AND gate
as shown in Fig. 10.26. The waveforms for this
Fig. 10.24 shows the arrangement of a four- stage
logic arrangement are shown in Fig. 10.28.
shift register based on J-K bistables. The timing
diagram for this circuit is shown in Fig. 10.25.
Note that each stage successively feeds data to
Figure 10.23 Timing diagram for the four-stage binary counter shown in Fig. 10.22
194
195
Many microprocessors designed for control and Table 11.1 Binary, denary and hexadecimal
instrumentation applications make use of an 8-bit Binary Denary Hexadecimal
data bus and a 16-bit address bus. Others have (base 2) (base 10) (base 16)
data and address buses which can operate with 0000 0 0
as many as 128-bits at a time. 0001 1 1
The largest binary number that can appear on an 0010 2 2
8-bit data bus corresponds to the condition when 0011 3 3
all eight lines are at logic 1. Therefore the largest 0100 4 4
value of data that can be present on the bus at 0101 5 5
any instant of time is equivalent to the binary 0110 6 6
number 11111111 (or 255). Similarly, the highest 0111 7 7
address that can appear on a 16-bit address
1000 8 8
bus is 1111111111111111 (or 65,535). The full
1001 9 9
range of data values and addresses for a simple
1010 10 A
microprocessor of this type is thus:
1011 11 B
Data from 00000000
1100 12 C
to 11111111 1101 13 D
Addresses from 0000000000000000 1110 14 E
to 1111111111111111 1111 15 F
Data representation
a $ symbol before a hexadecimal number or add
Binary numbers – particularly large ones – are an H to the end of the number. For example, 64
not very convenient. To make numbers easier means decimal ‘sixty-four’; whereas $64 means
to handle we often convert binary numbers to hexadecimal ‘six-four’, which is equivalent to
hexadecimal (base 16). This format is easier decimal 100. Similarly, 7FH means hexadecimal
for mere humans to comprehend and offers the ‘seven-F’, which is equivalent to decimal 127.
advantage over denary (base 10) in that it can be
converted to and from binary with ease. The first Example 11.1
16 numbers in binary, denary and hexadecimal Convert hexadecimal A3 into binary.
are shown in Table 11.1. A single hexadecimal
character (in the range zero to F) is used to Solution
represent a group of four binary digits (bits). This From Table 11.1, A = 1010 and 3 = 0011. Thus
group of four bits (or single hex character) is A3 in hexadecimal is equivalent to 10100011 in
sometimes called a nibble. binary.
A byte of data comprises a group of eight bits.
Thus a byte can be represented by just two Example 11.2
hexadecimal (hex) characters. A group of 16 Convert binary 11101000 binary to hexadecimal.
bits (a word) can be represented by four hex
characters, 32 bits (a double word by eight hex Solution
characters, and so on). From Table 11.1, 1110 = E and 1000 = 8. Thus
The value of a byte expressed in binary can be 11101000 in binary is equivalent to E8 in
easily converted to hex by arranging the bits in hexadecimal.
groups of four and converting each nibble into
hexadecimal using Table 11.1.
Note that, to avoid confusion about whether a
number is hexadecimal or decimal, we often place
206
Table 11.3 A simple example program immediately to the interrupt. In the case of a
Address Data Assembly Comment maskable interrupt, the processor’s response
code will depend upon whether interrupts are currently
2002 DB FF IN A, (FFH) Get a byte from enabled or disabled (when enabled, the CPU
Port A will suspend its current task and carry out the
2002 2F CPL Invert the byte requisite interrupt service routine).
2003 D3 FE OUT (FEH), A Output the byte The response to interrupts can be enabled
to Port B
or disabled by means of appropriate program
2005 C3 00 20 JP 2000 Go round again instructions. In practice, interrupt signals may be
generated from a number of sources and since
each will require its own customized response a
mechanism must be provided for identifying the
source of the interrupt and calling the appropriate
interrupt service routine. In order to assist in this
task, the microprocessor may use a dedicated
programmable interrupt controller chip.
A microcontroller system
Fig. 11.11 shows the arrangement of a typical
microcontroller system. The sensed quantities
(temperature, position, etc.) are converted to
Figure 11.10 (a) Flowchart for the example corresponding electrical signals by means of
program and (b) the eight bytes of program code a number of sensors. The outputs from the
stored in memory sensors (in either digital or analogue form) are
passed as input signals to the microcontroller.
to remember mnemonics. The flowchart for the The microcontroller also accepts inputs from the
program is shown in Fig. 11.10(a). user. These user-set options typically include
The program occupies a total of eight bytes of target values for variables (such as desired room
memory, starting at a hexadecimal address of temperature), limit values (such as maximum
2000 as shown in Fig. 11.10(b). You should also shaft speed) or time constraints (such as ‘on’ time
note that the two ports, A and B, each have and ‘off’ time, delay time, etc.).
unique addresses; Port A is at hexadecimal The operation of the microcontroller is controlled
address FF and Port B is at hexadecimal by a sequence of software instructions known as
address FE. a control program. The control program operates
continuously, examining inputs from sensors, user
Interrupts
settings and time data before making changes to
A program that simply executes a loop indefinitely the output signals sent to one or more controlled
has a rather limited practical application. In most devices.
microprocessor systems we want to be able to
The controlled quantities are produced by the
interrupt the normal sequence of program flow
controlled devices in response to output signals
in order to alert the microprocessor to the need
from the microcontroller. The controlled device
to do something. We can do this with a signal
generally converts energy from one form into
known as an interrupt. There are two types of
energy in another form. For example, the
interrupt; maskable and non-maskable.
controlled device might be an electrical heater
When a non-maskable interrupt input that converts electrical energy from the AC mains
is asserted, the processor must suspend supply into heat energy, thus producing a given
execution of the current instruction and respond temperature (the controlled quantity).
214
In most real-world systems there is a requirement The output port signals can be connected to a
for the system to be automatic or self-regulating. number of devices, including:
Once set, such systems will continue to operate XXLED indicators (both individual and multiple bar
without continuous operator intervention. The types);
output of a self-regulating system is fed back XXLED seven-segment displays (via a suitable
to its input in order to produce what is known interface);
as a closed-loop system. A good example of a XXmotors and actuators (both linear and
closed-loop system is a heating control system rotary types) via a suitable buffer/driver or a
that is designed to maintain a constant room dedicated interface;
temperature and humidity within a building XXrelays (both conventional electromagnetic
regardless of changes in the outside conditions. types and optically couple solid-state types);
In simple terms, a microcontroller must produce XXtransistor drivers and other solid-state
a specific state on each of the lines connected switching devices.
to its output ports in response to a particular
combination of states present on each of the Input devices
lines connected to its input ports (see Fig. 11.11). Input devices supply information to the computer
Microcontrollers must also have a central system from the outside world. In an ordinary
processing unit (CPU) capable of performing personal computer, the most obvious input device
simple arithmetic, logical and timing operations. is the keyboard. Other input devices available on
The input port signals can be derived from a a PC are the mouse (pointing device), scanner,
number of sources, including: and modem. Microcontrollers use much simpler
input devices. These need be nothing more
XXswitches (including momentary action
than individual switches or contacts that make
push-buttons);
and break, but many other types of device are
XXsensors (producing logic-level compatible
also used including many types of sensor that
outputs);
provide logic-level outputs (such as float switches,
XXkeypads (both encoded and unencoded types).
proximity detectors, light sensors, etc.).
It is important to note that, in order to be microcontroller systems often use much simpler
connected directly to the input port of a output devices. These may be nothing more than
microcontroller, an input device must provide LEDs, piezoelectric sounders, relays and motors.
a logic compatible signal. This is because In order to be connected directly to the output
microcontroller inputs can only accept digital port of a microcontroller, an output device must,
input signals with the same voltage levels as once again, be able to accept a logic compatible
the logic power source. The 0 V ground level signal.
(often referred to as VSS in the case of a CMOS Where analogue quantities (rather than simple
microcontroller) and the positive supply (VDD in the digital on/off operation) are required at the
case of a CMOS microcontroller) is invariably 5 V output a digital-to-analogue converter (DAC) will
± 5%. A level of approximately 0 V indicates a logic be needed. All of the functions associated with
0 signal and a voltage approximately equal to the a DAC can be provided by a single integrated
positive power supply indicates a logic 1 signal. circuit. As with an ADC, the output resolution of a
Other input devices may sense analogue DAC depends on the number of bits and 8, 10 and
quantities (such as velocity) but use a digital 12 bits are common in control applications.
code to represent their value as an input to the
microcontroller system. Some microcontrollers Interface circuits
provide an internal analogue-to-digital converter Finally, where input and output signals are not
(ADC) in order to greatly simplify the connection logic compatible (i.e. when they are outside the
of analogue sensors as input devices, but where range of signals that can be connected directly
this facility isn’t available it will be necessary to to the microcontroller) some additional interface
use an external ADC which usually takes the form circuitry may be required in order to shift the
of a single integrated circuit. The resolution of the voltage levels or to provide additional current
ADC will depend upon the number of bits used drive. Additional circuitry may also be required
and 8-, 10- and 12-bit devices are common in when a load (such as a relay or motor) requires
control applications. more current than is available from a standard
logic device or output port. For example, a
Output devices common range of interface circuits (solid-state
Output devices are used to communicate relays) is available that will allow a microcontroller
information or actions from a computer system to be easily interfaced to an a.c. mains-connected
to the outside world. In a personal computer load. It then becomes possible for a small
system, the most common output device is the microcontroller (operating from only a 5 V d.c.
flat-screen display. Other output devices include supply) to control a central heating system
printers and modems. As with input devices, operating from 240 V a.c. mains.
Figure 11.12 An analogue input signal can be connected to a microcontroller input port via
an analogue-to-digital converter (ADC)
216
Figure 11.13 An analogue output signal can be produced by connecting a digital-to-analogue converter
(DAC) to a microcontroller output port
217