CPPC 12 Lecture Notes 1 Introduction To HDL Part 2 PDF
CPPC 12 Lecture Notes 1 Introduction To HDL Part 2 PDF
Part 2
Instructions: This lecture notes is a review of your programming logic & design, discrete
mathematics and logic circuits & design necessary in the succeeding topics. It has many
examples, exercises and tasks to be answer. Submit this lecture notes again when you finished
answering the examples. Extract the exercises and tasks separately, copy it to new document,
answer all the questions and save it with a filename of Lastname_Lecture_Note_1_Exercise1
(for exercise 1), Lastname_Lecture_Note_1_Exercise2 (for exercise 2) and
Lastname_Lecture_Note_1_Tasks.
Digital logic design is a system in electrical and computer engineering that uses simple number
values to produce input and output operations. As a digital design engineer, you may assist in
developing cell phones, computers, and related personal electronic devices.
Industry Defined
Digital logic design is the basis of electronic systems, such as computers and cell phones.
Digital logic is rooted in binary code, which renders information through zeroes and ones, giving
each number in the binary code an opposite value. This system facilitates the design of
electronic circuits that convey information, including logic gates with functions that include AND,
OR, and NOT commands. The value system translates input signals into specific outputs. These
functions facilitate computing, robotics, and other electronic applications.
Logic
Logic is the systematic study of valid rules of inference, i.e. the relations that lead to the
acceptance of one proposition (the conclusion) on the basis of a set of other propositions
(premises).
Are there "rules" or "laws" that govern proper reasoning? Can we prove, mathematically, that a
particular argument is valid? To what extent can reasoning be automated?
CPPC 12 Introduction to HDL Lecture Note 1
1. Statement (proposition): a sentence that is either true or false, but not both.
a. 5 + 3 = 7
b. 21 / 7 = 3
c. Kennedy is President of the United States
d. He is a software engineer
e. Baltimore is the capital of Maryland.
f. 3 * z < 9
g. Every even integer greater than 2 is the sum of two primes
h. This sentence is false.
3. Logical Connectives:
Not (negation)
1. Mathematical symbol: ~
2. ~p means "it is not the case that p" where p is some statement.
3. Other notations: p , p
4. C++ notation:
5. The negation of a statement has the opposite truth-value from the statement.
If p is true, ~p is false.
6. The definition of negation is displayed in a truth table
p ~p
F T
T F
And (conjunction)
1. Mathematical symbol:
2. p q means “it is the case that p and q are true.”
3. C++ notation:
4. The conjunction of two statements p and q is true when and only when both p
and q are both true.
5. The definition of conjunction is displayed in a truth table
CPPC 12 Introduction to HDL Lecture Note 1
p q pq
F F
F T
T F
T T
6. Example
p: MIDN Berrios is an officer
q: MIDN Berrios is a gentleman
pq:
Or (disjunction)
1. Mathematical Symbol:
2. Also called "inclusive or"
3. C++ notation:
4. The disjunction of two statements p q is true if either p or q is true, or if
both p and q are true.
5. The definition of disjunction is displayed in a truth table
p q pq
6. Example
p: it is rainy
q: it is cold
p q:
Exclusive or
1. Mathematical Symbol: , XOR
2. p q is true if either p is true or q is true, but not both.
3. The definition of exclusive or is displayed in a truth table
p q pq
CPPC 12 Introduction to HDL Lecture Note 1
Example: ~ p q is performed as
Example
Let p = “It is chilly” and q = “It is overcast” . Translate each of the following
compound statements into a mathematical statement using symbolic logic.
Example
x 2
0<x<2
0<x 3
We know the truth table for p q and s r. But what is the truth table for a
compound statement, such as ~(p q) (s r)?
To develop the truth table for a complex statement we must consider each
combination of truth values for the component statements.
p q
Now, use the definition of ~ to write a column for ~p. Then, write a column for
~ p q using the definition of disjunction.
p q ~p ~ pq
p q
Logical Equivalence
Two (compound) expressions are logically equivalent if and only if they have
identical truth values for all possible combinations of truth values for the sub-
expressions. If A and B are logically equivalent, we write A B . (Another
notation for logical equivalence is ; that is, if A and B are logically equivalent
then A B .)
To test if A and B and logically equivalent, construct truth tables for A and B. If
the truth values of A and B match for all rows in the truth table, then A B .
p ~p ~ (~ p)
F T F
T F T
p q pq ~ p q ~p ~q ~pq
F F F T T T T
F T F T T F F
T F F T F T F
T T T F F F F
DeMorgan’s Laws
For this to be true, it must be the case that it is true that Walter is 20 years old
and it is true that Walter is in the Navy.
Now think of the negation of this compound statement. For this to be false, one
or both of the parts of the compound statement must be false.
B. DeMorgan‟s Laws ~( p q) ~p ~q
~( q) ~p ~q
Example: Consider p ~ p
p ~p p ~ p
F T T
T F T
Example: Consider p ~ p
p ~p p ~ p
F T F
T F F
CPPC 12 Introduction to HDL Lecture Note 1
hypothesis conclusion
Answer:
p q pq
F F
F T
T F
T T
In addition to expressing pq as “if p then q,” the following English expressions
are also used (note that these expressions parallel the normal English meaning
of “if p then q”):
if p, q p implies q q if p q whenever p
CPPC 12 Introduction to HDL Lecture Note 1
Think about this sentence. It says if q does not occur, then p does not occur. This
means that p can only occur if q occurs. Or, to put it more succinctly:
if p then q
if p, q
q if p
q whenever p
p implies q
p q
if not q then not p
~ q ~ p
p only if q
Example
Exercises
Question 1. Consider the sentence: Edgar will get an A only if he hands in all his homework.
Question 2. Consider the sentence: If Allan is a software engineer at the PMAP, then he is not
married.
The fact that Joshua lives in Steve Hall is a sufficient condition for me to conclude that
he is a software engineer.
Question 5. What is the truth value of this statement: If 2 + 2 = 5 then Mario is a deity.
Question 6. What is the negation of the following statement: If Jonathan is a senior then she is
cynical.
Question 7. Suppose p and q are statements and p → q is known to be false. What is the value
of p q?
Contrapositive:
Converse:
Inverse:
The biconditional
Given two statements p and q, the biconditional p ↔ q, read “p if and only if q,” is the
statement that is true if p and q have the same truth values and is false if p and q have
opposite truth values.
p q p↔q
Example: Express the statement “I am happy if and only if I have found true
love” as the conjunction of two if-then statements.
Notation. From now on, we will very often abbreviate “if and only if” as iff.
CPPC 12 Introduction to HDL Lecture Note 1
Logic Gates Consider the circuit below which has 2 switches in series:
S1 S2
L Light
S1 S2 Light
open open off
open shut off
shut open off
shut shut on
Change the words open and off to F and the words shut and on to T and the table becomes
S2 L Light
Changing the words open and off to F and the words shut and on to T and the table becomes
S1 S2 Light
F F F
F T T This is the truth table for the logical connective.
T F T We can say that the circuit above corresponds to S1 S2.
T T T
Notes:
Usually, when designing circuits, the symbol 0 is used to denote F and the symbol 1
is used to denote T.
A compound expression as we are using it here (in the context of logic circuits) is
called a Boolean expression. We will develop a more formal definition of a Boolean
expression later in the course.
In a digital logic circuit, only two values may be present. The values may be 5 and + 5
volts. Or the values may be 0.5 and 3.5 volts. To allow consideration of all of these
possibilities, we will say that digital logic circuits allow the presence of two logical values: 0
and 1.
So, signals in a digital logic circuit take on the values of 0 or 1. Logic gates are devices
which compute functions of these binary signals.
In this lecture we will consider three logic gates that are used to construct digital logic
circuits:
A. Not gate (inverter) - Has one input and one output. If the input, P, is 1, the output is 0.
If the input is 0, the output is 1.
P ~P
0 1 Corresponds to the ~ connective
1 0
CPPC 12 Introduction to HDL Lecture Note 1
B. And gate – has two inputs and one output. If both inputs, say P and Q, are both 1 then
the output is 1. Otherwise, the output is 0.
AND gate
P Q PQ
0 0 0
0 1 0 Corresponds to the connective
1 0 0
1 1 1
C) Or gate – has two inputs and one output. If either or both inputs, say P and Q, are 1,
the output is 1. Otherwise, the output is 0.
OR gate
P Q PQ
0 0 0
0 1 1 Corresponds to the connective.
1 0 1
1 1 1
Combinational circuits
A combinational circuit is a digital logic circuit whose output is determined only by the current
values of the inputs (with no dependence on past input values). A combinational circuit is built
up by combining our three basic logic gates with the following provisos:
The output of a gate may not eventually feed back to that same gate.
Example. The air conditioning plant on a ship is controlled by a logic circuit. The air
conditioner will turn on (logical “1”) if the temperature is above 80F (logical “1”). If the
motor is overheating (logical “1”), however, a signal is sent to turn the air conditioner off.
Sketch (within the box) the logic circuit to accomplish this design.
Answer:
Our study of combinational circuits will involve five (very much related) tasks:
(Task 1) Given a digital logic circuit, write the corresponding Boolean expression.
(Task 2) Given a Boolean expression, draw a digital logic circuit that represents this
expression.
(Task 3) Given a digital logic circuit, construct the corresponding truth table.
(Task 4) Given a truth table, construct a digital logic circuit that implements this truth
table.
(Task 5) Given a digital logic circuit, design a simpler digital logic circuit that performs
the equivalent function.
CPPC 12 Introduction to HDL Lecture Note 1
TASK 1: Given a digital logic circuit, write the corresponding Boolean expression.
Example: Determine the Boolean expression corresponding to the digital logic circuit
shown.
Example. Write the Boolean expression for the logic circuit shown below.
p
q
Evaluating the effect of the logic gates on the input expressions, we see:
CPPC 12 Introduction to HDL Lecture Note 1
TASK 2: Given an expression, draw a digital logic circuit that represents this
expression.
The basic approach is to write the expression on the right side of the page. Draw the circuit
from right to left, by working from the outermost part of the expression.
Example: Construct a digital logic circuit that will implement the Boolean expression
(p ~ q) ~ p
~p
q ~q
p ~ q
p p ~ q ~ p
~p
Finally,
q ~q
p ~ q
p
p ~ q ~ p
~p
CPPC 12 Introduction to HDL Lecture Note 1
Example: Draw a digital logic circuit that represents the Boolean expression
x (y ~ (x ~ z))
TASK 3: Given a digital logic circuit, construct the corresponding truth table.
There are many convenient ways to do this. We can determine the corresponding Boolean
expression (TASK 1). Or, alternatively, we can trace through the circuit for each possible
combination of input values.
Substitute p = 0 and q = 0 and r = 0 and trace through the circuit gate by gate. Repeat
this for the other combinations of input values. The resulting truth table is
p q output
Example. Construct the truth table for the circuit shown below.
p
q
p q output
Example. Write the Boolean expression for the logic circuit shown below, and then
construct the truth table for it.
p
q
Evaluating the effect of the logic gates on the input expressions, we see that the output
is:
Aside an aside (and not related to the example above), note that for AND gates and OR
gates, we will allow more than two inputs. For a multi-input AND gate, the output is one
if ALL of the inputs are 1. For a multi-input OR gate, the output is 1 is ANY one of the
inputs is a 1 (or if more than one input is a 1). The example below shows what we
mean.
TASK 4: Given a truth table, construct a digital logic circuit that implements this truth
table.
z1 z2 ... z n
c. After step b., we will have one Boolean expression corresponding to each row that
had an output of 1. Take the disjunction of all these Boolean expressions. The
resulting expression has the truth table under evaluation. (As an aside, an
expression such as this, which is a disjunction of several terms, where each of these
terms is a conjunction of irreducible expressions, is said to be disjunctive normal
form.)
d. Form the digital logic circuit from this Boolean expression using the technique
discussed in TASK 2 above.
p q output
0 0 0
0 1 1
1 0 0
1 1 1
Solution:
p q output
0 0 0
0 1 1
1 0 0
1 1 1
CPPC 12 Introduction to HDL Lecture Note 1
A B C Output
TASK 5: Given a digital logic circuit, design a simpler digital logic circuit that
performs the equivalent function.
a. Find the Boolean expression that corresponds to this logic circuit (TASK 1 above).
b. Use the Table on page 14 of the text to find a simpler logically equivalent Boolean
expression.
c. Given this simpler Boolean expression, draw the digital logic circuit that represents
this expression (TASK 2 above). This simpler circuit will perform precisely the same
way as the original (more complex) circuit.
Example. Suppose we find that a logic circuit has the Boolean expression
~ x ~ y ~ z ~ x ~ y z
Can this circuit be simplified?
~ x ~ y ~ z ~ x ~ y z
Exercises 2
Question 1 You have been tasked with designing the sprinkler system for the Commanding
Officer‟s stateroom. The CO‟s stateroom has three smoke alarms. Since the CO will be
very angry if his stateroom is drenched by a false or spurious alarm, you decide that the
sprinkler system will not be activated by any single smoke alarm. The sprinkler system will
activate if any two of the smoke alarms activate (or if all three activate).
a. Write a truth table that describes how the sprinkler operation will depend on the
status of the three smoke alarms. (Clearly state what you intend by logical 1 and
logical 0.)
b. Based on your truth table, design the digital logical circuit.
CPPC 12 Introduction to HDL Lecture Note 1
Question 2 Let‟s pretend that there are four midshipman who are very good friends
(remember, this is just pretending). Their names are:
MIDN Miller
MIDN Porter
MIDN Lees
MIDN Wolz
Although they are all good friends, MIDN Lees and MIDN Wolz are youngsters, so they
“kinda-sorta” get, shall we say, “outvoted” when it comes to some decision-making.
Our four midshipmen always eat dinner together. In fact, they always eat dinner
together in one of two locations: King Hall or California Pizza Kitchen (CPK). Each day,
at 1645, they take a vote to decide where all four will eat. The voting works as follows:
Design a digital logic circuit that will allow our four midshipmen to cast their votes
electronically. Based on the votes, the logic circuit will decide (based on the rules
above) where our midshipmen will be eating dinner that day. (To make our task of
grading easier, please use the following convention: Let 1 denote a vote for CPK and 0
denote a vote for King Hall.)
Number Representations
The decimal number system has 10 digits (0,1,2,3…9). Since it is based on 10 distinct
symbols, we say the base is 10. In decimal notation, we write a number as a string of digits.
To interpret a decimal number, we multiply each digit by the power of 10 associated with
that digit‟s position.
The binary number system has two digits (0 and 1). The base is two. Just as with decimal
notation, we write a number as a string of digits, but now each digit is 0 or 1. To interpret a
binary number, we multiply each digit by the power of 2 associated with that digit‟s position.
To convert a binary number to a decimal number, write the binary number as a sum of
powers of 2.
Note: We must be careful that the base is understood. When we say “11” above, we
mean the number 11 in base 10, not the number 11 in base 2. If the base is not clear
from context, it can be made explicit by including the base as a subscript as in:
10112 1110
ii. Now subtract this power of two from the original decimal number.
iii. If this new decimal number is zero, we‟re done. Otherwise return to
step i. above.
Think to yourself: Self, what is the largest power of 2 that is less than or equal to
78.
Answer:
Now, subtracting 2 from our number 2 gives 0, so we are done. Filling in the
zeros, we have our answer: The decimal number 78 in binary is
At the risk of insulting your intelligence, we ask that you “memorize” the binary
representations of the decimal digits 1 through 16.
Using the algorithm, your answer should match the representation shown on the
prior page.
CPPC 12 Introduction to HDL Lecture Note 1
Binary Arithmetic
We see that when we add two binary ones together, we have a carry into the next
column. This idea of “carrying over to the next column” when adding binary numbers
together is analogous to carrying over when adding decimal numbers: if the result of
the addition is a number too big to be represented as a single digit in the number
system, we carry a one over to the next column.
We see that when we add three binary ones together, we have a carry into the next
column.
101101 1111
+ 1011 + 101
------------- --------
4. Example: Express the decimal integer –13 as an eight bit binary number.
5. Example: Express the decimal integer 53 as an eight bit binary number.
A binary number, added to its two‟s complement, results in zero. This is “how its
„sposed to be: a number added to its negative should give zero.
Positive integers are stored in four bytes by converting the integer to a binary number.
The right most 31 bits are used. The left most bit is set to zero (indicating a positive
number).
Negative integers are stored in four bytes by converting the integer to a binary number in
two‟s complement notation. The right most 31 bits are used. The left most bit will be a
one.
CPPC 12 Introduction to HDL Lecture Note 1
Can you explain the output of the C++ program shown below?
#include<iostream>
using namespace std;
int main( )
{
int number = 2147483646;
cout << number << endl;
number = number + 1;
cout << number << endl;
number = number + 1;
cout << number << endl;
number = number + 1;
cout << number << endl;
number = number + 1;
cout << number << endl;
return 0;
}
Question: Design a digital logic circuit that will add two single bit binary numbers.
Design a digital logic circuit to add three bits together. Call the three inputs A, B and C.
Using the techniques you learned earlier, you can show that the Boolean expression for
the Carry bit, after some simplification, is
You should convince yourself that the Carry bit can be implemented by two XORs.
A
B
Carry
C
This circuit (i.e., these two circuits together) is called a full adder.
Sum
Example. Consider representing the half-adder and the full-adder as shown below:
Carry Sum
A B A B
Half adder C
Full adder
Half adder
Carry Sum