Академический Документы
Профессиональный Документы
Культура Документы
7 Implementation of a 2 to 4 Decoder 19
Lab Tasks
1) Verify the truth tables of all the ICs specified:
Input Output
A B Y=A.B
0 0 0
0 1 0
1 0 0
1 1 1
74LS32 ( OR Gate ):
Y=A+B
Input Output
A B Y=A+B
0 0 0
0 1 1
1 0 1
1 1 1
74LS04 ( NOT Gate ):
Y=
Equipment /Tool:
Trainer, 74LS32 (OR), 74LS08 (AND), 74LS04 (NOT).
X Y
. F
Now find the minterms of this expression and write it on the following blank
F= .
Now verify the results of both the tables. Are they both the same or not? And why?
Objectives:
Using two input NAND and NOR gates, construct the following
1. NOT
2. AND
3. OR
After doing this, implement the given expression on the trainer board.
Equipment /Tool:
Trainer, IC 74LS00, 74LS02.
Theory:
NAND and NOR gates are called universal gates because we can make any basic gate from
them by using the following circuits.
1) Implementation of Gates using NAND Gate only:
i) NOT Gate Behavior:
Input output
0 1
1 0
Input Output
X Y F
0 0 0
0 1 1
1 0 1
1 1 1
A A
0 1
1 0
A B Q
0 0 0
0 1 0
1 0 0
1 1 1
A B F
0 0 0
0 0 1
1 0 1
1 1 1
Exercise in Lab:
1) Implement following expression using NOR Gate only.
2) Implement following expression using NAND Gate only.
F= + .
Truth Table:
Input Output
X Y Z F
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
X Y F
0 0 0
0 0 1
1 0 1
1 1 0
Now from the table find the minterms and write the corresponding expression in the following
blank
P= .
From the expression make the corresponding circuit and implement it on the trainer board:
Now make the following circuit on the trainer and verify the following truth table:
Now implement the following circuit of even parity generator and fill the truth table:
X Y Z P C
0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
0 1 0 1
0 1 1 0
0 1 1 1
1 0 0 0
1 0 0 1
1 0 1 0
1 0 1 1
1 1 0 0
1 1 0 1
1 1 1 0
1 1 1 1
Tasks:
Write a truth table for a half adder, design a simplified circuit for it. Implement it on
trainer and verify the results.
Write a truth table for a full adder, design a simplified circuit for it. Implement it on
trainer and verify the results.
Fill in the truth table.
Design the complete circuit on the trainer and verify the results.
Procedure
Task 1 & 2
Fill in the following truth table of half adder and full adder and draw the circuit from them.
This is a 4-bit adder/subtractor circuit. FA is full adder. The operation depends upon Cin. If
Cin=0, addition is performed and if Cin=1, subtraction is performed.
Exercise in Lab:
Fill in the following truth table and verify your results and show it to the instructor:-
1)
A3 A2 A1 A0
B3 B2 B1 B0
S3 S2 S1 S0
2)
A3 A2 A1 A0
B3 B2 B1 B0
S3 S2 S1 S0
S B A Y
0 X 0 0
0 X 1 1
1 0 X 0
1 1 X 1
Circuit Diagrams:
Draw the diagram of 4 to 1 MUX as follows:
B A C C1 C2 C3 G Y
0
X X X X X X H L
L L L X X X L L
L L H X X X L H
L H X L X X L L
L H X H X X L H
H L X X L X L L
H L X X H X L H
H H X X X L L L
H H X X X H L H
INPUTS OUTPUTS
A B C Y
X X L L
X L X L
L X X L
H H H H
CIRCUIT DIAGRAM:
Draw a 2 to 4 decoder with active low pin:
0 1 0 1
0 0 Latch(Previous) Latch(Previous)
1 1 Undefined Undefined
1 0 0 1
1 1 Latch(Previous) Latch(Previous)
0 0 Undefined Undefined
C S R Q QBAR
0 X X Latch Latch
1 0 0 Latch Latch
1 0 1 0 1
1 1 0 1 0
1 1 1 unstable Unstable
Circuit Diagram:
Draw the circuit diagram for SR latch with a control bit with only NAND gates.
Equipment Used:
Trainer, NAND gates (74LS00), NOT Gate (74LS04), 7474 (D-Flipflop)
Background Theory:
In order to eliminate the undesired state in the SR Latch is to ensure that inputs S & R are never
equal to 1 at the same time. This is done in the D Latch. This latch has only two inputs: D
(Data) & C (Control), the D Latch receives its designation from its ability to hold data in its
internal storage.
Exercise in Lab:
Truth Table for D latch:
E or C D Q Q
0 X Latch
1 0 1 0
1 1 1 1
Circuit Diagram:
Draw the circuit for D Latch.
Procedure:
Following is the state machine that must be implemented.
Excitation Table:
Fill in the following excitation table according to the truth table for JK Flipflops
Q(t) Q(t+1) J K
0 0
0 1
1 0
1 1
Transition Table:
Fill in the following transition table
P.State Input=x N.State JB KB JA KA Output
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
K-Maps:
Fill in the following K-Maps for the following outputs
JB:
00 01 11 10
X 0
X 1
KB:
00 01 11 10
X 0
X 1
KA:
00 01 11 10
X 0
X 1
OUTPUT:
00 01 11 10
X 0
X 1
Equations:
Write the equations derived from the K-Maps. Fill in the following Blanks.
JB: .
KB: .
JA: .
KA: .
Output: .
Circuit Diagram:
Draw the resulting circuit diagram from the equation give above:
Keywords
The keywords define the language constructs. All keywords in Verilog are in small letters and
require to be used as such. Some of the examples are:
module - signifies the beginning of a module definition.
endmodule - signifies the end of module definition.
begin - signifies the beginning of block of statements.
end - signifies the end of a block of statements.
if - signifies a conditional activity to be checked.
assign - assigns a value or an expression to a net or variable.
Numbers
The numbers can be of integer type or real type. Integer Numbers Number storage is defined
as a number of bits, but values can be specified in binary, octal, decimal or hexadecimal. The
representation has three tokens with an optional sign preceding it. Numbers may be sized or
unsized. Unsized integers default to at least 32 bits.
Syntax: size base value
Examples:
Logical Values:-
Verilog uses a 4 value logic system for modelling.
Operators
They are of three types.
Unary: the unary operator is associated with a single operand. E.g. b = ~a
Binary: the binary operator is associated with two operands. E.g. c = a & b
Ternary: the ternary operator is associated with three operands. E.g. a = b? c : d
Operator Precedence
The operator precedence is shown below. The top of the table is the highest precedence, and
the bottom is the lowest. Operators listed on the same line have the same precedence. All
operators associate left to right in an expression. Ternary operator is exception to this; it
Data Types
Verilog has two major data type classes:
1) Net Data type
2) Variable data type.
Nets
Net data types are used to make connections between parts of a design. Nets reflect the value
and strength level of the drivers of the net or the capacitance of the net, and do not have a value
of their own. A net can be specified in different ways.
Wire
A wire (or net) represents a physical wire in a circuit and is used to connect gates or modules.
The value of a wire can be read, but not assigned to, in a function or block. A wire does not
store its value but must be driven by a continuous assignment statement or by connecting it to
the output of a gate or module.
Syntax wire [msb: lsb] wire_variable_list;
Example wire c; //declare a wire c
Variable data types
Variable data types are used as temporary storage of programming data. Variables can only be
assigned a value from within an initial procedure, an always procedure, a task or a function.
Variables can only store logic values; they cannot store logic strength. Variables are un-
initialized at the start of simulation, and will contain logic X until a value is assigned. Variables
can be declared trough a keyword reg.
Reg
A reg (register) is a data object that holds its value from one procedural assignment to the next.
They are used only in functions and procedural blocks. A reg is a Verilog variable type and
does not necessarily imply a physical register.
Syntax reg [msb: lsb] reg_variable_list;
Example reg a; // single 1-bit register variable
Continuous Assignment
The continuous assignment is used to assign a value onto a wire in a module. It is the normal
assignment outside of always or initial blocks. Continuous assignment is done with an assign
statement or by assigning a value to a wire during its declaration. The order of assign statements
does not matter. A change in any of the right-hand-side inputs will immediately reflect on the
left-hand-side output.
Syntax
wire wire_variable = value;
assign wire_variable = expression;
Example:
Note: The first assignment changes m before the second assignment reads m.
variable <= expression;
Non-blocking procedural assignment. Expression is evaluated when the statement is
encountered, and assignment is postponed until the end of the simulation time-step. In a
beginend sequential statement group, execution of the next statement is not blocked; and
will be evaluated before the assignment is complete.
In the sequence ;
begin
m<=n;
n<=m;
end
Procedure:
We are going to write a simple program in verilog for simple AND gate
To enter this design, first start the Project Navigator of Xilinx ISE 12.1 by clicking on the
Project Navigator Icon, as shown in Figure 11.1
Figure 11.1
Figure 11.2
For a new project, select the File menu and select New Project as shown in Figure 11.3. This
window allows the user create a New Project. For the AND gate design example, we would
like to create a New Project
A New Project window will then appear. It will have the following fields: Project Name (Name
of project), Project Location (location to store files), and Project Device Options. Name the
project and place it as your desire, enter Project Name: myand (in our case)
Figure 11.6
Figure 11.8
In the case of our simple AND gate example, we enter following code as shown in Figure 11.9.
Lab Task:
Implement NAND, OR, NOR and NOT gate and verify it using Testbench.
Circuit Diagram:
i) Circuit diagram for Half Adder
Task:
Modify above code which will perform function given below.
I. Add one bit input name updw to the sensitivity list if updw == 1 the counter will count
upward e.g. 1 2 3 and when updw =0 it will count down e.g. 3 2 1 0.
S_1: begin