Student's Manual
Student's Manual
Student's Manual
1
II. DE2 BOARD
2
24-bit CD-quality audio CODEC with line-in, line-out, and
microphone-in jacks
VGA DAC (10-bit high-speed triple DACs) with VGA-out connector
TV Decoder (NTSC/PAL) and TV-in connector
10/100 Ethernet Controller with a connector
USB Host/Slave Controller with USB type A and type B connectors
RS-232 transceiver and 9-pin connector
PS/2 mouse/keyboard connector
IrDA transceiver
Two 40-pin Expansion Headers with diode protection
In order to use the DE2 board, the user has to be familiar with the
Quartus II software.
2.a Connect the provided USB cable from the host computer to the
USB Blaster connector on the DE2 board. For communication
between the host and the DE2 board, it is necessary to install the
Altera USB Blaster driver software.
2.c Turn the RUN/PROG switch on the left edge of the DE2 board to
RUN position; the PROG position is used only for the AS Mode
programming.
2.d Turn the power on by pressing the ON/OFF switch on the DE2
board.
3.a SWITCHES
3
depressed. Since the pushbutton switches are debounced, they are
appropriate for use as clock or reset inputs in a circuit.
3.b LEDs
A list of the pin names on the Cyclone II FPGA that are connected
to the toggle switches is given in Table 1. Similarly, the pins used to
connect to the pushbutton switches and LEDs are displayed in Tables 2
and 3, respectively.
4
Signal Name FPGA Pin No. Description
KEY[0] PIN_G26 Pushbutton[0]
KEY[1] PIN_N23 Pushbutton[1]
KEY[2] PIN_P23 Pushbutton[2]
KEY[3] PIN_W26 Pushbutton [3]
Table 2: Pin Assignments for the pushbutton switches
The DE2 Board has eight 7-segment displays. These displays are
arranged into two pairs and a group of four, with the intent of displaying
numbers of various sizes. The seven segments are connected to pins on the
5
Cyclone II FPGA. Applying a low logic level to a segment causes it to light up,
and applying a high logic level turns it off.
5. CLOCK INPUTS
The DE2 board includes two oscillators that produce 27 MHz and 50 MHz
clock signals. The board also includes an SMA connector which can be used to
connect an external clock source to the board. The pin assignments appear in
Table 5.
Signal Name FPGA Pin No. Description
CLOCK_27 PIN_D13 27 MHz clock input
CLOCK_50 PIN_N2 50 MHz clock input
EXT_CLOCK PIN_P26 External (SMA) clock input
Table 5: Pin assignments for the clock
7
8
LABORATORY EXPERIMENT 1
DIGITAL LOGIC GATES
VCC
5V
1A VCC
1B 4A
1Y 4B
2A 4Y
2B 3A
2Y 3B
GND 3Y
74LS00N
1Y VCC
1A 4Y
1B 4B
2Y 4A
2A 3Y
2B 3B
GND 3A
74LS02N
1A VCC
1Y 6A
2A 6Y
2Y 5A
3A 5Y
3Y 4A
GND 4Y
74LS04N
1A VCC
1B 4B
1Y 4A
2A 4Y
2B 3B
2Y 3A
GND 3Y
74LS08N
1A VCC
1B 4B
1Y 4A
2A 4Y
2B 3B
2Y 3A
GND 3Y
74LS32N
1A VCC
1B 4B
1Y 4A
2A 4Y
2B 3B
2Y 3A
GND 3Y
74LS86N
LEARNING OBJECTIVES:
Identify various ICs, connection diagrams, and their specifications.
To study and verify the truth table of logic gates.
To demonstrate NAND gates as a universal gate.
To implement a Boolean function using NAND gates.
9
BASIC CONCEPTS:
The basic logic gates are the building blocks of more complex logic circuits.
These logic gates perform the basic Boolean functions, such as AND, OR, NAND, NOR,
Inversion, Exclusive-OR, Exclusive-NOR. Figure 1 shows the pin assignment to the
various logic gates. It is seen from the Figure 1 that each gate has one or two binary
inputs. The small circle on the output of the circuit symbols designates the logic
complement. The AND, OR, NAND, and NOR gates can be extended to have more
than two inputs.
Digital circuits are frequently constructed with NAND or NOR gates rather than
with AND and OR gates. NAND and NOR gates are easier to fabricate with electronic
components and are the basic gates used in all IC digital logic families. Because of the
prominence of NAND and NOR gates in the design of digital circuits, rules and
procedures have been developed for the conversion from Boolean functions given in
terms of AND, OR, and NOT into equivalent NAND and NOR logic diagrams.
PROCEDURES:
1. Check the ICs for their working by inserting the IC into the breadboard.
2. The pin assignments to the various gates are shown in Figure 1.
10
2-input XOR gate 2-input NOR gate
7486 7402
3. Provide the input data in the input switches, SW0 and SW7, and observe the
output on the LED0. Complete the table below.
No. IC Number SYMBOL INPUTS OUTPUT
3.1 SW0 SW7 LED0
AND IC SW0
0 0
7408 LED0 0 1
SW7
1 0
1 1
3.2 SW0
0 0
OR IC 0 1
LED0
7432 SW7
1 0
1 1
3.3
NOT/INVERTER SW0 0 -
LED0
7404
1 -
3.4 SW0
0 0
NAND IC 0 1
LED0
7400 SW7
1 0
1 1
3.5 SW0
0 0
NOR IC 0 1
LED0
7402 1 0
SW7
1 1
3.6 SW0
0 0
EX-OR IC 0 1
7486 LED0
SW7
1 0
1 1
Table 1
11
4. Universal NAND Gate
Using 7400 IC, connect a circuit that produces
a. an inverter.
b. a two-input AND.
c. a two-input OR.
d. a two-input NOR.
e. a two-input XOR.
In each case, verify your circuit by checking its truth table in Procedure 3.
5. Construct a circuit using 7400 IC that implements the Boolean function:
12
LABORATORY EXPERIMENT 2
SIMPLIFICATION OF BOOLEAN FUNCTIONS
VCC
5V
LED0
1A VCC 1A VCC
1B 4A 1B 1C
1Y 4B 2A 1Y
2A 4Y 2B 3C
2B 3A 2C 3B
2Y 3B 2Y 3A
GND 3Y GND 3Y
74LS00N 74LS10N
VCC
5V LED0
1A VCC
1B 4A
1Y 4B
2A 4Y
2B 3A
2Y 3B
GND 3Y
74LS00N
LEARNING OBJECTIVES:
To simplify the Boolean expression and to implement the logic circuit.
Given a truth table to derive the Boolean expressions and build the logic circuit.
BASIC CONCEPTS:
Gate-level minimization refers to the design task of finding an optimal gate-level
implementation of the Boolean functions describing a digital circuit. The complexity of
the digital logic gates that implement a Boolean function is directly related to the
complexity of the algebraic expression from which the function is implemented.
Although the truth table representation of a function is unique, when it is expressed
algebraically it can appear in many different, but equivalent, forms. Boolean expressions
may be simplified by algebraic means. However, this procedure of minimization is
awkward because it lacks specific rules to predict each succeeding step in the
manipulative process.
A Karnaugh map (K-map) is a straightforward procedure for minimizing Boolean
functions. A K-map is a diagram made up of squares, with each square representing
one minterm of the function that is to be minimized. The simplified expressions
13
produced by the map are always in one of the two standard forms: sum of products or
product of sums.
PROCEDURES:
LOGIC DIAGRAM
1. This part of the experiment starts with a given logic diagram from which we
proceed to apply simplification procedures to reduce the number of gates and,
possibly, the number of ICs. The logic diagram shown below requires two ICs – a
7400 and 7410. Note that the inverters for inputs x, y, and z are obtained from
the remaining three gates in the 7400 IC. If the inverters were taken from 7404
IC, the circuit would have required three ICs.
Figure 1
2. Connect the circuit in Figure 1 with the x, y, and z inputs going to three switches
(SW0, SW1 and SW2) and the output F to a LED0 indicator. Test the circuit and
complete the truth table below.
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
Table 1
14
3. Obtain the Boolean function of the circuit and simplify it, using map method.
Construct the simplified circuit using NAND gates. Test the circuit by connecting
the inputs to the switches and output to LED0. Show that the eight possible input
combinations of the circuits have identical outputs. This will prove that the
simplified circuit behaves exactly like the original circuit.
BOOLEAN FUNCTIONS
4. Consider two Boolean functions in sum-of-minterms form:
( ) ( )
( ) ( )
Simplify these functions by means of maps. Obtain a composite logic diagram
with four inputs, A, B, C and D connected to SW0, SW1, SW2 and SW3
respectively, and two outputs, F1 and F2 connected to LED0 and LED1.
Implement the two functions together, using a minimum number of NAND ICs.
Do not duplicate the same gate if the corresponding term is needed for both
functions. Use any extra gates in existing ICs for inverters if possible. Connect
the circuit and check its operation. The truth table for F 1 and F2 obtained from the
circuit should conform to the minterms listed.
COMPLEMENT
5. Plot the following Boolean function in a map:
Combine the 1‟s in the map to obtain the simplified function for F in sum-of-
products form then combine the 0‟s in the map to obtain the simplified function F‟,
also in sum-of-products form. Implement both F and F‟ with NAND gates and
connect the two circuits to the same input switches, but to separate output LED
displays. Obtain the truth table of each circuit and show that they are
complements of each other.
15
LABORATORY EXPERIMENT 3
ADDERS AND SUBTRACTORS
VCC
5V SUM
1A VCC
1B 4B
1Y 4A
2A 4Y
2B 3B
2Y 3A
GND 3Y
74LS86N
CARRY
1A VCC
1B 4B
1Y 4A
2A 4Y
2B 3B
2Y 3A
GND 3Y
74LS08N
VCC
5V DIFFERENCE
1A VCC
1B 4B
1Y 4A
2A 4Y
2B 3B
2Y 3A
GND 3Y
74LS86N
BORROW
1A VCC
1Y 6A
2A 6Y 1A VCC
2Y 5A 1B 4B
3A 5Y 1Y 4A
3Y 4A 2A 4Y
GND 4Y 2B 3B
2Y 3A
74LS04N GND 3Y
74LS08N
LEARNING OBJECTIVES:
To realize the adders and subtractors circuits using basic gates.
To learn about IC 7483 and its internal structure.
BASIC CONCEPTS:
Half Adder: A combinational logic circuit that performs the addition of two data
bits, A and B, is called a half-adder. Addition will result in two output bits; one of
which is the sum bit, S, and the other is the carry bit, C.
16
Half Subtractor: Subtracting a single-bit binary value B from another A (i.e. A -
B) produces a difference bit D and a borrow bit Bo. This operation is called half
subtraction and the circuit to realize it is called a half-subtractor.
Full Adder: The half-adder does not take the carry bit from its previous stage
into account. This carry bit from its previous stage is called carry-in bit. A
combinational logic circuit that adds two data bits, A and B, and a carry-in bit,
Cin, is called a full-adder.
Four-bit Parallel Adder: The Full adder can add single-digit binary numbers and
carries. The largest sum that can be obtained using a full adder is 11 2. Parallel
adders can add multiple-digit numbers. If full adders are placed in parallel, we
can add two- or four-digit numbers or any other size desired. Figure below uses
STANDARD SYMBOLS to show a parallel adder capable of adding two four-digit
binary numbers. The addend would be on A inputs, and the augend on the B
inputs. For this explanation we will assume there is no input to C in (carry from a
previous circuit)
PROCEDURES:
HALF ADDER
1. Construct and test a half-adder circuit shown in Figure 1 using one XOR gate AND
gate. Connect the inputs A and B to SW1 and SW0 respectively, the sum and carry
to LED0 and LED1 respectively. Complete the table 1 to determine the status of
17
the LED0 and LED1, with the possible combinations of the switches, if they are ON
or OFF.
INPUTS OUTPUTS
SW0 SW1 Sum Carry
(LED0) (LED1)
0 0
0 1
1 0
1 1
Table 1
A
Sum
B
7486N
Carry
7408N
Figure 1
Write the output Boolean equation for the Sum and Carry. _________
_________
FULL ADDER
2. Construct and test a full-adder circuit shown in Figure 2. Connect the inputs A, B,
CIN to SW0, SW1 and SW2 respectively, the sum and carry to LED0 and LED1
respectively. Complete the table 2 to determine the status of the LED0 and
LED1, with the possible combinations of the switches, if they are ON or OFF.
INPUTS OUTPUTS
SW0 SW1 SW2 Sum Carry
(A) (B) (Cin) (LED0) (LED1)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 2
18
A
B Sum
74LS86N
74LS86N
Cin
74LS08N
74LS32N Carry
74LS08N
74LS32N
74LS08N
Figure 2
Write the output Boolean equation for the Sum and Carry. _________
_________
HALF SUBTRACTOR
3. Construct and test a half-subtractor circuit shown in Figure 3. Connect the inputs
A and B to SW0 and SW1 respectively, the Difference(D) and Borrow(Bo) to
LED0 and LED1 respectively. Complete the table 3 to determine the status of the
LED0 and LED1, with the possible combinations of the switches, if they are ON
or OFF.
INPUTS OUTPUTS
SW0 SW1 D Bo
(A) (B) (LED0) (LED1)
0 0
0 1
1 0
1 1
Table 3
A
Difference
B
74LS86N
Borrow
74LS04N 74LS08N
Figure 3
Write the output Boolean equation for the Difference and Borrow. _________
_________
19
FULL SUBTRACTOR
4. Construct and test a full-subtractor circuit shown in figure 4. Connect the inputs
A, B, C to SW0, SW1 and SW2 respectively, the difference and borrow to LED0
and LED1 respectively. Complete the table 4 to determine the status of the LED0
and LED1, with the possible combinations of the switches, if they are ON or OFF.
INPUTS OUTPUTS
SW1 SW2 SW3 D Bo
(A) (B) (C) (LED0) (LED1)
0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1
Table 4
A
74LS86N
B Difference
C
74LS86N
74LS04N 74LS08N
74LS32N
74LS08N
Borrow
74LS32N
74LS08N
Figure 4
Write the output Boolean equation for the Difference and Borrow. _________
_________
PARALLEL ADDER
5. IC type 7483 is a four-bit binary parallel adder. The pin assignment is shown in
figure 5. The 2 four bit input binary numbers are A1 through A4 and B1 through
B4. The four bit sum is obtained from S1 through S4. C0 is the input carry and
C4 the output carry.
20
Test the four-bit binary adder 7483 by connecting the power supply and
ground terminals. Then connect the four inputs A to (SW0, SW1, SW2 and SW3)
and B inputs (SW4, SW5, SW6, SW7). The five outputs are applied to LEDs.
Perform the addition of a few binary numbers and check that the output sum
and output carry give the proper values. Show that when the input carry is equal
to 1, it adds 1 to the output sum.
Figure 5
21
LABORATORY EXPERIMENT 4
DECODERS and ENCODERS
VCC
5V
CA
J1 16
VCC
7 A OA 13
1 B OB 12
2 C OC 11
6 D OD 10
OE 9
3 ~LT OF 15
5 14 ABCDEFGHABCDEFGH
~RBI OG
4 ~BI/RBO
8 GND
74LS47N
VCC 16
7 A OA 13
1 B OB 12
2 C OC 11
6 D OD 10
OE 9
3 ~LT OF 15
5 ~RBI OG 14
4 ~BI/RBO
8 GND
74LS47N
VCC
5V
LED2 LED1 LED0
10 D0 VCC 16
11 D1 A0 9
12 D2 A1 7
13 D3 A2 6
1 D4
2 D5 GS 14
3 D6 EO 15
4 D7
5 EI
8 GND
74LS148N
LEARNING OBJECTIVES:
To realize a decoder circuit using basic gates
To design a 2x4 decoder using basic gates.
To verify IC 74LS138 and IC 74LS139.
To use 7447 IC for BCD to decimal conversion
22
To learn and understand the working IC 74147, IC 74148 and IC 74157.
To learn to do code conversion using encoders
BASIC CONCEPTS
A decoder is a combinational circuit that connects the binary information
from „n‟ input lines to a maximum of 2 n unique output lines. Decoder is also called
a minterm generator or maxterm generator. A minterm generator is constructed
using AND and INVERTER gates. The output is indicated by logic 1. A maxterm
generator is constructed using NAND gates. The output is indicated by a logic 0.
The name decoder is also used in conjunction with other code converters, such
as BCD-to-seven-segment decoder.
The light emitting diode (LED) finds its place in many applications in these
modern electronics fields. One of them is the Seven Segment Display. Seven
segment displays contains the arrangement of the LEDs in eight passion and a
dot(.) with a common electrode (Anode or Cathode). The purpose of arranging it
in the passion is that we can make any number out of that by switching ON and
OFF the particular LEDs. Figure 1 is the block diagram of the Seven Segment
LED arrangement.
Figure 1
23
PROCEDURES:
I. DECODERS
74LS08N
I3
74LS08N
Figure 1
b. Replace the IC 7408 to IC 7400 in Procedure 1.a. For this circuit vary the
inputs (all possible combinations of inputs) and note the corresponding
outputs. Complete the table 2 below.
A B
Inputs Outputs
A B I0 I1 I2 I3
0 0 7404N 7404N
0 1
1 0
I0
1 1
7400N
I1
Table 2
7400N
I2
7400N
I3
7400N
Figure 2
24
Compare the truth table in procedure 1.a and procedure 1.b.
________________________________________________________________
________________________________________________________________
________________________________________________________________
~1G VCC
Inputs Outputs 1A ~2G
1A 1B IY0 IY1 IY2 IY3 1B 2A
0 0 1Y0 2B
0 1 1Y1 2Y0
1 0 1Y2 2Y1
1Y3 2Y2
1 1
GND 2Y3
Table 3
74LS139N
Figure 3
3. 3x8 Decoder
Study the IC type 74LS138 shown in figure 4. Test the 3x8 decoder by
connecting the power supply, ground terminals and implementing a full adder.
Inputs A, B and C are connected to SW0, SW1 and SW2 respectively. Connect
G1 to SW3 and set to „1‟. ~G2A and ~G2B serve as an enable and they are
connected to ground.
1 A VCC 16
2 B Y0 15
3 C Y1 14
Y2 13
6 G1 Y3 12
4 ~G2A Y4 11
5 ~G2B Y5 10
Y6 9
8 GND Y7 7
74LS138N
Figure 4
25
4. BCD to Seven Segment Decoder
Use the dual seven segment display in the training module to complete
the column in Decimal Number Display. The IC 7447 in Figure 6 takes the Binary
Coded Decimal (BCD) as the input and outputs the relevant 7 segment code.
Test the dual 7-segment in the board by connecting the power supply and ground
terminals. Connect the D, C, B, A to switches SW0, SW1, SW2 and SW3.
Complete the table 4 below and observe the outputs. Make sure that the Gnd
and Vcc is connected.
VCC 16
7 A OA 13
1 B OB 12
2 C OC 11
6 D OD 10
OE 9
3 ~LT OF 15
5 ~RBI OG 14
4 ~BI/RBO
8 GND
74LS47N
Figure 5
Table 4
26
II. ENCODERS
Construct and test a decimal-to BCD encoder using IC 74147 shown in Figure 7.
Connect the output lines D, C, B, A to LED0, LED1, LED2 and LED3 respectively. I1, I2,
I3, I4, I5, I6, I7 and I8 are connected to the input switches SW0, SW1, SW2, SW3,
SW4, SW5,SW6 AND SW7 respectively. Complete the truth table shown in Table 5.
INPUTS OUTPUTS
I1 I2 I3 I4 I5 I6 I7 I8 I9 D C B A
1 1 1 1 1 1 1 1 0
X X X X X X X 0 1
X X X X X X 0 1 1
X X X X X 0 1 1 1
X X X X 0 1 1 1 1
X X X 0 1 1 1 1 1
X X 0 1 1 1 1 1 1
X 0 1 1 1 1 1 1 1
0 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1 1
Table 5
11 1 A 9
12 2 B 7
13 3 C 6
1 4 D 14
2 5
3 6
4 7
5 8
10 9
74LS147N
Figure 6
27
LABORATORY EXPERIMENT 5
MULTIPLEXERS AND DEMULTIPLEXERS
VCC
5V Sum Carry
VCC 16
6 1C0 1Y 7
5 1C1
4 1C2
3 1C3
10 2C0 2Y 9
11 2C1
12 2C2
13 2C3
14 A
2 B VCC
1A VCC
1Y 6A 1 ~1G
2A 6Y 15 ~2G 5V
2Y 5A 8 GND
3A 5Y
3Y 4A 74LS153N
GND 4Y
74LS04N
~1G VCC
1A ~2G
1B 2A
1Y0 2B
1Y1 2Y0
1Y2 2Y1
1Y3 2Y2
GND 2Y3
74LS139N
LEARNING OBJECTIVES:
To design and set up a 4-1 Multiplexer (MUX) using only NAND gates.
To design and set up a 1-4 Demultiplexer(DE-MUX) using only NAND gates.
To verify the various functions of IC 74153(MUX) and IC 74139(DEMUX).
To set up a Half Adder and Half Subtractor using IC 74153.
BASIC CONCEPTS
Multiplexers are very useful components in digital systems. They transfer
a large number of information units over a smaller number of channels, (usually
one channel) under the control of selection signals. Multiplexer means many to
one. A multiplexer is a circuit with many inputs but only one output. By using
control signals (select lines) we can select any input to the output. Multiplexer is
also called as data selector because the output bit depends on the input data bit
that is selected. The general multiplexer circuit has 2 n input signals, n
control/select signals and 1 output signal.
28
INPUTS 4-1
4:1 MUX Y = E’S1’S0’I0 + E’S1’S0I1 + E’S1S0’I2 +
MUX E’S1S0I3
ENABLE
(E’)
SELECT
INPUTS
PROCEDURES:
I. MULTILPLEXER
1. 4 to 1 MULTIPLEXER
29
S1 S0 En
I0
74LS20N
I1
Y
74LS20N
74LS20N
I2
74LS20N
I3
74LS20N
b. IC type 74153 is a Dual 4-Input Multiplexer with common select inputs and
individual enable inputs for each section. It can select two bits of data from
four sources. The pin assignment is shown in Figure 3.
Test the Dual 4-Input Multiplexer by connecting the power supply and
ground terminals. Then connect the four inputs 1C0, 1C1, 1C2 and IC3 to
SW0, SW1, SW2 and SW3 respectively. A and B are the select lines
connected to SW6 and SW7 respectively, and ~1G as the enable input
connected to the input switch SW5. The output 1Y is applied to LED.
Verify your answers in Table 1.
30
VCC 16
6 1C0 1Y 7
5 1C1
4 1C2
3 1C3
10 2C0 2Y 9
11 2C1
12 2C2
13 2C3
14 A
2 B
1 ~1G
15 ~2G
8 GND
74LS153N
Figure 3: IC 74153
5V
VCC 16
A 6 1C0 1Y 7 Sum
5 1C1
4 1C2
3 1C3
10 2C0 2Y 9 Carry
11 2C1
12 2C2
13 2C3
B
14 A
2 B
1 ~1G
15 ~2G
8 GND
74LS153N
5V
A VCC 16
6 1C0 1Y 7 Difference
5 1C1
4 1C2
3 1C3
10 2C0 2Y 9 Borrow
11 2C1
12 2C2
13 2C3
B
14 A
2 B
1 ~1G
15 ~2G
8 GND
74LS153N
31
II. DEMULTIPLEXER
1. 1-to-4 DEMULTIPLEXER
Y0
74LS00N
74LS20N
Y1
74LS00N
74LS20N
Y2
74LS00N
74LS20N
Y3
74LS00N
74LS20N
b. IC type 74139 is a Dual 4-Input Multiplexer with common select inputs and
individual enable inputs for each section. It can select two bits of data from
four sources. The pin assignment is shown in Figure 7. Make sure that
Vcc and Gnd of the IC is connected. 1Y0, 1Y1, 1Y2, 1Y3 are connected to
LED0, LED1, LED2 and LED3 respectively. Attach the enable input, ~1G,
to SW0. Verify your answer in Table 2.
32
~1G VCC
1A ~2G
1B 2A
1Y0 2B
1Y1 2Y0
1Y2 2Y1
1Y3 2Y2
GND 2Y3
74LS139N
Figure7: 74139
33
LABORATORY EXPERIMENT 6
FLIP-FLOPS AND COUNTERS
VCC
A
555_timer U1 U2
1 1CLK 1K 16 1 1CLK 1K 16
2 ~1PR 1Q 15 2 ~1PR 1Q 15
3 ~1CLR ~1Q 14 3 ~1CLR ~1Q 14
4 1J GND 13 4 1J GND 13
5 VCC 2K 12 5 VCC 2K 12
6 2CLK 2Q 11 6 2CLK 2Q 11
7 ~2PR ~2Q 10 7 ~2PR ~2Q 10
8 ~2CLR 2J 9 8 ~2CLR 2J 9
74LS76N 74LS76N
LEARNING OBJECTIVES:
Characteristic table verification of
- RS flip-flop
- T flip-flop
- D flip-flop
- JK flip-flop
To learn about various flip-flops
Conversion of one type of flip-flop to another
To test a 4-bit binary synchronous counter using flip-flop IC 7476.
BASIC CONCEPTS:
Logic circuits that incorporate memory cells are called sequential logic circuits;
their output depends not only upon the present value of the input but also upon the
previous values. Sequential logic circuits often require a timing generator (a clock) for
their operation. The latch (flip-flop) is a basic bi-stable memory element widely used in
sequential logic circuits. Usually there are two outputs, Q and its complementary value,
~Q.
34
An S-R latch consists of two cross-coupled NOR gates. An S-R flip-flop can also
be design using cross-coupled NAND gates.
A clocked S-R flip-flop has an additional clock input so that the S and R inputs
are active only when the clock is high. When the clock goes low, the state of flip-flop is
latched and cannot change until the clock goes high again. Therefore, the clocked S-R
flip-flop is also called “enabled” S-R flip-flop.
A D latch combines the S and R inputs of an S-R latch into one input by adding
an inverter. When the clock is high, the output follows the D input, and when the clock
goes low, the state is latched.
A S-R flip-flop can be converted to T-flip flop by connecting S input to Q‟ and R to
Q.
The J-K flip-flop can be compared to the bistable flip-flop and the triggered
bistable flip-flop combined. Refer to the logic diagram symbol of the JK flip-flop shown in
Figure 1. The clear and preset inputs correspond to the reset and set inputs of the
bistable flip-flop. The J, K and clock inputs correspond to the set, reset and trigger
inputs of a triggered bistable flip-flop. The Q and Q‟are inverse outputs that correspond
to set and reset. Thus, the JK flip-flop the clear and preset inputs are normally used to
reset it or preset it to an initial condition before or after a particular operation. The J, K
and clock inputs then are used during the operation to trigger the flip-flop as required.
The small circles on the clear, clock and preset inputs mean that these input signals
must go to a low level (logic 1 to logic 0 for positive logic) to cause the flip-flop to set or
reset. The absence of the small circles on the J and K inputs means that these input
signals must be at high level (logic 1) before the flip-flop can be triggered to either state
by the clock pulse. A low level signal applied to either of these inputs prevents triggering
to that state. It should be pointed out that when any input is disconnected or unused, the
flip-flop assumes a high level input and operates accordingly. The J-K flip-flop is one of
the most commonly used flip-flops in digital electronics. Because of its basic operation
and versatility it can be used in digital counters, registers, encoders, decoders, or simply
as a slip-flop.
~1PR
1J 1Q
1CLK
1K ~1Q
~1CLR
35
PROCEDURES:
I. SR flip-flop
a. Examine the circuits shown in Figure 1, Figure 2 and Figure 3. Switches SW0
and SW1 are used to apply logic levels to S and R flip-flop input. Connect the
circuit and complete the characteristic tables of the circuits shown below. The
output Q and ~Q are connected to LED0 and LED1 respectively. Use the out of
the 555 timer to serve as the Clk in Figure 3.
Figure 1: Cross-coupled
NOR gates
R
Q S R Q Q’ Remarks
1 0
7402N
0 0 After S=1, R=0
~Q 0 1
S
0 0 After S=0, R=1
7402N 1 1 forbidden
Figure 2: Cross-coupled
NAND gates
S S R Q Q’ Remarks
Q
1 0
7400N 1 1 After S=1, R=0
0 1
~Q
R 1 1 After S=0, R=1
7400N 0 0 forbidden
36
II. CONVERSION OF JK-FLIP FLOP TO T-FLIP FLOP
The T (toggle) flip-flop is a complementing flip-flop and can be obtained
from a JK flip-flop when J and K are tied together. This is shown in Figure 4.
When T = 0 (J=K=0), a clock edge does not change the output. When T=1
(J=K=1), a clock edge complements the outputs. Connect the circuit shown in
Figure 4. Connect the Clk to SW0 and vary the input from 1 to 0 repeatedly and
observe the output (1Q and ~1Q) to LED0 and LED1. Show that if functions as a
Toggle flip-flop.
VCC
2
~1PR
4 1J 1Q 15
Clk
1 1CLK
16 1K ~1Q 14
~1CLR
3 74LS76N
2
~1PR Clk D Qt+1
D
4 1J 1Q 15 1 X
Clk 1 1CLK 0 0
16 14
1K ~1Q 0 1
7404N ~1CLR
3 74LS76N
The five inputs to a JK flip-flop are clear, preset, J, K and clock. Clear and
preset inputs are used to insure a defined flip-flop condition prior to a J, K or
clock signal to control the output. If J = K = 0 the clock produces no change in
output; if J = K =1 the output changes with each clock pulse. Connect the circuit
in Figure 6 and demonstrate the operation of a JK flip-flop and complete the
table.
37
Figure 6: JK FLIP FLOP USING IC 7476
VCC
2
J J K Q Remarks
~1PR
4 1J 1Q 15 0 0
Clk 1 1CLK 0 1
16 1K ~1Q 14 1 0
K
~1CLR 1 1
3 74LS76N
The four bit binary counter is one of the many circuits used to process and
control digital data. This circuit consists of four triggered flip-flops connected so as to
trigger each other in succession. By applying clock pulses to the first flip-flop and using
the set output of each trigger the next flip-flop, the set-reset states of the four flip-flops
will represent a binary count of 0 through 15. Connect the circuit shown in Figure 7 and
verify the functionality. The LEDs are used to read out the four bits of the binary count.
Use the 555 timer output to produce continuous clock pulses.
VCC
LED3 LED2 LED1 LED0
5V
555 1J 1Q 1J 1Q 1J 1Q 1J 1Q
1CLK 1CLK 1CLK 1CLK
1K ~1Q 1K ~1Q 1K ~1Q 1K ~1Q
Figure 7
The decade counter is another of the many circuits used to process and
control digital data. This circuit is similar to the four bit binary counter except that
two of the flip-flops are gated to reset all flip-flops on the tenth count. Refer to
Figure 8. The decade counter operates as a straight binary counter for clock
pulses 1 through 9.
38
Connect the circuit shown in Figure 8. The four flip-flops form the decade
counter. Output D, C, B and A are connected to the seven segment display to
read out in numerical value. Use the Clk(555) output to produce continuous clock
pulses.
D C B A
VCC
5V
555 1J 1Q 1J 1Q 1J 1Q 1J 1Q
Figure 8
39
40
LABORATORY EXERCISE 1
TOOL FAMILIARIZATION
LEARNING OBJECTIVES
To familiarize yourselves with Quartus II Web Editon 10.1
To implement and test a combinational logic circuit in VHDL
PROCEDURE:
1. Start the Quartus II software. You should see a display similar to the one
in Figure 1. This display consists of several windows that provide access to all
features of Quartus II.
41
also the name of the top-level design entity in the project. Press
Next. Since we have not yet created the directory
tutorial1\designstyle1, Quartus II displays the pop-up box in Figure
3 asking if it should create the desired directory. Click Yes, which
leads to the window in Figure 4. In this window the designer can
specify which existing files (if any) should be included in the project.
We have no existing files, so click Next.
42
Figure 4: A window for inclusion of design files
43
II. Using the Text Editor
2. Quartus II provides a text editor that can be used for typing VHDL code.
Select File > New to get the window in Figure 6, choose VHDL File, and click
OK. This opens the Text Editor window. The first step is to specify a name for
the file that will be created. Select File > Save As to open pop-up box shown
in Figure 7. In the box labeled Save as type choose VHDL file. In the box
labeled File Name type example_vhdl. (Quartus II will add the filename
extension vhd, which must be used for all files that contain VHDL code.)
Leave the box checked at the bottom of the figure, which specifies Add file to
current project.
44
The VHDL code for this example is shown in Figure 8. Enter
this code into the Text Editor window. When creating a new project,
we chose the name example_vhdl for the top-level design entity.
Hence, the VHDL entity must match this name. Save the file, by
using File > Save or the shortcut Ctrl-s.
45
III. Simulating the Designed Circuit
Select Start > All Programs > Altera > University Program >
Simulation Tools > Altera U.P. Simulator. In the displayed
window select File > Open Project, which leads to the pop-up
window in Figure 10. Here, choose the Quartus II project that you
created. This is done by selecting the file example_vhdl.qpf as
shown in the figure. Note that the suffix .qpf stands for “quartus
project file".
46
To create test vectors for your design, select the Qsim
command File > New Simulation Input File. This command opens
the Waveform Editor tool, shown in Figure 12, which allows you to
specify the desired input waveforms.
In the Waveform Editor window, select Edit > Insert > Insert
Node or Bus. In the pop-up window that appears, which is shown
in Figure 13, click on Node Finder.
47
and also upon return to the window in Figure 13.This returns to the
Waveform Editor window, with the selected signals included as
presented in Figure 16.
48
Figure 15: The Selected signals
49
on grid lines. This feature is activated by clicking on the Snap to
Grid icon.
50
Figure 19: Drawing waveform for x1
51
manner. Click on the x3 input, which selects the entire 800-ns
interval. Then, click on the Overwrite Clock icon , as indicated in
Figure 21. This leads to the pop-up window in Figure 22. Specify the
clock period of 200 ns and the duty cycle of 50%, and click OK. The result
is depicted in Figure 23.
52
Figure 23: The completed input waveforms
Save the waveform file using a suitable name; we chose the name
example_vhdl.vwf. Note that the suffix vwf stands for vector waveform
file.
5. Simulation
Return to the Qsim window (in Figure 10). Select Assign >
Simulation Settings. A pop-up window shown in Figure 24 will appear
and browse for the file example_vhdl.vwf. Choose Functional.
53
simulation have to be done by modifying the example_vhdl.vwf file and
resimulating the circuit. Click OK. Qsim will now display the waveforms
produced in the simulation process, which are depicted in Figure 25.
The table in the bottom of Figure 26 lists the input and output ports of our
design project, and allows these ports to be assigned to specific pins. To
make the desired connection for input x1, double-click on its Location
column, as indicated in Figure 27, and choose pin N25 from the displayed list.
Repeat this procedure to complete all of the pin assignments, which leads to
the display in Figure 28.
54
Recompile the project with pin assignments to cause pin assignments to
be applied. .
55
V. Programming and Configuring the FPGA Device
Once the circuit has been compiled, it can be downloaded into the FPGA
chip on the DE2 board. The board supports a programming mode known as
JTAG programming. The configuration data is transferred from the host
computer (which runs the Quartus II software) to the board by means of a
cable that connects a USB port on the host computer to the corresponding
USB connector on the DE2 board. To use this connection, it is necessary to
have Altera‟s USB-Blaster software driver installed.
In the JTAG mode, the configuration data is loaded directly into the FPGA
device. The acronym JTAG stands for Joint Test Action Group.
6. JTAG Programming
Make sure that the RUN/PROG switch on the DE2 board is set to
the RUN position. Select Tools > Programmer to reach the window in Figure
29. If not already chosen in default, select JTAG in the Mode box. Also, if the
USB-Blaster is not chosen by default, press Hardware Setup button and
select the USB-Blaster in the window that pops-up as shown in Figure 30.
In the window in Figure 29 make sure that Program/Configure is
checked and then press Start. A blue LED on the board will light up when the
configuration data has been downloaded successfully.
Having downloaded the configuration data into the FPGA device,
you can now test the implemented circuit. Try all eight combinations of the
input variables x1, x2 and x3 by setting the corresponding states of the
switches SW0, SW1, and SW2.
Figure 29
56
Figure 30
57
LABORATORY EXPERIMENT 2
ADDERS AND SUBTRACTORS
LEARNING OBJECTIVES:
The purpose of this exercise is to learn to create connect simple input and output
devices to an FPGA chip and implement a circuit that performs binary addition
and subtraction that uses these devices.
PROCEDURES:
Part I
Figure 1a shows a circuit for a full adder, which has the inputs x, y, and cin, and
produces the output Sum and cout. Parts b and c of the figure show a circuit symbol and
truth table for the full adder. Write VHDL code that implements this circuit, as described
below.
Cin
Sum
Cout
58
3. Use switch SW0-2 on the DE2 board as the Cin, x, and y inputs. Connect the
output Sum to the green light LEDG7 and Cout to LEDR0.
4. Compile the project.
5. Download the compiled circuit into the FPGA chip. Test the functionality of the
full-adder by toggling the switches and observing the LEDs.
Part II
Figure 2a shows a circuit for a full subtractor, which has the inputs x, y, and z,
and produces the outputs Borrow(Bo) and Difference (D). Parts b and c of the figure
show a circuit symbol and truth table for the full subtractor. Write VHDL code that
implements this circuit, as described below.
X Y Z
Bo
(a) Circuit X Y Z D Bo
(b) Block Diagram 0 0 0 0 0
0 0 1 1 1
0 1 0 1 1
0 1 1 0 1
1 0 0 1 0
1 0 1 0 0
1 1 0 0 0
1 1 1 1 1
59
4. Compile the project.
5. Download the compiled circuit into the FPGA chip. Test the functionality of the
full-adder by toggling the switches and observing the LEDs.
Part III
Figure 3 shows how four instances of full adder entity can be used to design a
circuit that adds two four-bit numbers. This type of circuit is usually called a ripple-carry
adder, because of the way that the carry signals are passed from one full adder to the
next. Write VHDL code that implements this circuit, as described below.
60
LABORATORY EXPERIMENT 3
DECODERS and ENCODERS
LEARNING OBJECTIVES:
The purpose of this exercise is to learn and verify the operation of decoders and
encoders. We would write the VHDL code for the circuits and download to the
FPGA chip and test for the functionality by toggling the switches at the DE2
board.
PROCEDURES:
Part I
A 2-to-4 decoder is given in Figure 1. The two data inputs are w1 and w0. They
represent a two-bit number that causes the decoder to assert one of the outputs y0,…y3.
A decoder can be designed to have either active high or active low outputs. Setting the
inputs w1w0 to 00, 01, 10, or 11 causes the y0, y1, y2, or y3 to be set to 1, respectively. A
graphical symbol for the decoder is given in part (b) of the figure, and a logic circuit is
shown in part (c).
En w1 w0 y0 y1 y2 y3
1 0 0 1 0 0 0
1 0 1 0 1 0 0
1 1 0 0 0 1 0
1 1 1 0 0 0 1
x X X 0 0 0 0
(a) Truth Table w0 (b) Symbol
w1
y0
y1
y2
y3
En
61
Create a new Quartus II project for your circuit.
1. Create a VHDL code for the Figure 1 and include it in your project.
2. Use switch SW16-17 on the DE2 board as the s1,s0 input respectively, and
switches SW3−0 for w1-0 respectively. Connect the output f to the green light
LEDG0.
3. Compile the project.
4. Download the compiled circuit into the FPGA chip. Test the functionality of the 4-
to-1 multiplexer by toggling the switches and observing the LEDs.
Part II
The DE2 Board has eight 7-segment displays. These displays are arranged into
two pairs and a group of four, with the intent of displaying numbers of various sizes.
Figure 2 shows a 7-segment decoder module that has the four-bit input c3c2c1c0.
This decoder produces seven outputs that are used to display a numeric on a 7-
segment display. The seven segments in the display are identified by the indices 0 to 6
shown in the figure. Each segment is illuminated by driving it to the logic value 0. You
are to write a VHDL code that represents BCD-to-7-segment decoder.
PART III
62
one of the input signals should have a value of 1, and the outputs present the binary
number that identifies which input is equal to 1. The truth table for a 4-to2 encoder is
provided figure 4.a. Observe that the output y0 is 1 when either input w1 or w3 is 1, and
output y1 is 1 when input w2 or w3 is 1.
w3 w2 w1 w0 y1 y0
0 0 0 1 0 0
0 0 1 0 0 1
0 1 0 0 1 0
1 0 0 0 1 1
(a) Truth Table (b) Symbol
w0
w1 y0
w2
y1
w3
(c) Circuit
63
LABORATORY EXPERIMENT 4
MULTIPLEXERS AND DEMULTIPLEXERS
LEARNING OBJECTIVES:
To learn and verify the operation of multiplexers and demultiplexers. We would
write the VHDL code for the circuits and download to the FPGA chip and test for
the functionality by toggling the switches at the DE2 board.
PROCEDURES:
Part I
Figure 1.a. depicts a multiplexer with four data inputs, w0, w1, w2, and w3 and two
select inputs, s1 and s0. As shown in the truth table in part (b) of the figure, the two-bit
number represented by s1s0 selects one of the data inputs as the output of the
multiplexer. You are to write a VHDL code for a 4-to-1 demultiplexer.
s1 s0 f
0 0 w0
0 1 w1
1 0 w2
1 1 w3
a. Symbol b. Truth Table
64
Part II
w1 w0 En y0 y1 y2 y3
0 0 X En 0 0 0
0 1 X 0 En 0 0
1 0 X 0 0 En 0
1 1 X 0 0 0 En
a. Symbol b. Truth Table
65
LABORATORY EXERCISE 5
FLIP-FLOPS
LEARNING OBJECTIVES:
The purpose of this exercise is to learn and verify the operations of a flip-flop.
PART I
A D flip-flop has a single input, called D, and it stores the value of this input,
under the control of a clock signal. Figure 1.b shows the circuit for a gated D flip-flop. In
the gated D flip-flop, the output merely tracks the value of the input D while Clk = 1. As
soon as Clk goes to 0, the state of the latch is frozen until the next time the clock signal
goes to 1. Write a VHDL file that defines the D flip-flop circuit. Implement your circuit on
the DE2 board and test its functionality by operating the implemented switches.
D
Q
(c) Symbol
Figure 1: A D flip-flop
PART II
The JK flip-flop is the most versatile of the basic flip-flops. It has the input-
following character of the clocked D flip-flop but has two inputs, traditionally labeled J
and K. If J and K are different then the output Q takes the value of J at the next clock
edge. A JK flip-flop has two inputs J and K. If J and K are both low then no change
occurs. If J and K are both high at the clock edge then the output will toggle from one
state to the other. Write a VHDL file that defines the JK flip-flop circuit. Implement your
66
circuit on the DE2 board and test its functionality by operating the implemented
switches.
J K Q(t+1)
0 0 Q(t)
0 1 0
1 0 1
1 1 Q(t)
(c) Symbol
Figure 2: A JK flip-flop
PART III
The SR flip-flop is a circuit with two cross coupled NOR gates or two cross-
coupled NAND gates, and two inputs labeled S for set and R for reset. The SR latch
constructed with two cross-coupled NAND gate with clock input is shown in Figure 3.
The clock input (Clk) acts as an enable signal for other two inputs. The outputs of the
NAND gates stay at logic-1 level as long as the clock input remains at 0. When the
clock input goes to 1, information from the S or R input is allowed to affect the latch. The
set state is reached with S = 1, R = 0, and Clk = 1. To change this reset state, the inputs
must be S = 0, R = 1, and Clk = 1. Write a VHDL file that defines the SR flip-flop circuit.
Implement your circuit on the DE2 board and test its functionality by operating the
implemented switches.
Clk S R Next state of Q
0 x x No Change
1 0 0 No Change
1 0 1 Q = 0; reset state
1 1 0 Q = 1; set state
1 1 1 Indeterminate
(a) Characteristic Table
67
S
Q
Clk
~Q
R
Figure 3: A SR flip-flop
Part IV
The T (toggle) flip-flop is a single input flip-flop. It has two outputs which are Q
and Q‟. Write a VHDL file that defines the T flip-flop circuit. Implement your circuit on the
DE2 board and test its functionality by operating the implemented switches.
T Q(t+1)
0 Q(t) No Change
1 Q'(t) Complement
(b) Symbol
68
References
A. Books
Stephen Brown and Zvonko Vranesic, “Fundamental of Digital Logic with VHDL
Design”, 2nd edition, 2005
B. Internet Materials
69