logic, boolean algebra, and digital circuits - stem2stem2.org/je/logic.pdf · logic, boolean...

62
Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2 Related Documents 5 3 A Comment on Notation 5 4 A Note on Elementary Electronics 7 5 Boolean Algebra 8 6 Logic Operators and Truth Tables 8 7 A List of Logic Identities and Properties 9 7.1 DeMorgan’s Laws ......................... 11 8 Propositional Logic 12 9 A Truth Table Applet 13 10 Digital Logic Symbols 14 11 Disjunctive Normal Form and Minimal Disjunctive Normal Form 14 12 Prime Implicants 15 13 The Quine-McClusky Algorithm 15 1

Upload: buikiet

Post on 05-Feb-2018

226 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

Logic, Boolean Algebra, and Digital Circuits

Jim Emery

Edition 4/29/2012

Contents

1 Introduction 4

2 Related Documents 5

3 A Comment on Notation 5

4 A Note on Elementary Electronics 7

5 Boolean Algebra 8

6 Logic Operators and Truth Tables 8

7 A List of Logic Identities and Properties 97.1 DeMorgan’s Laws . . . . . . . . . . . . . . . . . . . . . . . . . 11

8 Propositional Logic 12

9 A Truth Table Applet 13

10 Digital Logic Symbols 14

11 Disjunctive Normal Form and Minimal Disjunctive NormalForm 14

12 Prime Implicants 15

13 The Quine-McClusky Algorithm 15

1

Page 2: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

14 A Quine-McClusky Applet 16

15 Relays and Switches as Logic Elements 16

16 Set Theory 16

17 Sequential Machines, Finite State Machines 17

18 Digital Electronics 17

19 The Half-Adder 17

20 The Full-Adder 19

21 Flip-Flops 20

22 The Difference Between A Latch and A Flip-Flop 20

23 SR NOR Latch 21

24 SR NAND Latch, ( Also written as SnRn NAND Latch) 22

25 The D Flip-Flop 23

26 A Verilog D Flip-Flop 23

27 The D Latch 24

28 Constructing A D Flip-Flop With a Pair of D Latches 25

29 The JK Flip-Flop 25

30 Multivibrator and Latch 26

31 The Wilkson Digital Logic Test Board 2631.1 Power: A Nine Volt Wall Wart Power Supply . . . . . . . . . 2631.2 Five Volt and Three Volt Regulated Power Supplies . . . . . . 2631.3 The 555 Timer Subcircuit . . . . . . . . . . . . . . . . . . . . 2831.4 Properties of Light Emitting Diodes . . . . . . . . . . . . . . 2931.5 Switches and Push Buttons . . . . . . . . . . . . . . . . . . . 3031.6 Storing A Logic State With A Switch . . . . . . . . . . . . . . 30

2

Page 3: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

31.7 Viewing A Logic Value With an LED . . . . . . . . . . . . . . 3131.8 Resistor Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 3131.9 The 74LS163 Synchronous 4-Bit Binary Counter . . . . . . . . 3131.10 74LVC540 Buffer-Line driver . . . . . . . . . . . . . . . . . 3331.11 The Subcircuit That Drives the LEDs on the Printed Circuit

Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3331.12 Testing the Wilkson Board With an SN74LS74AN . . . . . . 3531.13 The Solderless Breadboard . . . . . . . . . . . . . . . . . . . 3631.14 The pins from the PCB to the Breadboard . . . . . . . . . . 3631.15 The Xilinx CPLD . . . . . . . . . . . . . . . . . . . . . . . . 3731.16 The Circuit Board Pin Assignment for the XC9536XL CPLD 37

32 MUX, The Multiplexer and Demultiplexer 37

33 Programmable Logic Devices 37

34 Installing and Using the Xilinx ISE Software 38

35 Class Exercise: Create a D Flip-Flop With ISE 39

36 A Data sheet for the 74LS163 4-bit Binary Counter 39

37 More Information About Chris Wilkson’s Printed CircuitBoard: Assembly Order, Images, Bill of Materials. 40

38 A Sequential Machine: A Three Bit Binary Counter 41

39 Test Instruments and Tools for Digital Electronics 41

40 Download Cable 42

41 PCB Artist 43

42 LT Spice 43

43 A List of 7400 Series Integrated Circuits 43

44 A Class Design Project: Controlling Thunderbird Tail Lights 44

3

Page 4: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

45 Appendix A, RC Circuits, Time Constants, and the LM555Timer 4445.1 A Resistor Capacitor Circuit and the Time Constant . . . . . 44

46 Appendix B, A Xilinx ISE Tutorial 49

47 Appendix C, Introduction to the Verilog Hardware DesignLanguage 50

48 Appendix D, Running Icarus Verilog From The CommandLine in Windows 5148.1 MUX2 Program Listing . . . . . . . . . . . . . . . . . . . . . 5448.2 Running the Programs . . . . . . . . . . . . . . . . . . . . . . 54

49 Bibliography 55

50 Glossary 57

51 Constants 62

1 Introduction

This document is a preliminary draft version that is not yet complete. But Ihope there is some useful material here now, which I think some might findhelpful. More circuit diagrams will be added later. As it evolves, the latestversion will be found on the STEM2 website:

To Find it on STEM2 go to

www.stem2.org.

Select Documents and Downloads. Then select Electronics.

For A direct link:

http:\\www.stem2.org\je\logic.pdf

4

Page 5: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

2 Related Documents

Basic Electricity is a brief introduction to, and an explanation of someconcepts in electricity and electronics.

http://www.stem2.org/je/basicelectricity.pdf

Electric Circuits is an introduction to some topics in electrical engineering.

http://www.stem2.org/je/ee.pdf

Electromagnetic Theory is an outline of topics in that subject, which isa region in mathematical physics, also sometimes called, especially in olderbooks, Electricity and Magnetism. The document contains a treatmentof matters related to Maxwell’s Equations, which form the basis for classicalelectricity, magnetism, the theory of electromagnetic waves, the concept ofthe speed of light, and a foundation for optics. This is really an outline forsomeone who has already studied the subject, but by skimming over it oneunfamiliar with it might get an idea of what the subject is about, as wellas what are: electric and magnetic fields, electric potential, voltage, electricand magnetic polarization, capacitance, inductance, and even might see whyit necessarily led to relativity theory.

http://www.stem2.org/je/electromagnetictheory.pdf

3 A Comment on Notation

Logical variables take values true and false, or 0 and 1, or low and high(voltages). If a value is 1, the complementary value is 0, and if the valueis 0, then the complementary value is 1. If X is a logical variable, then itscomplement is written in several ways in this document, with a bar, as in X,or with an apostrophe as in X ′.

The labels to the pins of chips and logic gates can appear with a bar,as in CLR. The label CLR suggests that this pin causes something in thechip to be cleared, that is something to be set to zero or zeroes. Normally

5

Page 6: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

an action takes place when a value is high or equal to 1. But sometimes theaction suggested by the pin name takes place when the value is low. So thelabel CLR signifies that a pin is active low, and this does the clear whenthe value is low. This convention can be rather confusing, but it is common.Other authors might write this with a slash as in /CLR or as CLRn witha subscript n. The later signifies that the pin is active low. In verilog thissubscript version CLRn might be written as CLR n . This is recommendedbecause it can be used as a logical variable in the hardware language Verilog.Putting a bar over a variable is easy to do with handwriting, but not so easywhen writing with a computer, or in a computer generated diagram.

Conventions used for specifying that a pin is active when low are numer-ous. We have mentioned already that this might be denoted with a slashas in /LOAD, meaning the loading takes place when this pin is low. Alsopins with a small circle attached in a diagram denotes an active low pin.Another convention is to use the IEEE standard, using the so called bubblenotation or a small circle at a pin, which is to mean that the pin is activelow. This is a good method, because it avoids the ambiguity of labels andvariables. However schematic drawing programs may not support this, andit may be used by a minority of people. The IEEE standard requires bubbleto bubble labelling that may provide some light, or perhaps to some, moredark. The book in the bibliography by Wakerly has more information aboutspecifying active low pins, on symbols, on standards, and on historical usage.

As an opinionated editorial comment I think that labelling a pin with abar when it is active low is a very confused idea. A chip essentially is a func-tion with input pins and output pins. There is confusion between labellingpins, which are the inputs and outputs to functions, and the labelling of logi-cal variables. These are two different and distinct ideas and can not help butlead to ambiguity. This confusion extends to other fields such as computerprogramming and a very long time ago, to mathematics and physics. So inthe olden days in mathematics a function was a rule or computation thatfrom a variable value, say x, produced a new variable value say y. So it wasa sort of sausage machine. In modern times a function is considered a set,perhaps infinite, of ordered pairs, or of ordered n-tuples for higher dimen-sional functions. The use of the word variable is actually frowned upon a bitin mathematics, because what is this thing that varies and how does it vary?However it is not clear what we should use in place of the word variable.We do have subjects in mathematics called Complex Variables and RealVariables. So really the proper way to deal with pin labelling in chips is

6

Page 7: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

to imitate mathematics and depend on the pin order or number rather thanon a label symbol to give meaning. Then one can supply an explanation ofwhat for example, pin 5 is, with a sentence or a word. However, I thinkafter further education, that this problem is well recognized in the IEEE andin the electronics community, and so my rant may be pointless, especiallycoming from a mathematics and physics person, not an expert in electricalengineering. However consider computer programming.

In computer programming, one is instructed to give variables long ex-planatory names, so that programs are ”easier to read.” This has the samekind of difficulties described above, which I won’t go into, but comes froma simplistic understanding of algorithms, variables, functions and and thefact that algorithms are mathematical objects. This is all too common inthe computer science community, and one of the reasons I have a distaste forconventional computer science. So in summary, a symbol should not tell youwhat it is, for to do that is to restrict its use as an unknown, to restrict itsuse as something that may take on arbitrary values in various places as itsuse evolves. So perhaps too much said.

4 A Note on Elementary Electronics

What is meant by elementary electronics? Elementary algebra usually is thevery elements of the subject, the idea of a variable, or of an unknown, thetechniques of manipulating algebraic expressions, the commutative laws, theassociative laws, the distributive law, solving a simple equation, and so on.But elementary electronics seems to mean something a bit different?

