Файл: The quintessential PIC microcontroller (S. Katzen, 2000).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 15.06.2025

Просмотров: 5271

Скачиваний: 0

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

12 The Quintessential PIC Microcontroller

analagous process to the shift and add technique for multiplication, using a combination of shifting and subtracting.

Arithmetic is not the only way to manipulate binary patterns. George Boole8 in the mid-19th century developed an algebra dealing with symbolic processing of logic propositions. This Boolean algebra deals with variables which can be true or false. In the 1930s it was realised that this mathematical system could equally well be used to analyze switching networks and thus binary logic systems. Here we will confine ourselves to looking at the fundamental logic operations of this switching algebra.

A f

A

f = A

0 1

10

A

1

f = A

(a) Truth table

(b) Alternative logic symbols

Fig. 1.1 The NOT operation.

The inversion or NOT operation is represented by overscoring. Thus f = A states that the variable f is the inverse of A; that is if A = 0 then f = 1 and if A = 1 then f = 0. In Fig. 1.1(a) this transfer characteristic is presented in the form of a truth table. By definition, inverting twice

returns a variable to its original state; thus f = f.9

Logic function implementations are normally represented in an abstract manner rather than as a detailed circuit diagram. The NOT gate is symbolized as shown in Fig. 1.1(b). The circle always represents inversion in a logic diagram, and is often used in conjunction with other logic elements, such as in Fig. 1.2(c).

The AND operator gives an all or nothing function. The outcome will only be true when every one of the n inputs are true. In Fig. 1.2 two input variables are shown, and the output is symbolized as f = B · A, where · is the Boolean AND operator. The number of inputs is not limited to two, and in general f = A(0) · A(1) · A(2) · · · A(n). The AND operator is

8The first professor of mathematics at Queen’s College, Cork.

9In days of yore when logic circuits were built out of discrete devices, such as diodes, resistors and transistors, problems due to sneak current paths were rife. In one such laboratory experiment the output lamp was rather dim, and the lecturer in charge suggested that two NOTs in series in a suspect line would not disturb the logic but would block o the unwanted current leak. On returning sometime later, the students complained that the remedy had had no e ect. On investigation the lecturer discovered two knots in the o ending wire – obviously not tied tightly enough!


1.

Digital Representation

13

B A

f

B A

f

B

f = B

A

B

f = B

A

A

A

0 0

0

0 0

1

0 1

0

0 1

1

1 0

0

B

&

f = B

A

1 0

1

B

&

f = B

A

1 1

1

1 1

0

A

A

(a) Truth table

(b) Alternative logic symbols

(c) NAND

Fig. 1.2 The AND function.

sometimes called a logic product, as ANDing (cf. multiplying) any bit with logic 0 always yields a 0 output.

If we consider B as a control input and A as a stream of data, then consideration of the truth table shows that the output follows the data stream when B = 1 and is always 0 when B = 0. Thus the circuit can be considered to be acting as a valve, gating the data through on command. The term gate is generally applied to any logic circuit implementing a fundamental Boolean operator.

Most practical AND gate implementations have an inverting output. The logic of such implementations is NOT AND, or NAND for short, and is symbolized as shown in Fig. 1.2(c).

B A

f

B

f = B + A

B A

f

B

f = B + A

A

A

0 0

0

0 0

1

0 1

1

0 1

0

1 0

1

B

>1

f = B + A

1 0

0

B

>1

f = B + A

1 1

1

1 1

0

A

A

(a) Truth table

(b) Alternative logic symbols

(c) NOR

Fig. 1.3 The inclusive-OR operation.

The inclusive-OR operator gives an anything function. Here the outcome is true when any input or inputs are true (hence the ≥ 1 label in the logic symbol). In Fig. 1.3 two inputs are shown, but any number of variables may be ORed together. ORing is sometimes referred to as a logic sum, and the + used as the mathematical operator; thus f = B + A. In an analogous manner to the AND gate detecting all ones, the OR gate can be used to detect all zeroes. This is illustrated in Fig. 2.19 on page 35 where an 8-bit zero outcome brings the output of the NOR gate to 1.


14 The Quintessential PIC Microcontroller

Considering B as a control input and A as data (or vice versa), then from Fig. 1.3(a) we see that the data is gated through when B is 0 and inhibited (always 1) when B is 1. This is a little like the inverse of the AND function. In fact the OR function can be expressed in terms of AND using the duality relationship A + B = B · A. This states that the NOR function can be implemented by inverting all inputs into an AND gate.

AND, OR and NOT are the three fundamental Boolean operators. There is one more operation commonly available as an electronic gate; the Exclusive-OR operator (XOR). The XOR function is true if only one input is true (hence the =1 label in the logic symbol). Unlike the inclusive-OR, the situation where both inputs are true gives a false outcome.

B A

f

B

f = B + A

B A

f

B

f = B + A

0 0

0

A

0 0

1

A

0 1

1

=1

0 1

0

=1

1 0 1

B

f = B + A

1 0

0

B

f = B + A

1 1

0

A

1 1

1

A

(a) Truth table

(b) Alternative logic symbols

(c) ENOR

Fig. 1.4 The XOR operation.

If we consider B is a control input and A as data (they are fully interchangeable) then:

When B = 0 then f = A; that is the output follows the data input.

When B = 1 then f = A; that is the output is the inverse of the data input.

Thus an XOR gate can be used as a programmable inverter.

Another useful property considers the XOR function as a logic di erentiator. The XOR truth table shows that the gate gives a true output if the two inputs di er. Alternatively, the ENOR truth table of Fig. 1.4(c) shows a true output when the two inputs are the same. Thus an ENOR gate can be considered to be a 1-bit equality detector. The equality of two n-bit words can be tested by ANDing an array of ENOR gates (see Fig. 2.6 on page 23), each generating the function Bk Ak; that is:

n−1

fB=A = Bk Ak k=0

As a simple example of the use of the XOR/XNOR gates, consider the problem of detecting sign overflow (see page 10). This occurs if both the sign bits of word B and word A are the same (SB SA) AND the sign


1. Digital Representation 15

bit of the outcome word C is not the same as either of these sign bits, say SB SC. The logic diagram for this detector is shown in Fig. 1.5 and implements the Boolean function:

(SB SA) · (SB SC)

SA

SA = SB

V is true if:

SB

V

(Sign A = Sign B) AND

SC

(Sign C = Sign B)

SC = SB

Fig. 1.5 Detecting sign overflow.

Finally, the XOR function can be considered as detecting when the number of true inputs are odd. By cascading n+1 XOR gates, the overall parity function is true if the n-bit word has an odd number of ones. Some measure of error protection can be obtained by adding an additional bit to each word, so that overall the number of bits is odd. This oddness can be checked at the receiver and any deviation indicates corruption.