Intro Quartus Verilog v3
Intro Quartus Verilog v3
2
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
The objective of the following exercises is to build an 8 X 8 multiplier. The input to the multiplier consists
of two 8-bit multiplicands (a[7..0], b[7..0]) and the output from the multiplier is a 16-bit result
(result[15..0]). Additional outputs are a done bit (DONE_FLAG) and seven signals to drive a seven
segment display, (A,B,C,D,E,F,G).
There are several methods of implementing a multiplier, the method chosen for the Verilog labs is the
sequential multiplier method. This 8 X 8 multiplier requires four clock cycles to perform the full
multiplication. During each cycle, a pair of 4-bit portion of the multiplicands are multiplied in a 4 X 4
multiplier. The multiplication result of these 4 bit slices are then accumulated. At the end of the four
cycles, the full composed 16-bit result can be read at the output.
The following equations illustrate the mathematical principles supporting this implementation:
= ( ( a[7..4] * 2 ^ 4) + a[3..0] * 2 ^ 0 )
* ( ( b[7..4] * 2 ^ 4) + b[3..0] * 2 ^ 0 )
= ( ( a[7..4] * b[7..4] ) * 2 ^ 8 )
+ ( ( a[7..4] * b[3..0] ) * 2 ^ 4 )
+ ( ( a[3..0] * b[7..4] ) * 2 ^ 4 )
+ ( ( a[3..0] * b[3..0] ) * 2 ^ 0 )
Figure 1 in the following page illustrates the top level block diagram of the 8 X 8 multiplier.
The labs are structured as a bottom-up design approach. In each of the first four exercises, you will use
targeted features of the Verilog language to build the individual components of the 8 X 8 multiplier. Then,
in exercise five you will put everything together in a top level design. You will then compile and simulate
to verify the completeness of your design.
Important: Please use lower case alphabet letters for your source codes.
3
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
4
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Exercise 1
5
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Exercise 1
Part A
Figure 1-1.
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select the New Project Wizard from the File menu. The first time you open the New Project Wizard,
it shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step1.
3. Type a name for the project in the project name box. For this lab, type adder.
4. Type adder as the name of the top-level design entity of the project in the top-level design entry box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the adder source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (adder) in
the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
HDL File then click OK.
6
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
Figure 1-2.
7
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (Adder.vwf which is given
to you.).
Figure 1-3.
8
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
4. Click on Apply.
5. In the Simulator Settings Dialog Box, click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
Figure 1-4.
6. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
7. Check to see if you get the same results as shown in Figure 1-5.
9
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 1-5.
10
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Part B
Figure 1-6.
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select the New Project Wizard from the File menu. The first time you open the New Project Wizard,
it shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step1.
3. Type a name for the project in the project name box. For this lab, type mult4x4.
4. Type mult4x4 as the name of the top-level design entity of the project in the top-level design entry
box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the multiplier source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (mult4x4)
in the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
11
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
Figure 1-7.
12
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (mult4x4.vwf which is
given to you.).
Figure 1-8.
13
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
4. Click on Apply.
5. In the Simulator Settings Dialog Box, click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
Figure 1-9.
6. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
7. Check to see if you get the same results as shown in Figure 1-10.
14
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 1-10.
15
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
16
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Exercise 2
17
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Exercise 2
PART A
Objective: Build a four-input 2:1 multiplexer using IF-THEN statement.
The input to the multiplexer consists of two 4-bit data buses (a[3..0] and b[3..0]). The output (y[3..0]) is
a[3..0] if the select control (sel) is low (0). The output is b[3..0] if sel is high (1).
The four-input 2:1 multiplexer will be used in the top level design for selecting the 4-bit slices a[7..4],
a[3..0], b[7..4], and b[3..0] as inputs to the 4 X 4 multiplier.
Figure 2-1.
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select New Project Wizard from the File menu. The first time you open the New Project Wizard, it
shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step 1.
3. Type a name for the project in the project name box. For this lab, type mux4.
18
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
4. Type mux4 as the name of the top-level design entity of the project in the top-level design entry box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the mux4 source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (mux4) in
the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu select New or click on . The New file dialog box will appear; select Verilog
19
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
Figure 2-2.
2. Click OK to close the Compiler Settings Dialog Box.
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
20
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (mux4.vwf which is given
to you.).
4. Click on Apply.
Figure 2-3.
5. In the Simulator Settings Dialog Box, click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
21
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 2-4.
6. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
7. Check to see if you get the same results as shown in Figure 2-5.
22
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 2-5.
23
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Part B
In this exercise, you will build an 8-bit to 16-bit shifter using IF-ELSE statements and the shift-left operator
(<<). This shifter will be capable of performing three types of shifter operations: no shift, left shift by 4 bit
positions, and left shift by 8 bit positions.
The input to the shifter consists of a single 8-bit data bus (in[7:0]). The shift operation is controlled by the
control signal cnt[1:0].
This 8-bit to 16-bit shifter will be used to perform the * 2 ^ 0 (no shift), * 2 ^ 4 (left shift by 4 bit positions),
and * 2 ^ 8 (left shift by 8 bit positions) operations of the following equation:
= ( ( a[7:4] * 2 ^ 4) + a[3:0] * 2 ^ 0 )
* ( ( b[7:4] * 2 ^ 4) + b[3:0] * 2 ^ 0 )
= ( ( a[7:4] * b[7:4] ) * 2 ^ 8 )
+ ( ( a[7:4] * b[3:0] ) * 2 ^ 4 )
+ ( ( a[3:0] * b[7:4] ) * 2 ^ 4 )
+ ( ( a[3:0] * b[3:0] ) * 2 ^ 0 )
Figure 2-6.
24
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select New Project Wizard from File menu. The first time you open the New Project Wizard, it shows
the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step 1.
3. Type a name for the project in the project name box. For this lab, type shifter.
4. Type shifter as the name of the top-level design entity of the project in the top-level design entry box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the shifter source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (shifter)
in the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
25
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
Figure 2-7.
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
26
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (shifter.vwf which is given
to you.).
Figure 2-8.
4. Click on Apply.
5. In the Simulator Settings Dialog Box, Click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
27
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 2-9.
6. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
7. Check to see if you get the same results as shown in Figure 2-10.
28
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 2-10.
29
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
30
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Exercise 3
31
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Exercise 3
INPUTS OUTPUTS
INP2 INP1 INP0 a b c d e f g DISPLAY
0 0 0 1 1 1 1 1 1 0 0
0 0 1 0 1 1 0 0 0 0 1
0 1 0 1 1 0 1 1 0 1 2
0 1 1 1 1 1 1 0 0 1 3
1 X X 1 0 0 1 1 1 1 E
Figure 3-1.
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select the New Project Wizard from the File menu. The first time you open the New Project Wizard,
it shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step 1.
3. Type a name for the project in the project name box. For this lab, type seven.
4. Type seven as the name of the top-level design entity of the project in the top-level design entry box.
5. Click Next. The second page of the New Project Wizard appears.
32
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
6. At this point, there is no file to add because we will create the seven source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (seven) in
the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
33
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 3-2.
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (seven.vwf which is given
to you.).
34
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 3-3.
4. In the Simulator Settings Dialog Box, click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
35
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 3-4.
5. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
6. Check to see if you get the same results as shown in Figure 3-5.
36
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 3-5.
37
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
38
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Exercise 4
39
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Exercise 4
Part A
Functionality of the 16-bit register:
If clr=’1’ AND clken=’0’, then in_reg will be loaded into register at the rising edge of clock.
Otherwise, if clr=’0’, then the register is cleared at the rising edge of clock.
Note: This is a synchronous clear and clock enable register. Therefore, the IF-THEN
that checks for clear and clock enable should be inside the IF-THEN statement that
checks for the clock condition.
Figure 4-1.
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select the New Project Wizard from the File menu. The first time you open the New Project Wizard,
it shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step 1.
40
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
3. Type a name for the project in the project name box. For this lab, type reg16.
4. Type reg16 as the name of the top-level design entity of the project in the top-level design entry box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the reg16 source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (reg16) in
the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
41
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 4-2.
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
42
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (reg16.vwf which is given
to you.).
Figure 4-3.
4. Click on Apply.
5. In the Simulator Settings Dialog Box, click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
43
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 4-4
6. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
7. Check to see if you get the same results as shown in Figure 4-5
44
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 4-5.
Step 6 (Close the simulation waveform)
1. Close the Simulation Waveform window.
2. Switch back to the Compile Mode
45
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Part B
The 2-bit counter can be constructed using the +1 operation. It is used to help the state machine track the
cycles of the sequential multiplication.
Figure 4-6.
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select the New Project Wizard from the File menu. The first time you open the New Project Wizard,
it shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name r select the directory with Browse . The directory name has been
provided by the instructor in step 1.
3. Type a name for the project in the project name box. For this lab, type counter.
4. Type counter as the name of the top-level design entity of the project in the top-level design entry box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the counter source file.
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (counter)
in the Compilation Hierarchies tab of the Project Navigator window.
46
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
47
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 4-7.
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
48
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (counter.vwf which is
given to you.).
Figure 4-8.
4. In the Simulator Settings Dialog Box. Click on Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
49
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 4-9.
5. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete.
6. Check to see if you get the same results as shown in Figure 4-10.
50
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 4-10.
51
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
52
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Exercise 5
53
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Exercise 5
Part A
You have now completed building all of the components necessary to build the 8x8 multiplier, except for
the controlling state machine and the 4x4 multiplier (Part B). Due to time constraints, the controlling state
machine has been written for you and is located in <pathname>\verilog\lab5a\control.v.
This state machine will manage all the operation that occurs within the 8x8 multiplier.
The state machine will perform the ( (a[3..0] * b[3..0] ) * 2 ^ 0 ) multiplication in the first cycle (LSB state)
after the input signal start becomes a ‘1’. This intermediate result is saved in an accumulator.
In the second clock cycle (MID state), the ( ( a[3..0] * b[7..4] ) * 2 ^ 4 ) multiplication is performed. The
multiplication result is added with the content of the accumulator and clocked back into the accumulator.
In the third clock cycle (MID state), the ( ( a[7..4] * b[3..0] ) * 2 ^ 4 ) multiplication is performed. The
multiplication result is added with the content of the accumulator and clocked back into the accumulator.
In the fourth clock cycle (MSB state), the ( (a[7..4] * b[7..4] ) * 2 ^ 8 ) multiplication is performed. The
multiplication result is added with the content of the accumulator and clocked back into the accumulator.
This result is the final result:
= ( ( a[7..4] * b[7..4] ) * 2 ^ 8 )
+ ( ( a[7..4] * b[3..0] ) * 2 ^ 4 )
+ ( ( a[3..0] * b[7..4] ) * 2 ^ 4 )
+ ( ( a[3..0] * b[3..0] ) * 2 ^ 0 )
NOTE: There are two inputs to the state machine start and count[1..0]. The start signal is a single cycle
high-true signal. When start becomes a ‘1’, it indicates that multiplication can begin at next clock cycle.
The start signal can only be asserted for one clock cycle. The start signal shall stay a ‘0’ until next 8x8
multiplication is to be performed. The count[1..0] signal is the output of a free running 2-bit counter. The
count[1..0] signal is synchronously initialized by the start signal. Count[1..0] is used by the state machine
to track the cycles of the multiplication.
Please also note that this is NOT the optimal design. The state machine design as you see it is intended for
exercising your Verilog skills and not the ability to perform optimum solution.
54
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 5-1.
START=0
COUNT=X
---------------
in_sel[1..0]=X
shif[1..0]=x
done=0
clken=1
regclr=1
IDLE
START=0 state_out[2..0]=000
COUNT=3 START=1
--------------- COUNT=X
in_sel[1..0]=3 ---------------
shif[1..0]=2 in_sel[1..0]=X
START=1
done=1 shif[1..0]=x
COUNT=x
clken=0 done=0
---------------
regclr=1 in_sel[1..0]=x clken=1
regclr=0
shif[1..0]=x
others done=0
--------------- clken=1
in_sel[1..0]=x regclr=0
shif[1..0]=x
done=0
clken=1
regclr=1 others
ERR ---------------
state_out[2..0]=100 in_sel[1..0]=x
shif[1..0]=x LSB
MSB done=0 state_out[2..0]=001
state_out[2..0]=011 clken=1
others
--------------- regclr=1
in_sel[1..0]=x
shif[1..0]=x others
done=0 ---------------
clken=1 in_sel[1..0]=x
regclr=1 shif[1..0]=x
done=0 START=0
clken=1 COUNT=0
START=0 regclr=1 ---------------
COUNT=2 in_sel[1..0]=0
--------------- shif[1..0]=0
in_sel[1..0]=2 done=0
shif[1..0]=1 clken=0
done=0 regclr=1
clken=0 MID
regclr=1 state_out[2..0]=010
START=0
COUNT=1
---------------
in_sel[1..0]=1
shif[1..0]=1
done=0
clken=0
regclr=1
55
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Part B
You have now completed building all of the components necessary to build the 8x8 multiplier.
Making use of the knowledge you have gained up to this point, you should instantiate each component in a
top-level design and connect all signal as shown in Figure 5-2. You have successfully completed the
Introduction to Verilog class once your top-level design is compiled and simulated correctly.
Congratulations!
= ( ( a[7..4] * b[7..4] ) * 2 ^ 8 )
+ ( ( a[7..4] * b[3..0] ) * 2 ^ 4 )
+ ( ( a[3..0] * b[7..4] ) * 2 ^ 4 )
+ ( ( a[3..0] * b[3..0] ) * 2 ^ 0 )
56
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 5-2.
57
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
1. <pathname> is________________________________
Step 2 (Create new project and open Verilog text editor file)
Create a project by using the New Project Wizard. To create a project using the New Project Wizard, please
follow the following steps:
1. Select the New Project Wizard from the File menu. The first time you open the New Project Wizard,
it shows the introduction page; you can click Next to proceed to the first page of the wizard.
2. Type the directory name or select the directory with Browse . The directory name has been
provided by the instructor in step 1.
3. Type a name for the project in the project name box. For this lab, type mult8x8.
4. Type mult8x8 as the name of the top-level design entity of the project in the top-level design entry
box.
5. Click Next. The second page of the New Project Wizard appears.
6. At this point, there is no file to add because we will create the mult8x8 source file
7. Click Next. The summary page appears. The summary page gives information about your project.
8. Click Finish. You have just finished the project creation. You should see the top-level entity (mult8x8)
in the Compilation Hierarchies tab of the Project Navigator window.
9. From the File menu, select New or click on . The New file dialog box will appear; select Verilog
58
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
13. The lower-level components have been created in different directories than the current directory. In
order for Quartus to find these lower-level components, it must have a search path. Therefore, you
must do the following:
Go to the Project menu and Choose General Settings. From General Settings Choose User
1. From the Processing menu select Compiler Settings. In the dialog box select the Mode tab and Click on
Netlist extraction and synthesis only, including estimated timing. Leave other settings as defaults.
59
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 5-3.
3. From the Processing menu, Select Start Compilation or Click on . Click OK when synthesis is
complete.
1. The stimulus file has been created for you to verify the functionality of your design. If you are
interested in learning how to create your own stimulus file, please go to the Appendix of this manual.
2. From the Processing menu, Select Simulate Mode or Click on from toolbar.
3. From the Processing menu, Select Simulator Settings. Once the Simulator Settings Dialog Box has
appeared, Click on the Time/Vectors tab to browse to the vector stimuli file (mult8x8.vwf which is
given to you).
60
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 5-4.
4. Click on Apply.
5. In the Simulator Settings Dialog Box, click on the Mode tab. Change the simulation mode to be
Functional. Click OK to close the Simulator Settings Dialog Box.
61
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
Figure 5-5.
6. From the Processing menu Select Run Simulation or Click on . Click OK when the simulation is
complete
7. Check to see if you get the same results as shown in Figure 5-6.
62
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
Figure 5-6.
63
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
64
Copyright © 2001 Altera Corporation
Introduction to Verilog Exercises
APPENDIX
65
Copyright © 2001 Altera Corporation
Exercises Introduction to Verilog
3. Click OK.
4. Enter nodes into the waveform file. Insert menu -> Enter Node or Bus
5. Set the inputs to the appropriate values.
6. Save the file.
66
Copyright © 2001 Altera Corporation