Lab 8
Lab 8
Seven-Segment Display
ENEE 245: Digital Circuits and Systems Laboratory
Lab 8
Objectives
The objectives of this laboratory are the following:
To design a circuit using decoders and multiplexers that drives the seven-segment displays on
the Nexys2 board
The Nexys2 board uses the common anode method for its displays. This means that all the anodes
are tied together and connected through a pnp transistor to +3.3V, as shown in Figure 7.3. A
dierent FPGA output pin is connected through a 100 current-limiting resistor to each of the
cathodes, a g, plus the decimal point. A control signal of 0 will turn on an LED segment and a
signal of 1 will turn it o. A hex-to-7-segment decoder takes a 4-bit input (a Hex digit) and
generates the corresponding 8-bit pattern to light the appropriate LED segments in the display.
The table below shows output cathode values for each segment a g needed to display all hex values
from 0 F.
x
a b c d e f g
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0
1
0
0
1
0
0
0
0
0
0
1
0
1
0
0
0
0
0
0
0
1
1
0
0
0
0
1
1
0
1
1
0
0
1
0
0
0
0
0
0
0
0
0
1
0
1
1
0
1
0
0
1
0
0
1
0
0
1
0
0
0
0
1
0
1
0
1
1
1
0
1
0
1
0
0
0
0
0
0
0
1
1
1
0
0
0
1
0
0
0
0
0
1
0
0
1
1
0
0
0
0
0
1
0
0
0
0
1
0
0
0
1 = off
0 = on
You can similarly develop equations for the other six segments and then write the Verilog program
for the 7-segment decoder.
Clock Converter
To sequence through the display anodes, you will need to have a clock in your design. The Nexys-2
board has an onboard 50 MHz clock. This 50 MHz clock signal is a square wave with a period of 20
ns. This clock signal is too fast for this application, so you will need to down convert that clock for
this lab. For example, you can down convert the 50 MHz clock to 1 KHz. can be used to create an
N-bit counter, whose block diagram is shown in the figure below.
4
The following Verilog program can be used to generate this counter. Note that the sensitivity list of
the always statement contains the phrase posedge clk or posedge clr. This means that the if
statement within the always block will execute whenever either clr or clk goes high. If clr goes high
then the output q[N-1:0] will go to zero. On the other hand, if clr = 0 and clk goes high, then the
output q[N-1:0] will be incremented by 1. The default value of the parameter N in this code is 4. A
simulation of this 4-bit counter is shown in the figure below the code. Note that this counter counts
from 0 to F and then wraps around to 0.
// Example N-bit counter
module counter
#(parameter N = 4)
(input wire clr ,
input wire clk ,
output reg [N-1:0] q
);
// N-bit counter
always @(posedge clk or posedge clr)
begin
if (clr == 1)
q <= 0;
else
q <= q + 1;
end
endmodule
In these simulation results, note that the output q[0] is a square wave at half the frequency of the
input clk. Similarly, the output q[1] is a square wave at half the frequency of the input q[0], the
output q[2] is a square wave at half the frequency of the input q[1], and the output q[3] is a square
wave at half the frequency of the input q[2]. Note also that the binary numbers q[3:0] count from
0000 to 1111.
You can instantiate larger counters such as a 24-bit counter, for instance, that would count from 0 to
224 1 by using an instantiation statement such as the following:
counter #(.N(24))
cnt24 (.clr(clr),
.clk(clk),
.q(q)
);
Thus, a counter can be used to divide the frequency f of a clock, where the frequency of the output
q(i) is fi = f / 2i+1. This shows one way you can obtain a lower clock frequency by simply using one of
the outputs q[i]. For instance, the output q[0] will have a frequency of 25 MHz, the output q[17]
will have a frequency of 190.73 Hz, and the output q[23] will have a frequency of 2.98 Hz.
Anode Driver Unit
Using the clock signal, you need to develop a system that time-multiplexes among signals AN3-AN0
as depicted earlier. This will require using some sequential logic elements. The figure below shows a
block, which provides the desired signals described beneath it.
During each clock period only one of the outputs (AN3-AN0) is activated and O_1, O_0
corresponds to the active signal 00, 01, 10 or 11. The sequence O_1, O_0 can be generated by a 2bit counter that counts input clock tics. Thus, the output of a 2-bit counter cycles from 00 to 11,
incrementing the count with each clock tic. After O_1O_0 = 11 is generated on the fourth clock
cycle, the count will rollover back to 00 and continue. To generate the individual anode control
signals AN0-AN3, you can use a 2-to-4 decoder with O_1, O_0 as the inputs. However, remember
that AN0-AN3 need to be active LOW outputs.
Pre-Lab Preparation
Part 1: Reading
Read pages 4-6 in the Nexys2 Board Reference Manual available at http://www.digilentinc.com/
Data/Products/NEXYS2/Nexys2_rm.pdf
Part 2: Hex-to-7-Segment Decoder Using Continuous Assignment
1. Design a hex-to-7-segment decoder, with x[3-0] as input.
2. Define Inputs and Outputs. Draw a block diagram of the circuit showing the inputs and outputs
for the circuit.
3. Draw a truth-table that shows the 4 inputs and the 7 outputs.
4. Create Verilog code using continuous assignment statements.
5. Functional Simulation. Perform a functional simulation of the circuit to verify that it is working
correctly.
6. Create Symbol. Create a symbol for the hex7seg to use in the graphical editor. This creates a
symbol file that is a Graphic File and can be viewed and edited by opening it.
Part 3: Hex-to-7-Segment Decoder Using Case Statement
7. Design a hex-to-7-segment decoder using the Verilog case statement.
8. Perform a functional simulation of the circuit. Paste the results in your prelab report.
9. Create Symbol. Create a symbol for the hex7seg to use in the graphical editor.
10. Bring your Verilog codes in a flash drive.
Part 4: Multiple Digits Display
11. Design a clock converter that converts the 50 MHz clock to a 1 KHz clock.
12. Design an anode driver unit that generates the anode driver signals.
13. Design a 4-digit seven-segment controller.
Pre-Lab Report
In your prelab report, include the following:
Truth Table, circuit schematic, Verilog program, and simulation results for the hex-to-7-segment
decoder using continuous assignments, with all possible values of inputs x[3-0].
Truth Table, circuit schematic, Verilog program, and simulation results for the hex-to-7-segment
decoder with case statement, with all possible values of inputs x[3-0].
Circuit schematic, Verilog program, and simulation results for the anode signals.
Incorrect or incomplete designs and Verilog programs will not receive full credit. If you have any
problems with Verilog syntax and other pre-lab related issues, please resolve them before coming to
the lab. Your TA may not be able to help you with these issues during the lab session.
In-Lab Procedure
Bring flash drives to store your data.
Ask the TA questions regarding any procedures about which you are uncertain.
Implement the complete design (synthesize, map, and Place & Route) of your two designs using the
Xilinx ISE tools. Program the FPGA using the bit-stream file which is generated in the process. For
checko, you will show the TA the following:
1. Show the two designs working on the board.
2. Demonstrate at least one input pattern you have used in the test bench. Show that your
simulation results above match the observed waveforms on the DLA.
3. Demonstrate your 4-digit display to your TA with the clock at 1 KHz.
Post-Lab Report
Write up your code, schematics, and lab procedures. Demonstrate the correctness of your designs
through your pre-lab simulations and note any dierences between what you simulated and how the
circuits behaved in the lab.