My anthropological observations lead me to some answers. In one senseelementary electronics is just what beginning electronic hobbyists do. Andwhat they do typically, is not what one might call elementary electrical orelectronic engineering, but it is the assembling, building, and soldering ofelectronic circuits, and then observing what these circuits do, and then op-erating them, and then exclaiming ”cool”. So it is not the building up ofunderstanding, by studying the elements of the subject, rather it is thatwhich can be done by the beginner with perhaps very little understanding.

But the things that are built are not necessarily themselves simple. Soelementary electronics could be the building a television set, or the build-ing of a personal computer. These machines are certainly not elementary.No, elementary refers to the skills that the beginner brings to the task. So

7

Page 8: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

the theory of the detailed working of the electronic components is not partof elementary electronics. Because this would require various preparatorycourses and previous knowledge and previous skill, perhaps some mathemat-ics knowledge, and previous electrical experience.

So elementary electronics can prove to be a bit frustrating for those think-ing people who do need to know, and who do need to understand, in orderto do.

In conclusion, elementary electronics is a practical somewhat mindlessactivity, that does often brings pleasure, a pleasure similar to narcotics.

Warning A class advertising itself as a class in elementary electronics,may be a thinly veiled class in elementary or basic electrical engineering.

5 Boolean Algebra

George Boole, who lived from November 2, 1815 to December 8, 1864, pub-lished a famous book on logic, The laws of thought, in 1854. This makeshim the father of modern symbolic logic. So he invented a symbolic algebrafor logic in the first half of the nineteenth century. It has much in commonwith the modern algebra of sets, and has diverse application in many fields,including that of digital electronics.

Propositional logic, set theory, and digital logic all share the same booleanalgebra.

6 Logic Operators and Truth Tables

The ”or” operator is usually written as a ∨ in symbolic logic. So the propo-sition ”p or q” would be written p ∨ q. A + sign is usual in electronics, so”p or q” is written as p + q.

The truth table for ”or”:

p q p + q0 0 00 1 11 0 11 1 1

8

Page 9: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

The ”and” operator is sometimes written with a wedge as in p ∧ q. Butoften in electronics the operator is omitted as we do in algebra for multipli-cation. So the ”and” operator is implied when two variables are adjacent.So we write pq as we do for the multiplication of numbers.

The truth table for ”and”:

p q pq0 0 00 1 01 0 01 1 1

The ”inverter” :The inverter changes the input value to its opposite.

The ”nor” and the ”nand” :By inverting the outputs of the ”or” and ”and” we get the ”nor” and ”nand.”The truth tables for ”nor” and ”nand” are obtained by changing 0 to 1 and1 to 0 in the outputs of the ”or” and ”and”.

The Exclusive ”or” :The exclusive ”or”, written ”xor” has output 0 if both inputs are 1.

The truth table for ”xor”:

p q p ⊕ q0 0 00 1 11 0 11 1 0

7 A List of Logic Identities and Properties

I should give here a list of seventeen logical identities that Cris Wilkersonsupplied in one of his lectures. However, I did not write them down in my

9

Page 10: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

R1

C1

L1

10 Volts

120 V C2

D1

NPN

PNP

OpAmp

FET

IC

IC

IC

POT

Label

Wire

Connect

AND NAND OR NOR

XOR INV

1 2 3 4 5 6 7 8 9 10

11 12 13 14 15 16 17 18 19 20

21 22 23 24 25 26 27 28 29 30

31 32 33 34 35 36 37 38 39 40

41 42 43 44 45 46 47 48 49 50

51 52 53 54 55 56 57 58 59 60

61 62 63 64 65 66 67 68 69 70

71 72 73 74 75 76 77 78 79 80

81 82 83 84 85 86 87 88 89 90

91 92 93 94 95 96 97 98 99 100

101 102

103104

Figure 1: Circuit Symbols. A display of circuit elements available in theprogram cdiagram for creating a circuit diagram, including the standardsymbols for logic gates. Node numbers, which are shown here, are used tolocate the elements. 10

Page 11: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

notes. Some of them are pretty obvious I think, but DeMorgan’s laws areprobably not.

7.1 DeMorgan’s Laws

I could write these laws in propositional logic, set theory, or in electroniclogic notation.

I will do it in set theory. The idea is that you change each variable toits complement, the entire expression to its complement, and change theoperator to its dual operator. So for sets, change union to intersection andso on.

SoA ∪ B = (A′ ∩ B′)′

andA ∩ B = (A′ ∪ B′)′,

where apostrophe specifies the complement.In the case of electronics and logic this can be proved with truth tables.

In set theory you prove that the left side is a subset of the right, and thatthe right is a subset of the left, and therefore the sets are equal.De Morgan’s Laws Let A and B be sets, then

A ∪ B = (A′ ∩ B′)′

andA ∩ B = (A′ ∪ B′)′.

Proof. Suppose x ∈ A ∪ B. Without loss of generality suppose x ∈ A.Then x is not in A′, so x is not in A′ ∩ B′ then it is in the complement,x ∈ (A′ ∩ B′)′. So

A ∪ B ⊂ (A′ ∩ B′)′.

On the other hand suppose x ∈ (A′ ∩ B′)′. Then x is not in A′ ∩ B′

without loss of generality suppose x /∈ B′, then x ∈ B, therefore x ∈ A ∪ B.Then

(A′ ∩ B′)′ ⊂ A ∪ B.

SoA ∪ B = (A′ ∩ B′)′.

A similar technique shows that

A ∩ B = (A′ ∪ B′)′.

11

Page 12: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

8 Propositional Logic

A proposition is a logical statement that can be true or false. A combi-nation of such statements, which involves n propositional variables can beanalyzed using a truth table with n input columns and one output columncorresponding to the combination. For example, the statement r = (if p thenq) is considered false if and only if p is true and q is false, otherwise it is true.This has the same truth table as ”not ( p and (not q)) = (not p) or q.” Wehave reached the equality by applying one of DeMorgan’s laws. Symbolicallythis equality is written

p ⇒ q = ¬(p ∧ ¬q) = ¬p ∨ q,

and is read as p¯

implies q.Now given two propositions p and q, if both

p ⇒ q,

andq ⇒ p,

then p and q are called logically equivalent. Logical equivalence can bewritten as

p ⇔ q,

