Lab1 Verilog
Lab1 Verilog
Lab1 Verilog
The purpose of this exercise is to learn how to connect simple input and output devices to an FPGA chip and
implement a circuit that uses these devices. We will use the switches SW90 on the DE1 board as inputs to the
circuit. We will use light emitting diodes (LEDs) and 7-segment displays as output devices.
Part I
The DE1 board provides 10 toggle switches, called SW90 , that can be used as inputs to a circuit, and 10 red
lights, called LEDR90 , that can be used to display output values. Figure 1 shows a simple Verilog module that
uses these switches and shows their states on the LEDs. Since there are 10 switches and lights it is convenient to
represent them as vectors in the Verilog code, as shown. We have used a single assignment statement for all 10
LEDR outputs, which is equivalent to the individual assignments
assign LEDR[9] = SW[9];
assign LEDR[8] = SW[8];
...
assign LEDR[0] = SW[0];
The DE1 board has hardwired connections between its FPGA chip and the switches and lights. To use SW90 and
LEDR90 it is necessary to include in your Quartus II project the correct pin assignments, which are given in the
DE1 User Manual. For example, the manual specifies that SW0 is connected to the FPGA pin L22 and LEDR0 is
connected to pin R20. A good way to make the required pin assignments is to import into the Quartus II software
the file called DE1_pin_assignments.qsf, which is provided on the DE1 System CD and in the University Program
section of Alteras web site. The procedure for making pin assignments is described in the tutorial Quartus II
Introduction using Verilog Design, which is also available from Altera.
It is important to realize that the pin assignments in the DE1_pin_assignments.qsf file are useful only if the
pin names given in the file are exactly the same as the port names used in your Verilog module. The file uses the
names SW[0] . . . SW[9] and LEDR[0] . . . LEDR[9] for the switches and lights, which is the reason we used these
names in Figure 1.
3. Include in your project the required pin assignments for the DE1 board, as discussed above. Compile the
project.
4. Download the compiled circuit into the FPGA chip. Test the functionality of the circuit by toggling the
switches and observing the LEDs.
Part II
2a shows a sum-of-products circuit that implements a 2-to-1 multiplexer with a select input s. If s = 0 the
multiplexers output m is equal to the input x, and if s = 1 the output is equal to y. Part b of the figure gives a
truth table for this multiplexer, and part c shows its circuit symbol.
x
m
s
y
a) Circuit
s
s
0
1
x
y
x
y
b) Truth table
0
1
c) Symbol
x3
y3
x2
y2
m3
m2
X
Y
x0
y0
0
1
4
0
1
4
m0
a) Circuit
b) Symbol
s1
s0
u
v
a) Circuit
s1
s1 s0
0
0
1
1
u
v
w
w
0
1
0
1
s0
u
v
w
b) Truth table
00
01
10
c) Symbol
s1
s0
U
2
2
V
W
00
01
10
Perform the following steps to implement the two-bit wide 3-to-1 multiplexer.
1. Create a new Quartus II project for your circuit.
2. Create a Verilog module for the two-bit wide 3-to-1 multiplexer. Connect its select inputs to switches
SW98 , and use switches SW50 to provide the three 2-bit inputs U to W . Connect the SW switches to the
red lights LEDR and connect the output M to the green lights LEDG10 .
3. Include in your project the required pin assignments for the DE1 board. Compile the project.
4. Download the compiled circuit into the FPGA chip. Test the functionality of the two-bit wide 3-to-1 multiplexer by toggling the switches and observing the LEDs. Ensure that each of the inputs U to W can be
properly selected as the output M .
Part IV
Figure 6 shows a 7-segment decoder module that has the two-bit input c1 c0 . This decoder produces seven outputs
that are used to display a character on a 7-segment display. Table 1 lists the characters that should be displayed for
each valuation of c1 c0 . To keep the design simple, only three characters are included in the table (plus the blank
character, which is selected for codes 11).
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 Verilog module that implements logic functions
that represent circuits needed to activate each of the seven segments. Use only simple Verilog assign statements
in your code to specify each logic function using a Boolean expression.
0
c1
c0
5
7-segment
decoder
2
3
c1 c0
Character
00
01
10
11
d
E
1
SW 9
SW 8
SW 5 4
SW 3 2
SW 1 0
0
00
01
10
7-segment
decoder
1
2
Figure 7. A circuit that can select and display one of three characters.
SW9 SW8
00
01
10
Character pattern
d
E
1
E
1
d
1
d
E
4. Download the compiled circuit into the FPGA chip. Test the functionality of the circuit by setting the proper
character codes on the switches SW50 and then toggling SW98 to observe the rotation of the characters.
Part VI
mo rong
Extend your design from Part V so that is uses all four 7-segment displays on the DE1 board. Your circuit should
be able to display words with three (or fewer) characters on the four displays, and rotate the displayed word when
the switches SW98 are toggled. If the displayed word is dE1, then your circuit should produce the patterns shown
in Table 3.
SW9 SW8
00
01
10
11
Character pattern
d
E
1
d
E
1
E
1
d
1
d
E
c
Copyright
2011
Altera Corporation.