Fpga Design Tutor
Fpga Design Tutor
12 Tutorial
December 9, 2021
Copyright
Copyright © 2021 Lattice Semiconductor Corporation. All rights reserved. This
document may not, in whole or part, be reproduced, modified, distributed, or publicly
displayed without prior written consent from Lattice Semiconductor Corporation
(“Lattice”).
Trademarks
All Lattice trademarks are as listed at www.latticesemi.com/legal. Synopsys and
Synplify Pro are trademarks of Synopsys, Inc. Aldec and Active-HDL are trademarks
of Aldec, Inc. Modelsim and Questa are trademarks or registered trademarks of
Siemens Industry Software Inc. or its subsidiaries in the United States or other
countries. All other trademarks are the property of their respective owners.
Disclaimers
NO WARRANTIES: THE INFORMATION PROVIDED IN THIS DOCUMENT IS “AS IS”
WITHOUT ANY EXPRESS OR IMPLIED WARRANTY OF ANY KIND INCLUDING
WARRANTIES OF ACCURACY, COMPLETENESS, MERCHANTABILITY,
NONINFRINGEMENT OF INTELLECTUAL PROPERTY, OR FITNESS FOR ANY
PARTICULAR PURPOSE. IN NO EVENT WILL LATTICE OR ITS SUPPLIERS BE
LIABLE FOR ANY DAMAGES WHATSOEVER (WHETHER DIRECT, INDIRECT,
SPECIAL, INCIDENTAL, OR CONSEQUENTIAL, INCLUDING, WITHOUT
LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION, OR
LOSS OF INFORMATION) ARISING OUT OF THE USE OF OR INABILITY TO USE
THE INFORMATION PROVIDED IN THIS DOCUMENT, EVEN IF LATTICE HAS
BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. BECAUSE SOME
JURISDICTIONS PROHIBIT THE EXCLUSION OR LIMITATION OF CERTAIN
LIABILITY, SOME OF THE ABOVE LIMITATIONS MAY NOT APPLY TO YOU.
Bold Items in the user interface that you select or click. Text that you type
into the user interface.
Courier Code examples. Messages, reports, and prompts from the software.
Revision History 46
This tutorial leads you through all the basic steps of designing and
implementing a mixed VHDL and Verilog design targeted to the MachXO3L
device family. It shows you how to use several processes, tools, and reports
from the Lattice Diamond™ software to import sources, run design analysis,
view design hierarchy, and inspect strategy settings. The tutorial then
proceeds to step through the processes of examining the device resources,
setting timing and location assignments, programming the device, and adding
a logic analyzer to the design.
You can stop at the end of any task and restart at the beginning of the next
task. When you restart the Diamond software, it shows a Recent Projects list.
Just click the name of your project.
Online Help You can find additional information on any tool included in the
tutorial at any time by choosing Help > Lattice Diamond Help or Help >
<tool name>. The Help also provides easy access to many other information
sources.
About the Tutorial Design The design in this tutorial consists of four
Verilog HDL modules and two VHDL modules. The design that you create is
targeted to the MachXO3L device family.
Figure 1 illustrates the tutorial data flow through the system. You may find it
helpful to refer to this diagram as you move through the tutorial tasks.
Create Project
Inspect Strategy
Settings
Translate and
Map Design
Improve Hardware
Reveal Inserter/Analyzer
Note
Some of the screen captures in this tutorial may have been taken from a version of
Lattice Diamond that differs from the one you are using. There may be slight
differences in the graphical user interface (GUI), but the software functions the same.
The initial layout provides the Start Page, which provides a list of common
project actions like Open to open a pre-existing project and New to run the
New Project wizard. Links in the right pane of the Start Page provide
access to user guides, reference material, and online resources available
from www.latticesemi.com.
For almost all questions, the place to start is Lattice Diamond’s online
Help. It describes the FPGA design flow using Diamond, the libraries of
logic design elements, and the details of the Diamond design tools. The
Help also provides easy access to many other information sources. The
Help can be accessed from Help > Lattice Diamond Help.
2. Open a new project in one of the following ways:
In the Start Page, under Project, click New.
Choose File > New > Project.
In the toolbar, click the down arrow in the New button and then
choose Project.
The New Project wizard opens.
3. Click Next.
The Project Name page opens.
4. Specify the project name: LEDtest.
Note
File names for Diamond projects and project source files must start with a
letter (A-Z, a-z) and must contain only alphanumeric characters (A-Z, a-z,
0-9) and underscores (_).
5. Click Browse. In the Project Location dialog box, browse to where you
want to store the project’s files, such as C:/my_diamond_tutorial, as
shown in Figure 3. Click Select Folder.
6. Specify the implementation name: LEDtest.
The directory to store the implementation is automatically displayed in the
Location box. We will talk about creating a new implementation later in
this tutorial.
7. Click Next.
The Add Source dialog box appears.
8. Click Add Source.
The Import File dialog box appears.
9. Browse to: <diamond_install_directory>/docs/tutorial/Diamond_tutorial.
10. Select the following files (Control+A will do it):
count8.vhd
count32.v
testbench.v
topcount.v
typepackage.vhd
and click Open.
The Add Source step of the Wizard appears with all the selected source
files added.
11. Select Copy source to implementation directory.
12. Click Next.
The Device Selector dialog box appears.
13. Select the following device options:
Family: MachXO3L
Device: LCMXO3L-6900C
Performance grade: 5
Package type: CABGA256
Operating conditions: Commercial
Note
You can also see Area, I/O Assistant, Quick, and Timing listed in the Strategies
folder in the File List view. These are predefined strategies supplied by Lattice
Semiconductor that solve particular design requirements. For details of these
predefined strategies, refer to the Diamond Help.
When you create a new project in Diamond, a logical preference file (.lpf)
is automatically generated and assigned the same name as the FPGA
project.
For this tutorial a logical preference file named pin_assignments.lpf is
provided and contains all the pin assignments needed to program this
design project onto the MachXO3L FPGA. All changes that you make to
logical constraints will be saved in this file until you create a new logical
preference file or add another existing one.
18. In the File List, right-click LPF Constraint Files and choose Add >
Existing File.
The Add Existing File dialog box appears.
19. Navigate to <diamond_install_directory>/docs/tutorial/Diamond_tutorial
and select pin_assignments.lpf. Select Copy file to Implementation’s
Source directory and click Add.
20. In the File List view, right-click pin_assignments.lpf and choose Set as
Active Preference File.
21. Under Input Files, right-click testbench.v and choose Include for >
Simulation.
The Process view, shown in Figure 5, lists all the processes available, such
as Synthesize Design, Translate Design, Map Design, Place & Route Design,
and Export Files.
The Reports view allows you to examine and print process reports. There are
two panes in the Reports view. The left pane lists the reports. The right pane
displays the reports.
Log messages are displayed in the Output frame of the Diamond main
window.
In this task, you will generate a phase lock loop (PLL) module to import into
your design.
4. Click Customize.
The Lattice FPGA Module -- PLL dialog box appears.
5. In the Configuration tab:
Select Frequency Mode.
For CLKI Frequency, enter 20.
For CLKOP Desired Frequency, enter 80.
For CLKOP Tolerance, choose 1.0.
Select Provide PLL Lock signal.
6. Click Calculate.
7. Select Import IPX to Diamond project.
8. Click Generate.
The IPexpress .ipx file is generated.
9. The Generated Log tab appears, as shown in Figure 7.
In this tutorial we will just do the RTL simulation. For the other stages, the
process is similar.
For a simulator, this tutorial uses the Mentor® ModelSim® Lattice FPGA
Edition simulator that comes with Diamond on Windows.
If you are not using an HDL simulator that is integrated with Diamond, you can
skip this task. “Integrated” means that you can run the simulator from
Diamond. What is available depends on your operating system. You can use
other simulators outside of Diamond.
If you are not using the ModelSim that comes with Diamond, you need to
compile the primitive library. For instructions, open the Diamond Help and see
User Guides > Simulating the Design > Third-Party Simulators.
This tutorial comes with a simple testbench. You will probably create your own
testbenches using your simulator. Simulators usually include tools for creating
testbenches.
You can rerun the simulation by double-clicking the .spf file. The Simulation
Wizard will open with a Skip to End button. Click it to jump to the last page of
the wizard. Then click Finish to start the simulation running.
Now that you’ve run the simulation, you can see what happened on the top-
level signals of the testbench as shown in Figure 8. ModelSim stopped
automatically after the first microsecond of simulation time. The testbench is
set to run longer, over 5 µs, but this is enough to see the startup.
5. Choose Wave > Zoom > Zoom Full or click the Zoom Full button in
the toolbar to see the whole waveform. The Zoom toolbar looks like this:
In the Wave view, you see the reset signal activated by the testbench.
After reset is released, count2 and count3 start counting up.
6. The values of count2 may not be visible. Click the Zoom In button in
the toolbar until you can see the values.
7. Choose Simulate > Run > Run 100 or click the Run button to see
more of the simulation. The Run toolbar looks like this:
Another 100 ns is added to the waveforms. This is the time you set in the
Runtime Options dialog box. You can change this amount in the box next
to the Run button.
8. Click anywhere to see what the values are at that moment.
The nearest cursor (a vertical yellow line) jumps to where you clicked. The
value column shows all the values at that moment.
You can click on the cursor and drag it to other positions on the timeline.
You can also return to the cursor after scrolling away by clicking the Zoom
In on Active Cursor button.
Warning
Do not click Yes. If you do, the $finish statement in the testbench causes
ModelSim to exit.
If this happens, go to the File List view in the Radiant window and look under the
Script Files folder. Double-click sim_test/sim_test.spf to restart ModelSim.
Active Strategy
Active Implementation
5. In the Find box at the top of the Device View, enter EBR_R13C21
(Embedded Block RAM Row 13, Column 21).
The EBR design symbol is highlighted, as shown in Figure 11.
You will be using Synopsis Synplify Pro for Lattice to synthesize your design
for the MachXO3L FPGA. If you are designing for most devices, you can use
Lattice Synthesis Engine or another third-party synthesis tool instead of
Synplify Pro for Lattice. LSE is not available with LatticeEC, LatticeECP,
LatticeSC/M, or LatticeXP. To change the synthesis tool, from the Diamond
main window, choose Project > Active Implementation > Select Synthesis
Tool.
When finished, check the icon next to Synthesize Design in the Process
frame. A green check mark indicates success; a yellow triangle
indicates success with warnings; a red X indicates failure.
2. Click the Hierarchy---Post Synthesis Resources tab, as shown in
Figure 13.
In the Hierarchy table shown in Figure 13, topcount is the top module
displaying the resource utilization.
PFU Registers – 48 represents the total PFU register utilization
throughout the design and 0 represents the PFU registers used only in the
design module topcount. Similar utilization is shown for the I/O registers
and carry cells.
my_pll_uniq_1, count8_uniq_0, and count32_uniq_1 are the sub-modules
(instances) of the design. For example, for the sub-module
count32_uniq_1, 32(32) under PFU Registers represents the total PFU
registers used in the sub-module.
Hence, the total number of logic resources (adding the resources from the
individual module) is reflected in the top level module topcount.
constraints for the place and route tools. Preferences are organized by
type into separate tabs of Spreadsheet View.
3. Click the Detach Tool button at the upper-right corner of Spreadsheet
View.
Spreadsheet View is detached from the Diamond main window.
4. Click the PERIOD/FREQUENCY Preference button on the
Spreadsheet View tool bar.
The PERIOD/FREQUENCY Preference dialog box appears.
5. Enter the following preference settings:
Type: FREQUENCY
Second Type: Net
Available Clock Nets: CLKOP
Frequency: 80
6. Click OK.
The Timing Preferences tab of Spreadsheet View appears with the new
FREQUENCY preference defined.
7. Click the INPUT_SETUP/CLOCK_TO_OUT Preference button on the
Spreadsheet View toolbar.
The INPUT_SETUP/CLOCK_TO_OUT Preference dialog box appears.
8. Enter the following preference settings:
Type: INPUT_SETUP
Second Type: All ports
Clock Ports/Nets: clk
Time: 50
Hold time: 12
9. Click OK.
The Timing Preferences tab of the Spreadsheet View appears with the
new INPUT_SETUP preference defined. You can define preferences in
the relevant preference dialog box.
10. In the Timing Preferences tab, right-click INPUT_SETUP and choose New
INPUT_SETUP.
The INPUT_SETUP/CLOCK_TO_OUTPUT Preference dialog box
appears.
11. Enter the following settings:
Type: INPUT_SETUP
Second Type: Individual Ports
Available Input Ports: reset
Clock Ports/Nets; clk
Time: 50
13. Select the Port Assignments tab from the Spreadsheet View.
This tab shows the port assignments that came with the
pin_assignments.lpf file and specifications for each port. You could make
changes here if you needed to.
14. Choose File > Save pin_assignments.lpf from the Spreadsheet View.
15. Close Spreadsheet View.
16. In the File List view, under the LPF Constraint Files folder, double-click
pin_assignments.lpf.
Source Editor appears. Note the timing and location preferences defined.
17. Close Source Editor.
18. In the Process view, double-click Map Design.
The batch interface to logic synthesis, EDIF translation, and the design
mapper run. Report files appears in the Reports view. To view each
process report, select the process in the Design Summary pane.
19. From the Design Summary pane of the Reports view, select Process
Reports > Map.
The Map Report appears in the right pane.
20. Right-click in the right pane of the Reports view.
21. Choose Find in Text.
A box labeled “Find” appears at the bottom of the Reports view.
22. In the Find box, enter Design Summary.
The report highlights the Design Summary section of the report.
In the Design Summary pane, there is the report icon . If a report has been
generated, the icon appears as . If the report is not the most recent version,
the icon appears as . To view the contents of the entire report, click on the
report to be viewed. The entire report is then displayed in the right pane of the
Reports view. Use the scroll bar to navigate through the report. Some of the
reports are divided into sections (for example, Map, Place & Route, and
Signal/Pad). Click the arrow before the report name to display the sections in
a list. Choose the desired section. The whole report will be displayed with the
selected section displayed at the top of the right pane of the Reports view.
The I/O Timing Report appears in the right pane of the Reports view.
7. Choose Tools > Physical View.
The Physical View appears, shown in Figure 15. Physical View provides a
read-only detailed layout of your design that includes switch boxes and
physical wire connections.
11. Right-click on the Floorplan View tab and choose Move to Another Tab
Group.
Now both tabs are merged into a single group as before.
12. Close Floorplan View and Physical View.
By default, the timing analysis engine, TRACE, uses those timing constraints
applied by timing-driven map, place, and route. However, you can modify
timing preferences to manage the timing objectives of the implementation
tools independent of Static Timing Analysis. To accommodate an
experimental Static Timing Analysis loop, the TPF Spreadsheet View allows
you to edit the timing preferences for use with the Timing Analysis view. This
allows you to establish modified or additional timing preferences independent
of the constraints used for MPAR.
see Analyzing Static Timing > Using Timing Analysis View in the Diamond
Help.
7. Close Timing Analysis View. Spreadsheet View – TPF closes
automatically.
Note
If you do not have a MachXO3L Starter Kit, skip this task.
9. Click OK.
10. Click the Program button on the Programmer toolbar to initiate the
download.
If the programming process succeeds, you will see a green-shaded PASS
in the Programmer Status column. On the board, the red LEDs switch to a
counting pattern.
11. Toggle DIP switch 1 to reverse the counting pattern. DIP switch 1 is the
switch furthest from the LEDs.
12. In Diamond, choose File > Save LEDtest.xcf.
13. Close Programmer and unplug the board’s USB cable.
2. Click the Detach Tool button in the upper-right corner to detach Reveal
Inserter.
Reveal Inserter is detached from the Diamond main window.
3. Click on the Trace Signal Setup tab, if it is not already selected.
4. In the Design Tree pane, expand counter1(count8_uniq_0) and drag the
countai[7:0] bus to the Trace Data pane on the right.
The name of the bus now appears in bold font in the Design Tree pane.
5. Right-click the created trace bus and choose Rename Trace Bus. Name
the bus countai.
6. Select the Include Trigger Signals in Trace Data option.
7. Drag the clk signal from the Design Tree pane to the Sample Clock box,
or type counter1/clk in the Sample Clock box.
8. For Buffer Depth box, choose 1024.
9. Set Data Capture Mode to Multiple Trigger Capture and Minimum
Samples Per Trigger to 32.
The Trace Signal Setup tab should now resemble Figure 20.
Note
If you do not have a MachXO3L Starter Kit, skip the rest of the tutorial. Go to
“Summary of Accomplishments” on page 44.
To generate a bitstream:
1. In the Process view, click Bitstream File under Export Files.
2. Click the Run button on the Diamond toolbar.
Diamond reruns all processes, generating the selected files and saving
them in your project directory.
3. Choose Tools > Programmer.
Programmer opens using the LEDtest.xcf file.
4. Click the Program button on the Programmer toolbar to initiate the
download.
If the programming process succeeds, you will see a green-shaded PASS
in the Programmer Status column.
5. Close Programmer.
This task assumes that the MachXO3L Starter Kit board is connected to your
computer with a USB cable.
8. Click OK.
The Reveal Logic Analyzer main window now appears with the LA Trigger
tab selected, as shown in Figure 23. It contains the same trigger units and
trigger expressions that you set up in Reveal Inserter.
9. In the Trigger Options section, for Samples Per Trigger, choose 64.
10. In the Trigger Position section, choose Post-Trigger.
In the Trigger Position section, you can specify the trigger position relative
to the trace data. The numbers in the section title show the current
position.The two options to choose from include:
Pre-selected allows you to choose one of the standard positions.
Pre-Trigger: 4/64 of the way from the beginning of the samples.
Center-Trigger: 32/64 of the way from the beginning of the
samples.
Post-Trigger: 57/64 of the way from the beginning of the samples.
User-selected allows you to choose a position with the slider.
The Reveal Analyzer LA Trigger tab should now appear as shown in
Figure 24.
To capture data:
1. Click the Run button in the Reveal Analyzer toolbar.
The Run button changes into the Stop button and the status bar next to
the button shows the progress.
Reveal Analyzer first configures the modules selected for the correct
trigger condition, then waits for the trigger conditions to occur. When a
trigger occurs, the data is uploaded to your computer. The resulting
waveforms appear in the LA Waveform tab.
Since the “countbi” trigger was set to <= 88 and the “dir” trigger was set to
<= 1, any DIP switch setting will immediately set off a trigger. The trigger
expression can now evaluate the next trigger unit and generate a trigger
for data to be captured.
If no trigger occurs, click the Manual Trigger button.
You now see the waveforms displayed, but the data may be varied as
shown in Figure 25.
Summary of Accomplishments
You have completed the Lattice Diamond 3.12 Tutorial. In this tutorial, you
have learned how to:
Create a new Lattice Diamond project.
Create an IPexpress module.
Check Hardware Description Language (HDL).
Verify functionality with simulation.
Inspect strategy settings.
Examine resources.
Set timing and location assignments.
Process the design.
Examine static timing analysis results.
Analyze power consumption.
Run export utility programs.
Download a bitstream to an FPGA.
Use Reveal Inserter to add on-chip debug logic.
Use Reveal Logic Analyzer to perform logic analysis.
Recommended References
You can find additional information on the subjects covered by this tutorial in
the Diamond software online Help, and in the Diamond User Guide.
Revision History
The following table gives the revision history for this document.