or(¬p ∨ q) ∧ ((¬q ∨ p).

A logical proposition that is always true is called a tautology. So p and q arelogically equivalent if the proposition

p ⇔ q

is always true.Now consider the problem of minimizing gates in a digital circuit. Sup-

pose we apply the Karnough map method, the Quine-McKlusky method,or apply various Boolean Algebra identities to reach a minimal number ofgates. We would like to know if the application of these methods has indeedproduced a logically identical circuit, that is we want to check that we havenot made a mistake. This can be done by examining the truth tables forthe two expressions. But this can be rather tedious, and error prone itself.

12

Page 13: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

We can use use a computer program to compute the truth tables. The nextsection introduces an applet to do this. However, the two truth tables maynot produce truth tables that have the same ordering of columns, or of rows,which makes visual comparison difficult. However, suppose the original cir-cuit has p for a boolean algebra representation, and the minimized circuithas expression q. So if we compute the truth table for

(¬p ∨ q) ∧ (¬q ∨ p),

then the circuits are equivalent if all outputs have values ”true” or ”1”, andthis is easy to see from the resulting truth table no matter how the rows andcolums are arranged.

9 A Truth Table Applet

Here is a link to an applet that constructs a truth table from a propositionallogic expression:

http://www.aiai.ed.ac.uk/~gwickler/truth-table.html

The expression is entered in polish notation , also called prefix notation,where the operator preceeds the operand or operands. So writing an arith-metic problem in ordinary notation, also called infix notation, we write forexample the sum of 2 and 3 as

2 + 3.

In polish or prefix notation we would write this as

(+ 2 3).

To show thatp ⇒ q

is logically equivalent to¬p ∨ q,

for example, we type into the program

(<=> (or (not p) q) (=> p q))

Then we select compute. From the truth table we find this to be a tautology,which means it is true for all values of the variables.

13

Page 14: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

10 Digital Logic Symbols

The figure labelled Circuit Symbols shows some standard electrical sym-bols including those for logic gates.

11 Disjunctive Normal Form and Minimal Dis-

junctive Normal Form

The word disjunction in logic corresponds to ”or”, and in set theory to union,whereas conjunction corresponds to ”and”, and to intersection in set theory.So for example, in set theory, an element x is in the union of two sets A∪Bif x ∈ A or x ∈ B. In logic if p and q are propositions, then ” p or q”, written

p ∨ q,

is the disjunction of p and q. Each of p and q is called a disjunct. Inelectronics we would write this disjunction as

p + q.

Given a truth table for a function f , a logical function can be foundthat has that truth table by keeping only the rows for which f is 1. Thussuppose we have variables p, q, r, s and a row where f is 1, and p = 0, q =1, r = 1, s = 0. Then p′qrs′ is called a disjunct and is 1 if and only ifp = 0, q = 1, r = 1, s = 0. Thus it implies f . So if we write a logicalexpression as a sum of products, each product is called a disjunct becausethe finale expression is a sum of these products. If the disjuncts for all ofthe rows for which f = 1 are summed, then this sum, has the specified truthtable. The use of the terms disjunct and conjunct tends to be confusingcaused I suppose by the concepts of operator, and operand. So a disjunctioncorresponds to an operation, while disjuncts are the operands, the elementsbeing operated upon. The sum of all the products where the value is 1 inthe truth table is called a disjunctive normal form. So a disjunctive normalform is a sum of products. A disjunctive normal form need not be a minimaldisjunctive normal form. In electronics we want a minimal disjunctive normalform in order to attempt to minimize the number of gates in a digital circuit.The term ”minterm” is sometimes used for disjunct.

14

Page 15: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

For more information, see the books on digital circuits and logic in thebibliography, or go to Linda Hall library, which is on Cherry St on the UMKCcampus, to find a cornucopia of books on the subjects.

12 Prime Implicants

Prime implicants are products in which redundant variables have been re-moved. A product or disjunct P implies F if whenever P = 1 then F = 1.The product is a prime implicant if whenever a factor is removed from P toform Q, then Q no longer implies F . So suppose A1, A2, A3 are basic logicalvariables and P = A1A2A3 Suppose P = 1, so necessarily A1 = 1, A2 =1, A3 = 1. If F = 1 in this case then P implies F . So P is an implicant of F .But now suppose variable A2 is removed from P to give R = A1A3 and R stillimplies F . This means that setting A1 = 1, A3 = 1 still makes F = 1. Thismeans that P is not a prime implicant. So if a disjunct P implies F then ifany variable in the product that is set to zero does not change F = 1, thenthat variable is redundant. When all redundant factors have been removedfrom P then the resulting product is a prime implicant.

13 The Quine-McClusky Algorithm

This is an algorithm to find the minimal disjunctive normal form for a booleanfunction. It is essentially equivalent to the Karnaugh map method, but caneasily be computerized, so can handle larger problems than the Karnaughmap. It works by finding the essential prime implicants. A logical expressionp implies q if whenever p is true then q is true. If p implies q, then p is saidto be an implicant of q.

However, the Quine-McClusky Algorithm is NP-complete, which meansvery roughly that the size of the computation grows exponentially with thesize n of the problem. In this case n is the number of logical variables. Sothe method will work only for a relatively small n. It would not be practicalfor example if n = 15.

For more information, see the books on digital circuits and logic in thebibliography, or go to Linda Hall library on the UMKC campus to find aplethora of books on the subjects. Quine was a famous American logicianand philosopher.

15

Page 16: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

There are several Quine-McClusky program on the internet, it might beeducational to write one myself.

14 A Quine-McClusky Applet

Here is a link to a Quine-McClusky applet that I found from bethel.edu:

http://www.mathcs.bethel.edu/~gossett/DiscreteMathWithProof/QuineMcCluskey.html

One enters an expression like the following

D2D′0 + D′

2D1D0 + D2D1

by clicking on the minterms or implicants in a display of inputs to a truthtable.

There are many such applets available apparently. This is the first oneI tried and appears to be a nice one. So from this full disjunctive form, aminimal disjunctive normal form is computed by the Java applet.

15 Relays and Switches as Logic Elements

See below for a simple circuit consisting of a resistor and a switch for storinglogical values. A similar representation can be automated with relays, andwith the an electronic switch, a transistor.

16 Set Theory

The theory of sets has an algebra similar to Boolean algebra and to thetheory of propositional logic. Set theory is much more than this though,since it includes infinite sets, strange things like the Axiom of Choice,transfinite numbers, hierarchies of infinities, cardinal numbers and ordinalnumbers. There are many books devoted to set theory. Many advancedmathematics books start with a condensed coverage of set theory. If youhave a mathematical inclination see for example the book Topology byDugundji, or books on Measure Theory or on Real Analysis.

16

Page 17: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

17 Sequential Machines, Finite State Machines

The machine may reside in a finite set of states. An output value dependsboth on the state and the input. The next state function depends also onthe current state and on the input.

See Nagle et al in the bibliography.

18 Digital Electronics

Digital electronics works with discrete voltage levels, such as the TTL voltagelevels of 5 volts for the high logic value, representing a high logic state ofone, and a 0 voltage representing low logic value of zero. Digital circuits areconstructed with electronic logic gates, one or more gates being packaged inintegrated circuit chips. This contrasts with analog electronics, where voltagelevels are continuous.

19 The Half-Adder

The half-adder is a digital circuit made up of a few gates that computes theaddition of a pair of binary bits, but does not consider the input of a carrybit. So the half adder computes from the inputs A and B, the sum bit S,and the carry bit C. Here is a truth table for the half-adder isThe truth table for the ”half-adder”:

A B S C0 0 0 00 1 1 01 0 1 01 1 0 1

There are several ways to implement the half adder. One way is to com-pute the sum as an ”exclusive or,” and the carry as an ”and”. Thus

S = A ⊕ B,

C = A + B.

See the figure labelled Adders.

17

Page 18: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

A

B S

C

Half-Adder

A

B

C

S

C0

Full-Adder

Figure 2: Half-Adder and Full-Adder. The half-adder gives the sum oftwo bits A amd B, generates a sum bit S, and generates a carry bit C. Thefull-adder adds A and B and an input carry bit C and generates a sum bitS, and an output carry bit C0. See the text for equations.

18

Page 19: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

20 The Full-Adder

The full-adder computes the sum of two bits A and B and a carry bit C. Sojust adding A + B + C for each possibility, and writing the result in binarywe have

0 + 0 + 0 = 0 = 00

0 + 0 + 1 = 1 = 01

0 + 1 + 0 = 1 = 01

0 + 1 + 1 = 2 = 10

1 + 0 + 0 = 1 = 01

1 + 0 + 1 = 2 = 10

1 + 1 + 0 = 2 = 10

1 + 1 + 1 = 3 = 11

So we get:The truth table for the ”full-adder”:

C A B CO S0 0 0 0 00 0 1 0 10 1 0 0 10 1 1 1 01 0 0 0 11 0 1 1 01 1 0 1 01 1 1 1 1

where C is the input carry, CO is the output carry, and S is the sum. So

CO = C ′AB + CA′B + CAB′ + CAB

= (C ′ + C)AB + CA(B′ + B) + CB(A + A′)

= AB + CA + CB

19

Page 20: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

andS = C ′A′B + C ′AB′ + CA′B′ + CAB

= A ⊕ (B ⊕ C).

Notice that the truth table is divided into parts where the input carry iszero and where the input carry is 1. So the input carry bit could be used asinput to a multiplexer to use one logic circuit when the carry input is 0, andanother when the carry input is 1. A multiplexer is abbreviated as MUX.

Strings of full adders can be combined to created a circuit capable ofadding multi-bit binary numbers. Such circuits form components of computerprocessors.

See the figure labelled Adders.

21 Flip-Flops

A flip-flop is a digital circuit that can be in either of two states, zero or one,and so stores a logical value. Signals at its inputs, together with the currentstate, cause a change in state of the flip-flop and a change in the output onthe next clock edge. A latch is also sometimes called a flip-flop.

Flip-flops can be divided into common types: the SR latch or flip-flop(”set-reset”), D (”data” or ”delay”), T (”toggle”), and the JK. The behavioris controlled by the characteristic equation, which is the next state functionand defines Qnext . The characteristic equation is a function of the currentstate and the input (or inputs). The current state Q will become equal toQnext at the next clock edge.

22 The Difference Between A Latch and A

Flip-Flop

The distinction between a latch and a flip-flop is that a latch does not dependon a clock pulse to switch states, a flip-flop does. A latch is level sensitivewhereas a flip-flop is transition sensitive. Usually the flip-flop changes stateon the rising edge of a clock pulse. A latch is used as a memory element tostore data, and retains a constant value until it is set or reset. A flip-floppotentially changes state at each rising edge of the clock pulse.

20

Page 21: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

23 SR NOR Latch

This is a simple latch, sometimes called a Set-Reset flip-flop, that can beconstructed with a pair of NOR gates. This is accomplished by using crossover feedback connections between the two chips. There is no clock pulse.This latch can be constructed with two NOR gates. Call them A and B. Oneof the inputs to gate A is S. One of the inputs to gate B is R. The outputof gate B is called Q, the output of gate A is the complement of Q labelledQ. The second input to gate A is the output of gate B. And the secondinput to gate B is the output of gate A. The output of gate A is labelled Q.So to justify our labelling we must show that the outputs of gates A and Bare complements of one another. So if S = 1, and R = 0 then the output ofNOR gate A is necessarily 0, independently of what its second input is. Thatis Q = 0. This is fed back to the input of gate B, and because R is the otherinput to B and R = 0, then the output of gate B, which is Q, is necessarily1. So the output of the gate B, which is Q is 1. So we have consistency without labelling. So if S = 1 and R = 0 then the output of the latch is 1. Thatis S = 1 sets the latch to high.

The circuit is symmetrical, so in the case of R = 1 and S = 0 we findthat Q = 1 and Q = 0 and the labelling is consistent. So inputs of R = 1and S = 0 resets the output of the latch to 0. So S stands for set, and R forreset.

Now suppose the latch has been set with S = 1, and R = 0, so that Q = 1and Q = 0. Suppose S changes to S = 0 and R remains at R = 0. We claimthat if the state of the latch remains at Q = 1 (and Q = 0) then the cicuitis stable so that Q = 1 remains the output with the new inputs. BecauseQ = 1 is fed back to NOR gate A, the output of A is 1, that is Q = 0. Onthe other hand because Q = 1 is fed back to NOR gate B, the output of Bis 0, that is Q = 0. The circuit is stable, there is no change in output.

Similarly if the latch has been reset with R = 1, and S = 0, then if Rchanges to zero and S remains at zero then there is no change in output.

However, the change to inputs S = 1, and R = 1, does not give a stablecircuit, so these inputs are forbidden. (see the figure to be drawn)

The truth table for the ”SR NOR latch”:

21

Page 22: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

S R Q0 0 Previous Output0 1 01 0 11 1 Forbidden Inputs

24 SR NAND Latch, ( Also written as SnRn

NAND Latch)

An SnRn latch can also be built from a pair of NAND gates. In this case theoutput Q is set and reset when the inputs are low rather than high as is thecase for the SR NOR latch. We signify that the action takes place when theinputs are low by writing them as Sn and Rn. We could also write them as/S and /R. The analysis is nearly the same as that for the SR NOR latchgiven in the previous section. In this new circuit, the pair of NOR gates arereplaced by a pair of NAND gates, with the same previous feedback connec-tions, except that the output Q is taken from NAND gate A rather than B.That is the input to gate A is S, and the input to gate B is R. (see the figureto be drawn)

The truth table for the SnRn NAND Latch:

Sn Rn Q0 0 Forbidden Inputs0 1 11 0 01 1 Previous Output

A Verilog Module for the SnRn NAND Latch

module rs_latch(

input r_n;

input s_n;

output q;

22

Page 23: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

output q_n;

);

assign q=!(s_n*q_n);

assign q_n=!(r_n*q);

endmodule

25 The D Flip-Flop

The D flip-flop is a basic flip-flop that is frequently used internally to con-struct more complex logic chips. The D stands for delay. When the data pinis set it does not transfer its value to the output pin Q immediately. Thisoccurs on the next rising clock edge sensed at the clock pin. So the output is”delayed.” The D flip-flop may be built from SR NAND Latches. See belowfor the use of the dual D type positive edge triggered flip-flop SN74LS74AN,to produce a symmetric square wave from a nonsymmetric 555 pulse train,and which functions as a divide by two counter.

Flip-flops are event triggered devices, so are not purely combinatorial logicdevices. Action takes place on the event of a rising edge clock signal. Theverilog HDL (Hardware Definition Language) does deal with event triggereddevices.

26 A Verilog D Flip-Flop

This program demonstrates verilog’s ability to deal with event driven devices.This ability is demonstrated below in the ”always” statement.Verilog D Flip-Flop

1 // D flip-flop Code

2 module d_ff ( d, clk, q, q_bar);

3 input d ,clk;

4 output q, q_bar;

5 wire d ,clk;

6 reg q, q_bar;

7

8 always @ (posedge clk)

9 begin

10 q <= d;

23

Page 24: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

11 q_bar <= ! d;

12 end

13

14 endmodule

27 The D Latch

The D latch is not an event driven device, there is no clock signal. So it isa purely combinatorial logic device. The D latch may be constructed from aSnRn NAND latch and is nearly equivalent to what is called a SnRn NANDlatch with enable ( See Wakerly). The D latch has two inputs, D and Gand two outputs Q and Qn. The three wire statements below define localvariables in the following verilog program (As I write this I have not yet triedto run the following program in ISE, so it may well contain errors. I do notknow if verilog distinguishes between upper and lower case. I assume it does,and I assume mixing lower and upper case will cause compiler errors. It iseasy for me to do such mixing. )

Verilog D Latch

module D_latch (

input D;

input G;

output Q;

output Q_n;

);

wire S_n;

wire R_n;

wire D_n; // I assume this is necessary?

assign D_n = !D;

assign S_n =!(G*D_n);

assign R_n = !(D*G);

RS_latch(R_n,S_n,Q,Q_n);

endmodule;

24

Page 25: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

28 Constructing A D Flip-Flop With a Pair

of D Latches

So a D Flip-Flop is an event triggered device. It is slightly amazing thatby adding a simple clock input and using two combinatorial D latches, wecan construct an event driven device that reacts to rising clock edges. Eventdriven devices can not be described by simple truth tables, but we need todisplay their action with timing diagrams. They are sequential machines andhave a state, and a next state function.Verilog D Flip-Flop Using the D Latch Module

module D_Flip-Flop (

input D;

input C;

output Q;

output Q_n;

);

wire Q1;

wire Q1_n;

wire C_n;

assign C_n = !C;

D_latch(D,C_n,Q1,Q1_n);

// According to the notes, there is a subtlety here in assigning

// Q_n caused by a glitch in the timing diagram, but I

// don’t recall the details.

D_latch(Q1,G,Q,Q_n);

endmodule;

29 The JK Flip-Flop

The JK flip-flop is like a D flip-flop, but has two inputs, with labels J and K.Let Q be the output. If J and K are different, then the output Q takes thevalue of J at the next clock edge. Put another way if J and K are differentthen J high sets the output to 1, and K high resets the output to 0. If Jand K are both low then no change occurs. If J and K are both high at

25

Page 26: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

the clock edge then the output will toggle from one state to the other. Thecharacteristic equation is

Qnext = JQ + KQ.

30 Multivibrator and Latch

A latch and a multivibrator are circuits related to flip-flops. A latch is nottriggered by a clock pulse, as the flip-flop is.

A multivibrator is a somewhat more general device, and can be used inboth digital and in analog circuits. It was used long before digital electronicswas invented. In an analog circuit it may be used as a square wave oscillator.So for example, the rectangular horizontal and vertical sync pulses in analogtelevision signals are generated by multivibrators. It was called a multivi-brator because the square pulses it generates has many harmonics (Fouriercomponents) and so many multivibrations.

31 The Wilkson Digital Logic Test Board

This digital test board is used to test, study, and design digital circuits. Theprinted circuit board is constructed to be mounted onto a plastic breadboard.Pins on the bottom of the PCB fit into the breadboard. External connectionsare made from a series of pins mounted to the PCB.

31.1 Power: A Nine Volt Wall Wart Power Supply

There is a jack on the PCB that accepts a 1/8th inch plug from a nine voltDC power supply. The wall wart we are using is a Jameco (see below).

31.2 Five Volt and Three Volt Regulated Power Sup-

plies

Five volts is available for powering TTL chips. This voltage is supplied witha 7805, a five volt voltage regulator. As an aside, although this regulator isdesigned to provide a regulated five volts, it can be tricked into supplyingother regulated voltages. The LM7805 is a three pin chip with a metal plate

26

Page 27: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

on the back that may be attached to a heat sink with a screw through thehole in the plate. This chip can get hot. Looking at the chip from the front,the pin on the left is the input pin. It is connected to an unregulated positivevoltage at a higher voltage than 5 volts. In our case this voltage is beingsupplied by the positive nine volts from the wall wart. See the data sheetfor the allowed input voltage range. The center pin is the ground pin. Theright pin is the output pin where the regulated five volts is available.

A 3.3 voltage is on the board for supplying CMOS chips. This voltage issupplied with a LM317 voltage regulator. The LM317 is a variable voltageregulator. Here external components are selected to make it have an outputof 3.3 volts. This is done as follows in the following way. First note that thepin order for the 317 differs from that for the LM7805. Looking at the frontof the chip, the left pin is called the adjustment pin, which is connected toa resistor called R2, and also is connected to a second resistor and then theresistor is to ground. The center pin is the output pin where the regulatedvoltage is available. The right pin is the input pin, in our case connected tothe nine volt unregulated voltage from the wall wart. This voltage can be ina range described in the data sheet. The LM317 has the property that thevoltage at the output pin is always at 1.25 volts above that at the adjustmentpin. There is a resister R1 between the output pin and the adjustment pin.These two resistors R1 and R2 determine the magnitude of the regulatedoutput voltage. So let iq be the current flowing from the adjustment pin.Let i2 be the current flowing through resistor R2 to ground. Let i1 be thecurrent flowing through R1 from the output pin to the adjustment pin. Thenthe current flowing through resister R2 is the sum of the current flowing fromthe chip to the adjustment pin, and the current flowing through R1. That is

i2 = iq + i1.

But as stated above, the voltage across R1 is always maintained at 1.25volts. Therefore

i1 =1.25

R1R2.

Let the voltage v2 be the voltage across resistor R2,

v2 = i2R2 = (iq + i1)R2

= iqR2 +1.25

R1.

27

Page 28: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

Let v0 be the voltage at the output pin. Then

v0 = 1.25 + v2

= 1.25 +1.25

R1R2 + iqR2

= 1.25(1 + R2/R1) + iqR2.

However the current out of the chip into the adjustment pin is very small, sowe can write approximately that

vO = 1.25(1 + R2/R1).

In our circuit we have specified R1 = 240 and R2 = 390 Ohms. So theregulated output voltage is

vO = 1.25(1 + 390/240) = 3.28volts.

31.3 The 555 Timer Subcircuit

A clock pulse is supplied with a 555 timer. This LM555 circuit here createsa rectangular wave of frequency controlled by a potentiometer. It runs inwhat is referred to in the National Semiconductor data sheet, as the astablemode. A nice reference for the way the 555 works internally is the bookMake: Electronics by Charles Platt. A resistor RA is connected betweenpin 8 and pin 7 of the 555. Pin 8 is connected to the 5 volt positive supplyvoltage. A resistor RB connects pin 7 to pin 6. A capacitor C connects pin6 to ground. The wave is controlled by the charging and discharging of Cthrough the resistors. When the output signal is low the internal flip-flopgrounds pin 7 and also grounds the output pin 3. In this part of the cycle thecapacitor is discharging from a voltage equal to 2/3 of the supply voltage toa voltage equal to 1/3 of the supply voltage. This voltage on the capacitoris fed back to the pin 2 input of the 555. When the voltage at pin 2 reaches1/3 of the supply voltage, a comparator connected to pin 2 flips the flip-flopto disconnect pin 7 from ground and also connects the output pin, pin 3 tothe 5 volt supply voltage. This does two things, starts a positive pulse inthe output signal, and also causes the capacitor to be charged through theresistors RA and RB. When the capacitor reaches 2/3 of the supply voltage,a comparator connected internally between pins 6 and 5 turns on and flipsthe flip-flop back to restart the cycle.

28

Page 29: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

See ee.pdf (source ee.tex) for an analysis of the charging and dischargingon STEM2 for the latest version. See also a current version in the Appendix.It is shown there, in the section on the RC circuit, that the frequency of thewave is given by

f =1/ ln(2)

C(RA + 2RB)=

1.4427

C(RA + 2RB),

which is a formula that also occurs in the National Semiconductor data sheet(pp6-7) for the LM555. In the version of the astable circuit that we are usinghere, pin 6 and pin 7 are joined, so that the effective value of RB is verysmall. This makes the discharge very fast so that the low pulse is very short,and the high pulse is nearly the entire period of the wave. So the frequencythen is

f =1.4427

CRA.

In our circuit the resistor RA is a 1k resistor in series with a 100k poten-tiometer. If we use C = .1µF then we may adjust the frequency between

f1 =1.4427

(.1 × 10−6)(1000)= 1.44 × 104 = 14.4kHZ

and

f2 =1.4427

(.1 × 10−6)(101 × 103)= 142.8Hz.

On the other hand if C = 100µF then the frequency ranges from

f1 =1.4427

(100 × 10−6)(1000)= 14.4HZ

to

f2 =1.4427

(100 × 10−6)(101 × 103)= .142HZ

31.4 Properties of Light Emitting Diodes

Light Emitting Diodes emit photons when they are forward biased. Too muchvoltage will cause too much current and heat and will destroy the diode. Soa resistor of small value is placed in series to limit the current. So supposea LED is connected in series with a resistor R = 270Ω to a five volt voltage

29

Page 30: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

source. In a specific circuit we measured a voltage drop across the resistorof 3.2 volts. This means that the voltage drop across the diode was

v = 5 − 3.2 = 1.8.

So an LED usually drops on the order of 2 volts. This voltage drop doesdepend on the current. In this case the current was

i =3.2

270= 11.9mA.

So the diode was dissipating

(1.8)(11.9) = 21.42mW.

This energy loss is in the form of both light and heat.The long lead of a LED is usually positive, the short end negative. Most

multimeters have a socket for testing diodes. They can also be tested andthe polarity checked by checking their resistance with a multimeter.

31.5 Switches and Push Buttons

The board contains two sets of toggle switches, (the white switch blocks)and two black push button switches. The toggles may be placed into threestates. These switches may be used to set certain binary constants and forcontrolling data and setting values on chips. I believe that pushing a blackbutton connects one of the external pins to ground.

31.6 Storing A Logic State With A Switch

Suppose the logic high voltage is v = 5 volts. Consider such a voltageconnected to a resistor R = 10k, in series with a switch and the switchconnected to ground. The value stored is the voltage at the junction of theresistor and the switch. If the switch is open the current flowing through theresistor is near zero, so the voltage is high at 5 volts. If the switch is closed,the resistor junction is connected to ground, so the output is 0 volts. So anopen switch stores a logic value 1, and a closed switch stores a logic valuezero. With the switch closed the current is

i =5

10000= .5 × 10−3A = .5mA.

30

Page 31: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

31.7 Viewing A Logic Value With an LED

Suppose an LED has its positive terminal connected to a positive sourcevoltage, and its negative terminal to a node whose voltage level is to bemeasured. If the level is high, then no current flows and the LED is not on.If the level is low, then current flows through the diode and the LED is on.A resistor is needed in series with the LED to limit the current. A resistorof value about 270Ω will limit the current and prevent the destruction of theLED. It would be better if the LED glowed with a high voltage. This canbe accomplished by confecting a logic inverter between the node being beingread, and the LED. The LED will now glow when the signal is high, and turnoff when the signal is low. A line driver inverter may be used, one such asthe 74LS74, which also contains an amplifier, with high input impedance tolimit the current draw from the circuit element whose voltage is measured.

31.8 Resistor Arrays

A resistor array is a collection of several resistors in one package. Typicallyit looks like a long bug with a single row of pins. One pin labelled with a dotis the common terminal, and usually has a square pin. The resistance fromthe common pin to each of the other pins is some fixed resistance, say 270Ω.Such an array might be used to serve as the resistors for a set of LEDs.

31.9 The 74LS163 Synchronous 4-Bit Binary Counter

An example part number for a synchronous 4-Bit Binary Counter is theNational semiconductor DM74LS161A. The Texas Instruments data sheetfor the SN74LS163A has been stored as a local file with name 74LS163ti.pdf.The chip has 16 pins. Here is a list of them:The Pins for the Fairchild DM74LS163A:

31

Page 32: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

1 CLR2 CLK3 A4 B5 C6 D7 ENP8 GRD9 LOAD10 ENT11 OD12 OC13 OB14 OA15 RCO16 VCC

A explanation of the pins:

CLR if this is low, zero levels are entered in the outputs OA, OB,OC,OD.CLK The state change takes place during a rising edge of the clock pulse.ENP The Clock is active only if this enable is high.GRD The negative ground supply connectionLOAD when this value is low the A, B,C,D values are copied to the outputsOA, OB,OC,OD.ENT The clock is active only if this enable is high. The ripple carry requiresa high value here.RCO Ripple Carry Output. This pin is set high when all four output pinsOA, OB, OC, OD are high and ENT is high.VCC the positive supply connection

There is some good material on the 163 binary counter in the bookDigital Design by John F. Wakerly, pp 595-607.

An example use of the 163. Here is a circuit that will turn on theoutput pins in sequence, and then turn them off in sequence, and then re-

32

Page 33: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

peat the cycle. Suppose ENP and ENT are permanently held high, LOAD ispermanently set low, and the following pairs are connected. OA is connectedto B, OB to C, OC to D, and an inverted OD to A. The CLR pin is con-nected to one of the two push buttons On the breadboard. The connectingwire from is connected to hole j2 on the breadboard. When the button ispressed CLR is connected to ground and thus causes zeroes to be copiedto the outputs. So suppose in the beginning all outputs OA, OB, OC, ODare low. Because OD is complemented and copied to A, A will be high.Now the LOAD pin is always low, so on the next clock pulse the valuesat the data pins A, B, C, D are copied to the outputs OA, OB, OC, OD.In the beginning the data pins B, C, D are low. So after the clock pulsethe outputs OA, OB, OC, OD = 1000. These are connected to LEDs soonly the first LED is lit. Now because of the feedback connections to thedata pins A, B, C, D, these pins now have the values A, B, C, D = 1100.During the next clock pulse these values are copied to the outputs, so nowOA, OB, OC, OD = 1100, and after the next pulse OA, OB, OC, OD = 1110,next OA, OB, OC, OD = 1111. Now we have a change, since OD = 1 causesA = 0. So after the next clock pulse OA, OB, OC, OD = 0111. Now thesame way in which the one was propagated to the other positions, the zerogets propagated, until eventually OA, OB, OC, OD = 0000. Now the wholecycle starts over.

31.10 74LVC540 Buffer-Line driver

One may use the internet to find the data sheet for this chip. Such a datasheet has been stored as a local PDF file on my computer with the name74LVC540.pdf. This is a CMOS surface mount chip.

See all about circuits, buffers:

http://www.allaboutcircuits.com/vol_4/chpt_3/3.html

31.11 The Subcircuit That Drives the LEDs on thePrinted Circuit Board

Refer to the notes for December 31, 2011. A diagram will be drawn. Fromthis circuit diagram we see that the node between each LED and its currentlimiting 270 Ohm resistor is not accessible. Therefore the LRDs can not bedimmed by switching in another resistor. So the only means to dim the LEDS

33

Page 34: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

74LS163

GRD

/CLR

CLK

D0

D1

D2

D3

ENP

/LD

ENT

Q3

Q2

Q1

Q0

RCD

VCC

Figure 3: LS163 4-bit binary counter example. Here is the samplecircuit for turning on LEDs in sequence, then turning them off as describedin the text. The enable pins ENP and ENT are permanently set high so thatthe clock is always enabled, the load pin is permanently low so that load isalways active, the CLR can be set low with a push button, but appears tobe unnecessary. The output pins are connected to LEDs, so the LEDs cycleon, then cycle off one by one.

34

Page 35: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

is to use a high frequency pulse width modulation signal with an adjustableduty cycle.

31.12 Testing the Wilkson Board With an SN74LS74AN

The SN74LS74AN or DM74LS74A is a dual D type positive edge triggeredflip-flop. The rising edge of the approximately 2 µ second off pulse from the555 is used to get a symmetric square wave of 1/2 the frequency of the 555.

A rising edge from the 555 signal causes a count of 1, so turns on apositive pulse. When the next rising edge is encountered, whatever is atD is copied to the output Q. And the complimentary value is copied to Q.This complimentary value is fed back to the D input, so that on the nextrising input the value at Q will be the compliment. Thus the output changesfrom high to low, then low to high, then high to low and so on. This is thedivide-by-two counter, see Mims Engineer’s Notebook II p53.

The SN74LS74AN may also be used as a line driver and inverter.The Pins for the Fairchild DM74LS74A:

1 CLR12 D13 CLK14 PR15 Q16 Q17 GRD8 VCC9 CLR210 D211 CLK212 PR213 Q214 Q2

Explanation of pins:

If CLR is low, Q is Cleared to 0 and Q to 1.CLK The value at D is copied to Q during a rising edge of the clock pulse.

35

Page 36: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

If PR is low, Q is Preset to 1 and Q to 0.GRD The negative ground supply connection.VCC the positive supply connection.If CLR and PR are both high, they are disabled.

31.13 The Solderless Breadboard

The PCB fits on top of a Jameco Solderless Breadboard JE24 which has1360 contact points, a red power strip near the center of the board with 100contacts along the length of the board, and a similar blue power strip. Theboard measures 6.5 by 3.25 (actually 6.5 by 3.125) inches and has two bindingposts, which are removed to make way for the PCB. The contact points onthe left side have coordinates (A,1) to (J,63) and the same coordinates onthe right side. Looking at the board so that the two binding posts are atthe top, there a 63 rows of contact points, each row is divided into 4 sets of5 contacts. Each 5 contacts are connected together. In each row, the firstfive contacts on the left have letter labels a,b,c,d,e. across the trough, thenext set of five have labels f,g,h,i,j. Then going across the center blue andred vertical power strips in the center of the board, we find on the right sideof the board, two more sets of five labelled a,b,c,d,e, then across the troughthe set f,g,h,i,j.

31.14 The pins from the PCB to the Breadboard

On the right side of the breadboard, contacts j1 to j4 connect to the two blackpush-buttons in ways that depends on whether they are presses or released.Contact j6 connects to the output pin of the 555, so is the clock signal. j7and j8 connect to the capacitor that controls the frequency of the 555 clock.j8 is the negative connection, and j7 is the positive. j11 connects to the firstred LED (the one nearest the top of the breadboard), j12 to the second, j13to the third, j14 to the fourth, j15 to the fifth, j16 to the sixth, j17 to theseventh, and j18 to the eighth.

On the left hand side of the board, a1,...a8 connect to points betweenthe toggle switches and the resisters in a resistor array to store logic values.a10,...a17 connect to points between the toggle switches and the resister ina resistor array to store logic values.

36

Page 37: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

Setting the toggle switches .... has the following effect:

31.15 The Xilinx CPLD

The Xilinx XC9536XL chip is a CPLD (Complex Programable Logic Device)mounted into a socket on the PCB. The data sheet for the XC9536XL canbe found on the internet. I have stored a copy as file

xc9536xl.pdf

31.16 The Circuit Board Pin Assignment for the XC9536XL

CPLD

Here is a file showing the connections to the XC9536XL pins:

http://www.stem2.org/je/IO_Board_v100_CPLD_Pinout.pdf

32 MUX, The Multiplexer and Demultiplexer

MUX is Short for multiplexer. A multiplexer has n inputs, 1 output, and aselect pin or pins. From a select signal, it selects from a number of inputsand sends the selected input to a single output.DMUX is Short for demultiplexer. This is the inverse of a MUX. A demul-tiplexer has 1 input and n outputs with a select pin or pins. From a selectsignal it selects one from n output ports, and sends the single input signalto the selected port.

See the Wikipedia article on multiplexers. It gives a list of common 7400series multiplexer and demultiplexer chips.

33 Programmable Logic Devices

CPLD is an abbreviation for ”Complex Programmable Logic Device.”A Xilinx XC9536XL chip is part of the test circuit board.

Xilinx

XC9536XL

PCG44AWN1029

37

Page 38: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

F4109624A

10C

Xilinx supplies free software, called ISE, for programming this chip andother chips. A digital circuit can be constructed with the software usingeither a schematic design process or a verilog text program. Then this circuitis downloaded from the computer to the chip to create physical hardware inthe chip.

A huge number of logic devices are available in the Xilinx software. Forexample, we constructed in class a 163 binary counter circuit, using a Xilinxlibrary module for the 163. We then downloaded it to the chip, using aspecial wiring connector belonging to Chris.Other Programmable Logic Array Acronyms: PAL ”ProgrammableArray Logic”, FPGA ”Field Programmable Gate Array.”

Here is a link for downloading the programming software from Xilinx:

http://www.xilinx.com/support/download/index.htm

The download file is huge, being about 5 GBytes. Transferring the down-loaded file to another computer via a flash drive can be a problem, becauseflash drives tend to be formatted as FAT32. This format can only handle filesthat are less than 4 GBytes. However, if the tar file is untarred, we obtaina folder containing many smaller files, which can be handled in the FAT32Windows format.

34 Installing and Using the Xilinx ISE Soft-

ware

The software installation can be a bit complex. The software is free, but alicence file must be obtained from the Xilinx WEB site. After registering, afile is mailed to your email address. This file is required in order to make thesoftware work.

The best way to learn how to install the software, and to run the GUI(Graphical User Interface), is to have someone familiar with the softwarehelp you. It is a myth that GUI software is easy to use, especially if it israther complex software. Don’t be shy about asking for help. After all it is

38

Page 39: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

just stupid software, running on a stupid computer. Those who think theyare geniuses because they know how to run a software program, or a candyvending machine for that matter, should seek psychological help.

One might blunder through with madcap clicking, and yet not rememberwhat was clicked. It is rather difficult to record the icon clicking steps, inthe same way as it is difficult to record all of the keys presses when learningto play Scarlatti, by watching Vladamir Horowitz. The secret to learningthis sort of thing, is to have a skilled music teacher show you how, and thenpractice, practice, practice. After that, you will be able to tell people howto get to Carnegie Hall.

There are some tutorials available for Xilinx ISE on the internet. See thelinks below and a pdf copy of the html tutorial. The tutorial shows how tobuild a half adder from primary logic gates.

After the program for the logic has been created with the software, itis downloaded from the PC to the physical chip. There is a special wiringharness for downloading this data. This harness is quite expensive, althoughthere appears to be a cheap Chinese knockoff available.

35 Class Exercise: Create a D Flip-Flop With

ISE

As an exercise, using the Xilinx ISE software, create two D latches andconnect them as described above to make a D flip-flop. Download it to yourboard and test it.

36 A Data sheet for the 74LS163 4-bit Binary

Counter

The Fairchild version of this 4-bit Binary Counter is named the DM74LS163A.The Texas Instruments data sheet for their version of this chip is stored onmy computer as74LS163TI.pdf

39

Page 40: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

37 More Information About Chris Wilkson’s

Printed Circuit Board: Assembly Order,

Images, Bill of Materials.

Here are some links to information about Chris Wilkson’s printed circuitboard from the Digital Electronics Class of 2011. First is a list of a suggestedassembly order. This is obtained from the following link to a documentcalled Assembly Order of Wilkson’s Circuit Board, which gives sug-gestions about the order of soldering on components, together with variousother notes.

http://www.stem2.org/je/assemblyorder.pdf

Next are images of a Top View and Bottom View of the completed board:

http://www.stem2.org/je/toppcb.jpg

http://www.stem2.org/je/botpcb.jpg

Here is a Bill of Materials for the board:

http://www.stem2.org/je/IO_Board_v100_BOM.pdf

These files can also be reached by going to the stem2 web site:

http://www.stem2.org

Select Downloads and Documents, and then Electronics.

40

Page 41: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

38 A Sequential Machine: A Three Bit Bi-

nary Counter

See notes Dec 31, 2011. The three bits are stored in three D-Flip-Flops. Thesingle input resets the Flip-Flops to zero when it is zero. The current stateis D = 0, 1, 2, 3, 4, 5, 6, 7. The next state function is Q = D +1. So the truthtable isThe truth table is:

D2 D1 D0 Q2 Q1 Q0

0 0 0 0 0 10 0 1 0 1 00 1 0 0 1 10 1 1 1 0 01 0 0 1 0 11 0 1 1 1 01 1 0 1 1 11 1 1 0 0 0

Let us find the next state bit functions for the three bits of Q = Q2Q1Q0

.

Q2 = D′2D1D0 + D2D

′1D

′0 + D2D

′1D0 + D2D1D

′0

= D′2D1D0 + D2D

′1D0 + D2D

′0

= (D′2D1 + D2D

′1)D0 + D2D

′0

= (D2 ⊕ D1)D0 + D2D′0

The Quine-McClusky applet I mentioned above finds

Q2 = D2D′0 + D′

2D1D0 + D2D1.

39 Test Instruments and Tools for Digital Elec-

tronics

The following test instruments and tools are useful for digital electronics. Asoldering station with a grounded tip. A digital multimeter. Cheap multi-meters are available at Harbor Freight for sometimes the unbelievable price

41

Page 42: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

of 3.95 dollars. A nicer model at 19.95 measures capacitance and comeswith a thermocouple for measuring temperatures. A cheap solder sucker(spring loaded) can be purchased at the MicroCenter computer store for afew shekels, four bucks or so. A good oscilloscope is also quite useful. I alsopurchased a cheap capacitance and inductance meter on the internet. Flushcut diagonal pliers are cheap at harbor freight. Also Harbor freight carries aset of cheap jeweller eye loupes, which prove quite handy for reading the mi-croscopic printing on many electronic components. A logic pulser and probecould be very useful.

40 Download CableFrom Tim Middleton:

Friday, December 2, 2011 7:00 PM

Sweeet!

It came in the mail today weeeeeeeeeeeee.........

Gonna try using it after dinner.

Sent from my iPad

On Nov 20, 2011, at 2:49 PM, tim middleton <[email protected]> wrote:

> Electronics class. . .

>

> I have located and ordered a DLC9G (DownLoadCable) for programming the

CPLD chips we have been working with in class. I feel I have learned

enough to move forward with having my own programming cable so

I ordered it this morning.

>

> It will arrive some time in 2011 from Hong Kong . . . if there are

any of you that are also interested in programming these chips at

home on your own. . . .

>

> here is the link to the company I ordered mine from here

> http://www.ebay.com/itm/200539866123

> the total was 42 plus 7 dollars shipping this includes having the

flying leads connector.

> I expect it to get here some time in the middle of December.

>

> For some reason the DownLoadCable from Xilinx are approx 225 each. from avnet . . .

>

> http://avnetexpress.avnet.com/store/em/EMController/Development-Tools/

Xilinx/HW-USB-II-G/_/R-7532182/A-7532182/An-0?action=part&catalogId

=500201&langId=-1&storeId=500201

>

> Chris has his DLC9G. We will be attempting to find a reliable

way to get one for the cave if the one I ordered works out it might

be cool to order another for the cave. When mine comes in I will

42

Page 43: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

be happy to share it.

> If it is possible to construct a parallel cable based one for

the cave we might move in that direction.

>

> From what I spoke with Chis about yesterday the unit is older

is likely a "pirated" unit for it to be as cheap $41 as it is

compared to the unit for sale linked from Xilinx site on Avnet -

the model Chris has is authentic and out of production what is

offered on the Avnet site is version 2 and is newer in many ways .

http://www.xilinx.com/products/boards-and-kits/HW-USB-II-G.htm

>

> Thanks Tim

41 PCB Artist

This free program was used to construct Wilkson’s printed circuit board. Theboard design was sent to China where one hundred boards were fabricatedfor about ten dollars each.

42 LT Spice

This free electrical circuit simulator is a very good version of Spice. Thispackage can also generate schematic diagrams. In fact the usual way ofusing it is to construct a circuit diagram graphically and then instructingit to be run with specified conditions. This contrasts with other versions ofSpice that run from a net list, which is a text file specifying the circuit. Anet list can be output from LT Spice. Output may be viewed as graphs andrelated to oscilloscopes displays of physical circuit signals.

43 A List of 7400 Series Integrated Circuits

Query Wikipedia for this list. A local version

listof7400integratedcircuits.pdf

is on my computer.

43

Page 44: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

44 A Class Design Project: Controlling Thun-

derbird Tail Lights

The taillights on this car consist of three lights on the left tail light and threelights on the right tail light. When a switch for a left turn is on, the threelights blink so that the inside light 1 is on, then 1 and 2 on, and finally 12 3 are on, then this repeats, so indicating a turn to the left. Same type ofbehavior for a right turn. When a hazard light switch is on, all lights blink1 second on, then 1 second off. When parking, the parking lights are to beat half intensity. From my notes I can’t really reconstruct all of the requiredbehaviors. The lights are to be controlled by the dip switches on the PCBboard, and the push buttons. I think there are brake lights involved too, butdon’t recall the details. The project is to be completed either with hardwarechips, or by using the ISE software to create a program for the Xilinx CPLDchip.

45 Appendix A, RC Circuits, Time Constants,

and the LM555 Timer

The following section occurs in my document called Electrical Circuits,which appears on the STEM2 website as ee.pdf. See that document for thelatest version.

45.1 A Resistor Capacitor Circuit and the Time Con-stant

Discharging a Capacitor. Consider a capacitor C with charge q(0) attime t = 0 connected to resistor R. The voltage drops around the circuit arezero. So

Rdq

dt+

q

C= 0.

ordq

dt+

q

RC= 0,

and sodq

q= − dt

RC

44

Page 45: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

Integrating both sides we have

ln(q) = − t

RC+ k,

where k is a constant of integration. Taking the exponential we have

q(t) = exp(−t/RC) exp(k).

Evaluating at t = 0 we see that

exp(k) = q(0),

Soq(t) = q(0) exp(−t/RC).

andq(t)

q(0)= exp(−t/RC).

tc = RC

is called the time constant. So in one time constant

q(t)

q(0)= exp(−tc/RC) =

1

e= .3679.

So the charge has decayed to about 37 per cent of its initial value. In fivetime constants it will have decayed to

1

e5= .0067

of its initial value. So the capacitor discharges about 100−37 = 63 percent ofits initial charge in one time constant. The energy of the capacitor is storedin the electric field between the capacitor plates. The energy density of thefield can be shown to be

E · D2

,

and so the total energy of the capacitor could be computed by integrating thisexpression over the volume between the capacitor plates. For the definitionsof the electric fields E and D see the document mentioned above called

45

Page 46: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

Electromagnetic Theory. As the capacitor discharges, this field energy isdissipated as heat in the resistor due to the current flow through it.The RC Circuit. Suppose a circuit consists of a voltage source of magnitudeε in series with a capacitor C and a resistor R. The voltage drops aroundthe circuit give us the equation

iR +q

C= ε.

That isdq

dt+

q

RC=

ε

R.

We can convert the left side to a derivative of a function by multiplying bythe integrating factor et/(RC), and then we are able to integrate to solve ourproblem. So we have

dq

dtet/(RC) +

q

RCet/(RC) =

ε

Ret/(RC).

d

dt(qet/(RC))′ =

ε

Ret/(RC).

Integrating, we have

qet/(RC) =ε

R

∫e−t/(RC)dt =

ε

R(RCet/(RC) + K),

where K is a constant. We have at time t = 0

q(0) =ε

R(RC + K),

soK =

ε

Rq(0) − RC.

Thenq(t) = εC + (q(0) − εC)e−t/(RC),

is the general solution of the RC circuit.The capacitor discharges when the source voltage is shorted so that

ε = 0.

Then as above we get

46

Page 47: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

q(t) = q(0)e−t/(RC).

Charging a Capacitor. Consider that the initial charge on the capacitoris q(0) = 0. Then

q(t) = εC(1 − e−t/(RC)).

The final charge reached when t = ∞ is qf = εC. In one time constantRC, the charge on the capacitor is

q(t) = qf(1 − 1/e),

which is aboutqf (1 − .37) = .63qf .

So the time constant is the time it takes to charge the capacitor to about 63percent of its final value.

So in conclusion, the time constant RC is the time it takes for a chargedcapacitor C to dissipate about 63 percent of its charge through a resistor R,and on the other hand the time for an initially uncharged capacitor to reachabout 63 percent of its final charge.Example, The frequency of a 555 timer in astable mode The 555timer in astable mode charges from 1/3 of the supply voltage ε, to 2/3 of thesupply voltage through a resistor R1 for period t1, then discharges through adifferent resistor combination of value R2 from 2/3 of the supply voltage to1/3 of the supply voltage for period t2. The period of the oscillation is then

t = t1 + t2.

Consider the time it takes to charge up from voltage v0 = ε/3 to voltagev1 = 2ε/3. That is from charge

q(0) =εC

3,

to

q(t1) =2εC

3.

That is2εC

3= q(t1) = εC + (q(0) − εC)e−t/(RC)

47

Page 48: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

= εC + (εC

3− εC)e−t1/(RC).

Thus2

3= 1 + (

1

3− 1)e−t1/(RC).

So

−1

3= −2

3e−t1/(RC).

Then

et1/(RC) = 2,

andt1 = RC ln(2).

Now let us compute the time it takes discharge the capacitor from voltagev2 to voltage v1. The discharge equation has a zero source voltage, that isε = 0. Let t2 be the discharge time. We have

q(t2) = q(0)e−t2/(RC),

where

q(t2) =εC

3,

and

q(0) =2εC

3.

So1

3=

2

3e−t2/(RC).

Soet2/(RC) = 2.

So

t2 = RC ln(2).

Now suppose the capacitor charges through resistor R1, and dischargesthrough resister R2. Then the period of oscillation is

T = t1 + t2 = C(R1 + R2) ln(2).

48

Page 49: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

The frequency is

ν =1/ ln(2)

C(R1 + R2).

We have1/ ln(2) = 1.4427.

So

ν =1.4427

C(R1 + R2).

Referring to the National Semiconductor data sheet for the LM555, page7-8, which gives a a circuit for the astable or oscillatory mode of the 555,there is a resistor RA connecting the positive supply voltage at pin 8 to pin7. A second resistor RB connects pin 7 to pin 6. A capacitor C is connectedbetween pin 6 and ground. So the capacitor charges through R1 = RA + RB

and discharges back through R2 = RB. Thus

R1 + R2 = RA + 2RB

So the astable frequency is

ν =1.4427

C(RA + 2RB),

as given in the data sheet.

46 Appendix B, A Xilinx ISE Tutorial

A tutorial featuring a design of a half-adder is at the following link:

http://strumpen.net/xilinx/tut82i/ise.html

Here is a link to a pdf copy:

http://www.stem2.org/je/isetut.pdf

This tutorial is for an earlier version of the ISE software, and for a devicethat is not our Xilinx XC9536XL.Beginning Steps of the Tutorial:

49

Page 50: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

1. Select New Project to get the new project wizard.

2. Fill in the project name box, project location box, and the Top Level Source Type

(schematic). Select next.

3. Now see the device properties window. Perhaps change device family and device.

4. Select next a couple of times, then finish.

5. A new project hierarchy is displayed in the Sources Window portion of the

project window.

6. You can browse through that directory by selecting the Open Project

item in the File menu of the Project Navigator.

7. In the ‘‘Processes’’ window of the Project Navigator, cf. Figure 3, double click

on the entry entitled Create New Source. (Alternatively, pull down the Project

menu and click on New Source.) Select source type Schematic and enter in File

name ‘‘halfadder’’, as shown in Figure 4 below.

8. Click Next and Finish. The Project Navigator window now shows the

‘‘Design Summary’’ of the Schematic Editor, see Figure 5. To switch

to the drawing area of the Schematic Editor click on the halfadder.sch tab

at the bottom of the ‘‘Workspace’’ window. Later in the design process,

clicking on that file name in the Project Manager will automatically

start up the Schematic Editor.

47 Appendix C, Introduction to the Verilog

Hardware Design Language

Verilog is a hardware description Language. Its syntax is like that of aprogramming language. The Xilinx ISE program can use Verilog to create adigital logic design.

Hello World Program

1 //-----------------------------------------------------

2 // This is my first Verilog Program

3 // Design Name : hello_world

4 // File Name : hello_world.v

5 // Function : This program will print ’hello world’

6 // Coder : Deepak

7 //-----------------------------------------------------

8 module hello_world ;

9

50

Page 51: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

10 initial begin

11 $display ("Hello World by Deepak");

12 #10 $finish;

13 end

14

15 endmodule // End of Module hello_world

48 Appendix D, Running Icarus Verilog From

The Command Line in Windows

The following file is a Verilog program by the author of Icarus Verilog,which on windows is available as a command line program. The commentsat the beginning of the file show how to run the program in Unix or Linux.The example is a hardware square root program. To run the windows version,the two programs iverilog.exe and vvp.exe must be in the current path.If not, run them from the iverilog bin directory.

For windows:

iverilog -osqrt sqrt.vl

vvp sqrt

File listing:

/*

* Copyright (c) 1999 Stephen Williams ([email protected])

*

* This source code is free software; you can redistribute it

* and/or modify it in source code form under the terms of the GNU

* General Public License as published by the Free Software

* Foundation; either version 2 of the License, or (at your option)

* any later version.

*

* This program is distributed in the hope that it will be useful,

* but WITHOUT ANY WARRANTY; without even the implied warranty of

* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the

* GNU General Public License for more details.

*

* You should have received a copy of the GNU General Public License

* along with this program; if not, write to the Free Software

* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

*

51

Page 52: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

* $Id: sqrt.vl,v 1.4 2004/10/04 01:10:56 steve Exp $"

*/

/*

* This example shows that Icarus Verilog can run non-trivial

* programs, too. This uses a variety of Verilog language features

* to implement the module of a square-root device. The program

* uses IEEE1364-1995 language features and should work correctly

* on any Verilog compiler.

*

* Run the file with Icarus Verilog under UNIX using the command:

*

* % iverilog -osqrt sqrt.v

* % ./sqrt

*/

/*

* This module approximates the square root of an unsigned 32bit

* number. The algorithm works by doing a bit-wise binary search.

* Starting from the most significant bit, the accumulated value

* tries to put a 1 in the bit position. If that makes the square

* to big for the input, the bit is left zero, otherwise it is set

* in the result. This continues for each bit, decreasing in

* significance, until all the bits are calculated or all the

* remaining bits are zero.

*

* Since the result is an integer, this function really calculates

* value of the expression:

*

* x = floor(sqrt(y))

*

* where sqrt(y) is the exact square root of y and floor(N) is the

* largest integer <= N.

*

* For 32bit numbers, this will never run more then 16 iterations,

* which amounts to 16 clocks.

*/

module sqrt32(clk, rdy, reset, x, .y(acc));

input clk;

output rdy;

input reset;

input [31:0] x;

output [15:0] acc;

// acc holds the accumulated result, and acc2 is the accumulated

// square of the accumulated result.

reg [15:0] acc;

reg [31:0] acc2;

// Keep track of which bit I’m working on.

reg [4:0] bitl;

wire [15:0] bit = 1 << bitl;

wire [31:0] bit2 = 1 << (bitl << 1);

52

Page 53: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

// The output is ready when the bitl counter underflows.

wire rdy = bitl[4];

// guess holds the potential next values for acc, and guess2 holds

// the square of that guess. The guess2 calculation is a little bit

// subtle. The idea is that:

//

// guess2 = (acc + bit) * (acc + bit)

// = (acc * acc) + 2*acc*bit + bit*bit

// = acc2 + 2*acc*bit + bit2

// = acc2 + 2 * (acc<<bitl) + bit

//

// This works out using shifts because bit and bit2 are known to

// have only a single bit in them.

wire [15:0] guess = acc | bit;

wire [31:0] guess2 = acc2 + bit2 + ((acc << bitl) << 1);

task clear;

begin

acc = 0;

acc2 = 0;

bitl = 15;

end

endtask

initial clear;

always @(reset or posedge clk)

if (reset)

clear;

else begin

if (guess2 <= x) begin

acc <= guess;

acc2 <= guess2;

end

bitl <= bitl - 1;

end

endmodule

module main;

reg clk, reset;

reg [31:0] value;

wire [15:0] result;

wire rdy;

sqrt32 root(.clk(clk), .rdy(rdy), .reset(reset), .x(value), .y(result));

always #5 clk = ~clk;

always @(posedge rdy) begin

$display("sqrt(%d) --> %d", value, result);

$finish;

end

53

Page 54: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

initial begin

clk = 0;

reset = 1;

$monitor($time,,"%m.acc = %b", root.acc);

#100 value = 63;

reset = 0;

end

endmodule /* main */

48.1 MUX2 Program Listing

This is a verilog program for a two-input Multiplexor. When select is 0 itoutputs in0, and when select is 1 it outputs in1.

module testmux;

reg a, b, s;

wire f;

reg expected;

mux2 myMux (.select(s), .in0(a), .in1(b), .out(f));

initial

begin

#0 s=0; a=0; b=1; expected=0;

#10 a=1; b=0; expected=1;

#10 s=1; a=0; b=1; expected=1;

#10 $stop;

end

initial

$monitor(

"select=%b in0=%b in1=%b out=%b, expected out=%b time=%d",

s, a, b, f, expected, $time);

endmodule // testmux

//

module mux2 (in0, in1, select, out);

input in0,in1,select;

output out;

wire s0,w0,w1;

not

(s0, select);

and

(w0, s0, in0),

(w1, select, in1);

or

(out, w0, w1);

endmodule // mux2

48.2 Running the Programs

Run the programs iverilog.exe and vvp.exe on the input file testmux2.v:

iverilog -otestmux2 testmux2.v

54

Page 55: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

vvp testmux2

Prints the output:

select=0 in0=0 in1=1 out=0, expected out=0 time= 0

select=0 in0=1 in1=0 out=1, expected out=1 time= 10

select=1 in0=0 in1=1 out=1, expected out=1 time= 20

** VVP Stop(0) **

** Flushing output streams.

** Current simulation time is 30 ticks.

> finish

49 Bibliography

[1] Boole George The Laws of Thought, 1854.

[2] Mendelson Elliot Boolean Algebra and Switching Circuits, Schaum’sOutline Series, McGraw-Hill, 1970.

[3] Nagle H. Troy, Carroll B. D., Irwin J. David An Introduction to Com-puter Logic, Prentice-Hall 1975. (Presents a computer algorithm for com-puting the minimal sequential machine. I worked on a program implementingthis algorithm, based on someone’s PhD theses, in the 70’s.)

[4] Mano M. Morris, Digital Logic and Computer Design Prentice-Hall1979.

[5]Flores Ivan, Computer Logic, 1979, Prentice-Hall.

[6]McWhorter Gene, Understanding Digital Electronics, 1978, Texas In-struments learning Center, Radio Shack.

[7] Roth Charles H. Jr. Fundamentals of Logic Design, 4th Edition,1992, West Publishing, (Karnaugh Maps, Quine-McClusky Method, Sequen-tial Networks, Reduction of State Tables and State Assignment, Design ofBinary Adders, Hazards.)

55

Page 56: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

[8] Texas Instruments. The TTL Data Book for Design Engineers,Second Edition, 1982, Texas Instruments Corporation.

[9] Wakerly John F, Digital Design: Principles and Practices, SecondEdition, 1994, Prentice-Hall.

[10] Platt Charles, Make: Electronics, O’Reilly, 2009.

[11] Mims Forrest, Engineer’s Notebook II: Integrated Circuit Appli-cations, Radio Shack, 1982, (a collection of circuit examples for 7400 seriesintegrated circuits, see for example the circuit for the 74LS74 Dual D Flip-Flop on page 53, the divide-by-two counter).

[12] Cavanagh Joseph, Computer Arithmetic and Verilog HDL Fun-damentals, CRC Press, 2010. Copy at Linda Hall Library TK7868.D5 C38.Chapter 1, Number Systems and Number Representations. Chapter 2, LogicDesign Fundamentals. Chapter 3, Introduction to Verilog HDL.

[13] Lala Parag K Principles of Modern Digital Design, Wiley-Interscience,2007. Contains material about the Hardware Description Language calledVHDL. There is a copy of this book at Linda Hall Library TK7868.L6L36.

[14] Dailey Denton J, Programming Logic Fundamentals Using XilinxISE and CPLDs, Pretince Hall, 2004, 203 pages. Introduction to PLDsusing Xilinx ISE.

[15] Pedroni Volnei A. Circuit Design with VHDL, 2004, MIT Press. Ap-pendix B is instruction on the use of VHDL in Xilinx ISE.

[16] Chu Pong P. , FPGA Prototyping by Verilog Examples: XilinxSpartan-3 Version, Wiley-Interscience, 2008. Instruction on FPGA designusing a Xilinx ISE and Spartan-3 chip.

[17] Wikipedia , Flip-Flops, The article on Flip-Flops is quite good as ofNovember 2011. Take note of the fact that Wikipedia articles constantlychange. For this reason, when I find a good article I like to print a PDF copyof it and store it.

56

Page 57: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

[18] J. Wawrzynek, CS61c: Verilog Tutorial October 17, 2007, verilog-berkeley.pdf, http://inst.eecs.berkeley.edu/ cs61c/resources/verilog.pdf

[19] Stephen Williams, Icarus Verilog A free verilog program available forseveral systems including Linux, and a version for Windows (command lineonly). GNU General Public License version 2.0

[20] Deepak Kumer Tala, Verilog Tutorial verilog tutorial.pdf.

http://www.ece.umd.edu/courses/

enee359a/verilog\_tutorial.pdf

[21] Palnitkar, Samir, Verilog HDL : a guide to digital design andsynthesis SunSoft Press, 1996. Linda Hall TK7885.7 .P34 1996, SILOS IIIsimulation environment for windows CDROM 234.

[22] Sternheim Eliezer, Singh Rajvir, Ttivedi Yatin Digital Design withVerilog HDL Automata Publishing Company, Cupertino CA, 1990. LindaHall Library TK7885.7 S73.

[23] Thomas Donald E., Moorby Philip R., The Verilog Hardware De-scription Language, 2nd Edition, Kluwer Academic Publishers, 1995. LindaHall Library TK7885.7 .T48, Disk 331.

[24] C.-L. Chang and C.-T. Lee. Symbolic Logic and Mechanical The-orem Proving, chapter 2. Academic Press, 1973.

50 Glossary

ASIC Application-Specific Integrated Circuit.

SSI Small Scale Integration

MSI Medium Scale Integration

LSI Large Scale Integration

57

Page 58: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

IC Integrated Circuit

Preset, Set, Reset the placing of a logic chip in a certain state.

FF Flip-Flop, an integrated circuit that may be in two different logic statescontrolled by inputs and by a next state function.

S-R Flip-Flop and Latch A Set Reset Flip-Flop

D Flip-Flop Delay Flip-Flop.

T Flip-Flop Toggle Flip-Flop.

JK Flip-Flop Controlled by two input values.

PB Push Button

PCB Printed Circuit Board

TTL Transistor Transistor Logic

CMOS Complementary Metal Oxide Semiconductor

ENP Enables the clock on a clocked chip when high.

ENT Enables the clock on a clocked chip when high, and allows ripple carry.

HDL Hardware Description Language.

Verilog is a Hardware Description Language used to model digital systems.

VHDL another Hardware Description Language. The syntax is similar tothe ADA programming language.

FPGA Field Programmable Gate Array

CPLD Complex Programmable Logic Device

58

Page 59: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

MUX Short for multiplexer. From a select signal, selects from a number ofinputs and sends the selected input to a single output.

DMUX Short for demultiplexer. The inverse of a MUX. From a select sig-nal, it selects one from n output ports, and sends the single input signal tothe selected port.

RDL Register Transfer Level, the transfer of logical values to registers in ahardware description language

Fan Out

Tautology

Logical Equivalence

The Axiom of Choice

Zorn’s Lemma

The Chain Condition

Zermelo-Frankel Axioms of set theory

Logical Implication

First Order Logic

Existential Quantifier

Syllogism

Aristotle

ROM Read Only Memory

RAM Random Access Memory

59

Page 60: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

DRAM Dynamic Random Access Memory

EPROM

UVL Ultraviolet Light

Cardinal Numbers

Ordinal Numbers

Operators

Operands

Postfix

Prefix

Transfinite Numbers

NPN

PNP

FET

Smitt-Trigger Shows hysteresis.

Electrolytic Capacitor

Tantalum Capacitor

Ceramic Capacitor

Registers

Hysteresis

60

Page 61: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

Boltzman’s Constant

The Electronic Charge of the electron

Coulomb

Ampere

Volt Unit of electrical potential

Coulomb’s Law

Maxwell’s Equations

Faraday’s Law of Induction

Magnetic Poles

Permeability

Permittivity

Henry Unit of inductance

Joule

kilo

mega

milli

micro

nano

pico

61

Page 62: Logic, Boolean Algebra, and Digital Circuits - Stem2stem2.org/je/logic.pdf · Logic, Boolean Algebra, and Digital Circuits Jim Emery Edition 4/29/2012 Contents 1 Introduction 4 2

diode

diode equation

Is Saturation Current

Zener Diode

51 Constants

Charge of the Electron

62