Ug948 Vivado Sysgen Tutorial
Ug948 Vivado Sysgen Tutorial
(v2016.4) October
UG948 (v2016.3) November28,30, 2016
2016
This tutorial was validated with 2016.3. Minor procedural differences might be required when using later
releases.
Revision History
11/30/2016: Released with Vivado® Design Suite 2016.4 without changes from 2016.3.
Introduction
System Generator for DSP is a design tool in the Vivado® Design Suite that enables you to use the
MathWorks® model-based Simulink® design environment for FPGA design. Previous experience with
Xilinx® FPGA devices or RTL design methodologies is not required when using System Generator.
Designs are captured in the Simulink™ modeling environment using a Xilinx-specific block set.
Downstream FPGA steps including RTL synthesis and implementation (where the gate level design is
placed and routed in the FPGA) are automatically performed to produce an FPGA programming
bitstream.
Over 80 building blocks are included in the Xilinx-specific DSP block set for Simulink. These blocks
include common building blocks such as adders, multipliers and registers. Also included are complex
DSP building blocks such as forward-error-correction blocks, FFTs, filters, and memories. These complex
blocks leverage Xilinx LogiCORE™ IP to produce optimized results for the selected target device.
VIDEO: The Vivado Design Suite Quick Take Video Tutorial: System Generator Multiple
Clock Domains describes how to use Multiple Clock Domains within System Generator, making it
possible to implement complex DSP systems.
VIDEO: The Vivado Design Suite QuickTake Video Tutorial: Generating Vivado HLS block
for use in System Generator for DSP describes how to generate a Vivado HLS IP block for use in
System Generator, and ends with a summary of how the Vivado HLS block can be used in your
System Generator design.
VIDEO: The Vivado Design Suite Quick Take Video: Using Vivado HLS C/C++/System C
block in System Generator describes how to incorporate your Vivado HLS design as an IP block
into System Generator for DSP.
VIDEO: The Vivado Design Suite Quick Take Video: Specifying AXI4-Lite Interfaces for your
Vivado System Generator Design describes how System Generator provides AXI4-Lite
abstraction making it possible to incorporate a DSP design into an embedded system. Full support
includes integration into the IP Catalog, interface connectivity automation, and software APIs.
VIDEO: The Vivado Design Suite QuickTake Video Tutorial: Using Hardware Co-Simulation
with Vivado System Generator for DSP describes how to use Point-to-Point Ethernet Hardware
Co-Simulation with Vivado System Generator for DSP. Hardware co-simulation makes it possible to
incorporate a design running in an FPGA directly into a Simulink simulation.
Lab 1: Understand how to create and validate a model using System Generator, synthesize the
model into FPGA hardware, and then create a more optimal hardware version of the design.
Lab 2: Learn how fixed-point data types can be used to trade off accuracy against hardware area
and performance.
Lab 3: Learn how to create an efficient design using multiple clock domains.
Lab 4: Make use of workspace variables to easily parameterize your models.
Lab 5: Model a control system using M-code.
Lab 6: Learn how to incorporate existing RTL designs, written in Verilog or VHDL, into your
design.
Lab 7: Import C/C++ source files into a System Generator model by leveraging the tool
integration with Vivado High-Level Synthesis (HLS).
Lab 8: Use AXI interfaces and Vivado IP integrator to easily include your model into a larger
design.
Lab 9: Integrate your design into a larger system and operate the design under CPU control.
Software Requirements
The lab exercises in this tutorial require the installation of MATLAB R2015b, R2015a, R2014b, or R2014.a.
See the Vivado Design Suite User Guide: Release Notes, Installation, and Licensing (UG973) for a
complete list and description of the system and software requirements.
1. Configure MATLAB.
On Windows systems:
a. Select Start > All Programs > Xilinx Design Tools > Vivado 2016.3 > System Generator
> System Generator 2016.3 MATLAB Configurator.
IMPORTANT: On Windows systems you may need to launch the MATLAB configurator
as Administrator. When MATLAB Configurator is selected in the menu, use the mouse
right-click to select Run as Administrator.
b. Click the check box of the version of MATLAB you want to configure and then click OK.
On Linux systems:
Launching System Generator under Linux is handled via a shell script called sysgen located in the
<Vivado install dir>/bin directory. Before launching this script, you must make sure the
MATLAB executable can be found in your Linux system’s $PATH environment variable. When you
execute the sysgen script, it will launch the first MATLAB executable found in $PATH and attach
System Generator to that session of MATLAB. Also, the sysgen shell script supports all the options
that MATLAB supports and all options can be passed as command line arguments to the sysgen
script.
When the System Generator opens, you can confirm the version of MATLAB to which System
Generator is attached by entering the version command in the MATLAB Command Window.
>> version
ans =
8.6.0.267246 (R2015b)
RECOMMENDED: You will modify the tutorial design data while working through this
tutorial. You should use a new copy of the SysGen_Tutorial directory extracted from
ug948-design-files.zip each time you start this tutorial.
TIP: This document assumes the tutorial files are stored at C:\SysGen_Tutorial. All
pathnames and figures in this document refer to this pathname. If you choose to store
the tutorial in another location, adjust the pathnames accordingly.
Introduction
In this lab exercise, you will learn how use System Generator to specify a design in Simulink and
synthesize the design into an FPGA. This tutorial uses a standard FIR filter and demonstrates how
System Generator provides you the design options that allow you to control the fidelity of the final
FPGA hardware.
Objectives
After completing this lab, you will be able to:
Procedure
This lab has three primary parts:
In Step 1, you will review an existing Simulink design using the Xilinx FIR Compiler block, and
review the final gate level results in Vivado.
In Step 3, the same filter is designed using standard discrete blockset parts.
4. From your Simulink project worksheet, select Simulation > Run or click the Run simulation button.
When simulation completes you can see the spectrum for the initial summed waveforms, showing a
1 MHz and 9 MHz component, and the results of both filters showing the attenuation of the 9 MHz
signals.
You will now create a version of this same filter using System Generator blocks for implementation in an
FPGA.
5. Click the Library Browser button in the Simulink toolbar to open the Simulink Library Browser.
When using System Generator, the Simulink library includes specific blocks for implementing
designs in an FPGA. You can find a complete description of the blocks provided by System
Generator in the Vivado Design Suite Reference Guide: Model-Based DSP Design Using System
Generator (UG958).
6. Expand the Xilinx Blockset menu, select DSP, then select Digital FIR Filter.
7. Right-click the Digital FIR Filter block and select Add block to model Lab1_1.
You can define the filter coefficients for the Digital FIR Filter block by accessing the block attributes
– double-click the Digital FIR Filter block to view these – or, as in this case, they may be defined
using the FDATool.
8. In the same DSP blockset as the previous step, select FDATool and add it to the Lab1_1 design.
An FPGA design requires three important aspects to be defined:
The input ports
The output ports
The FPGA technology
The next three steps show how each of these attributes is added to your Simulink design.
IMPORTANT: If you fail to correctly add these components to your design, it cannot be
implemented in an FPGA. Subsequent labs will review in detail how these blocks are
configured; however, they must be present in all System Generator designs.
9. In the Basic Elements menu, select Gateway In and add it to the design.
10. Similarly, from the same menu add a Gateway Out block to the design.
11. Similarly, from the same menu add the System Generator token used to define the FPGA
technology.
12. Finally, make a copy of one of the existing Spectrum Analyzer blocks and rename the instance to
Spectrum Analyzer SysGen by clicking the instance name label and editing the text.
13. Connect the blocks as shown in the following figure. Use the left-mouse key to make connections
between ports and nets.
The next part of the design process is to configure the System Generator blocks.
2. Close the Properties Editor for the Digital Filter Design instance.
3. Double-click the FDATool instance to open the Properties Editor.
4. Adjust the filter specifications to the following values (shown in the figure above):
Frequency Specifications
o Units = MHz
o Fs = 20
o Fpass = 1.5
o Fstop = 8.5
Magnitude Specifications
o Units = dB
o Apass = 0.01
o Astop = 100
blocks. This determines how often the continuous input waveform is sampled. This sample rate is
automatically propagated to other blocks in the design by System Generator. In a similar manner, the
number of bits used to represent the data is defined in the Gateway In block and also propagated
through the system.
Although not used in this tutorial, some Xilinx blocks enable rate changes and bit-width changes, up or
down, as part of this automatic propagation. More details on these blocks are found in the Vivado
Design Suite Reference Guide: Model-Based DSP Design Using System Generator (UG958).
Both of these attributes (rate and bit width) determine the degree of accuracy with which the
continuous time signal is represented. Both of these attributes also have an impact on the size,
performance, and hence cost of the final hardware.
System Generator allows you to use the Simulink environment to define, simulate, and review the
impact of these attributes.
10. Double-click the Gateway In block to open the Properties Editor.
Because the highest frequency sine wave in the design is 9 MHz, sampling theory dictates the sampling
frequency of the input port must be at least 18 MHz. For this design, you will use 20 MHz.
11. At the bottom of the Properties Editor, set the Sample Period to 1/20e6.
12. For now, leave the bit width as the default fixed-point 2’s complement 16-bits with 14-bits
representing the data below the binary point. This allows us to express a range of -2.0 to 1.999,
which exceeds the range required for the summation of the sine waves (both of amplitude 1).
17. Click the Run simulation button to simulate the design and view the results, as shown in Figure
13: FIR Compiler Results.
Because the new design is cycle and bit accurate, simulation may take longer to complete than before.
The results are shown above, on the right hand side (in the Spectrum Analyzer SysGen window), and
differ slightly from the original design (shown on the left in the Spectrum Analyzer FDA Tool window).
This is due to the quantization and sampling effect inherent when a continuous time system is
described in discrete time hardware.
The final step is to implement this design in hardware. This process will synthesize everything contained
between the Gateway In and Gateway Out blocks into a hardware description. This description of the
design is output in the Verilog or VHDL Hardware Description Language (HDL). This process is
controlled by the System Generator token.
18. Double-click the System Generator token to open the Properties Editor.
19. Select the Compilation tab to specify details on the device and design flow.
20. From the Compilation menu, select the IP Catalog compilation target to ensure the output is in IP
Catalog format. The Part menu selects the FPGA device. For now, use the default device. Also, use
the default hardware description language, VHDL.
IMPORTANT: The Vivado project provided in the ip_catalog directory does not
contain top-level I/O buffers. The results of synthesis provide a very good estimate of
the final design results; however, the results from this project cannot be used to create
the final FPGA.
24. Invoke the Vivado Design Suite: Start > All Programs > Xilinx Design Tools > Vivado 2016.3 >
Vivado 2016.3.
25. Click Open Project and then navigate to the folder
C:\SysGen_Tutorial\Lab1\netlist\ip_catalog.
26. Select file lab1_1.xpr and the Vivado IDE invokes the generated project file.
27. Click the Run Synthesis button to synthesize the design into hardware.
To get an exact confirmation of the final resources and timing, you could select Run Implementation
when the synthesis finishes. However, the results after synthesis provide a very good approximation of
the final results without the additional run time of implementing a fully placed and routed design and is
recommended early in the design cycle.
28. When synthesis completes, select Open Synthesized Design in the Synthesis Completed dialog box
and click OK.
29. In the Flow Navigator, select Synthesized Design > Report Utilization.
31. In the Utilization tab of the results windows area, click Summary to view a summary of the
resources used after the design is synthesized.
The frequency at which an FPGA device can be clocked easily exceeds 20 MHz. Running the FPGA at a
much higher clock frequency will allow System Generator to use the same hardware resources to
compute multiple intermediate results.
4. Double-click the FDATool instance to open the Properties Editor.
This shows the filter uses 11 symmetrical coefficients. This will require a minimum of 6 multiplications.
This is indeed what is shown in Figure 20: Lab1_1 Synthesis Results, where the final hardware is using 6
DSP48 components, the FPGA resource used to perform a multiplication.
The current design samples the input at a rate of 20 MHz. If the input is sampled at 6 times the current
frequency, it is possible to perform all calculations using a single multiplier.
6. Close the FDATool Properties Editor.
7. In the System Generator token update the sampling frequency to 120 MHz (6 * 20 MHz) in this
way:
a. Specify an FPGA clock Period of 8.33 ns (1/120 MHz).
b. Specify a Simulink system period of 1/120e6 seconds.
12. In the Flow Navigator, click the Run Synthesis button to synthesize the design into hardware.
13. When synthesis completes, select Open Synthesized Design in the Synthesis Completed dialog box
and click OK.
14. In the Flow Navigator, select Synthesized Design > Report Utilization.
15. In the Report Utilization dialog box, click OK.
16. In the Utilization tab of the results windows area, click Summary to view a summary of the
resources used to synthesize the design.
The hardware design now uses only a single DSP48 resource (a single multiplier) and compared to the
results in Figure 20: Lab1_1 Synthesis Results, the resources used are approximately half.
17. Exit the Vivado Design Suite.
18. Exit the Lab1_2.slx Simulink worksheet.
2. Click the Library Browser button in the Simulink toolbar to open the Simulink Library Browser.
3. Expand the Xilinx Blockset menu.
a. As shown in the following figure, select the Control Logic section, then select the Counter and
right-click with the mouse to add this component to the design.
b. Select the Memory section (shown at the bottom left in the figure above) and add a ROM to
the design.
c. Finally, select the DSP section and add a DSP48 Macro 3.0 to the design.
4. Connect the three new instances to the rest of the design as shown below.
You will now configure the instances to correctly filter the data.
5. Double-click the FDATool instance and select Filter Coefficients from the toolbar to review the
filter specifications.
This shows the same specifications as the previous steps in Lab 1 and confirms there are 11 coefficients.
You can also confirm, by double-clicking on the input Gateway In that the input sample rate is once
again 20 MHz (Sample period = 1/20e6). With this information, you can now configure the discrete
components.
6. Close the FDATool Properties Editor.
7. Double-click the Counter instance to open the Properties Editor.
a. For the Counter type, select Count limited and enter this value for Count to value:
length(xlfda_numerator('FDATool'))-1
This will ensure the counter counts from 0 to 10 (11 coefficient and data addresses).
b. For Output type, leave default value at Unsigned and in Number of Bits enter the value 4.
Only 4 binary address bits are required to count to 11.
c. For the Explicit period, enter the value 1/(11*20e6) to ensure the sample period is 11 times
the input data rate. The filter must perform 11 calculations for each input sample.
b. In the Pipeline Options tab, use the Pipeline Options drop-down menu to select By_Tier.
c. Select Tier 3 and Tier 5. This will ensure registers are used at the inputs to A and B and between
the multiply and accumulate operations.
The final step is to compile the design into a hardware description and synthesize it.
12. Double-click the System Generator token to open the Properties Editor.
13. From the Compilation menu, make sure the Compilation target is IP Catalog.
14. Press Generate to compile the design into a hardware description.
15. Click OK to dismiss the Compilation status dialog box.
16. Click OK to dismiss the System Generator token.
17. Use one of these two alternatives to open the example Vivado project:
Use Start > All Programs > Xilinx Design Tools > Vivado 2016.3 > Vivado 2016.3, click
Open Project, navigate to the folder C:\SysGen_Tutorial\Lab1\netlist\ip_catalog
and select the file lab1_3.xpr.
OR
Navigate to C:\SysGen_Tutorial\Lab1\netlist\ip_catalog and double-click the file
lab1_3.xpr.
18. In the Flow Navigator, click the Run Synthesis button to synthesize the design into hardware.
19. When synthesis completes, select Open Synthesized Design in the Synthesis Completed dialog box
and click OK.
20. In the Flow Navigator, select Synthesized Design > Report Utilization.
21. In the Report Utilization dialog box, click OK.
22. In the Utilization tab of the results windows area, click Summary to view a summary of the
resources used to synthesize the design.
The design now uses fewer FPGA hardware resources than either of the versions designed with the
Digital FIR Filter macro (Figure 20: Lab1_1 Synthesis Results and Figure 24: Lab1_2 Synthesis Results).
23. Exit the Vivado Design Suite.
24. Exit the Lab1_3.slx worksheet.
Summary
In this lab, you learned how to use the System Generator blockset to create a design in the Simulink
environment and synthesize the design in hardware which can be implemented on a Xilinx FPGA. You
learned the benefits of quickly creating your design using a Xilinx Digital FIR Filter block and how the
design could be improved with the use of over-sampling.
Finally, you learned how you can take total control of the hardware implementation by using discrete
primitives.
Note: In this tutorial you learned how to add System Generator blocks to the design and then
configure them. A useful productivity technique is to add and configure the System Generator
token first. If the target device is set at the start, some complex IP blocks will be automatically
configured for the device when they are added to the design.
The following solutions directory contains the final System Generator (*.slx) files for this lab. The
solutions directory does not contain the IP output from System Generator or the files and directories
generated when Vivado is executed.
C:/SysGen_Tutorial/Lab1/solution
Introduction
In this lab exercise, you will learn how hardware-efficient fixed-point types can be used to create a
design which meets the required specification but is more efficient in resources, and understand how to
use Xilinx Blocksets to analyze these systems.
Objectives
After completing this lab, you will be able to:
Procedure
This exercise has two primary parts.
In Step 1 you will review and synthesize a design using floating-point data types.
In Step 2 you will work with the same design, captured as a fixed-point implementation, and
refine the data types to create a hardware-efficient design which meets the same requirements.
As you can see in the figure above, both the input and output of instance FIR are of type double.
8. Return to the top-level design using the toolbar button Up To Parent , or click on the tab labeled
Lab2_1.
The design is summing two sine waves, both of which are 9 MHz. The input gateway to the System
Generator must therefore sample at a rate of at least 18 MHz.
9. Double-click the Gateway In1 instance to open the Properties Editor and confirm the input is
sampling the data at a rate of 20 MHz (a Sample period of 1/20e6).
10. Close the Gateway In Properties editor.
11. Press the Run simulation button to simulate the design.
The results shown below show the System Generator blockset produces results which are very close to
the ideal case, shown in the center. The results are not identical because the System Generator design
must sample the continuous input waveform into discrete time values.
22. In the Utilization tab of the results windows area, click Summary to view a summary of the
resources used to synthesize the design.
You implemented this same filter in Lab 1 using fixed-point data types. When compared to the
synthesis results from that implementation – the initial results from Lab 1 are shown below in Figure 39:
Lab1_1 Synthesis Results and you can see this current version of the design is using a large amount of
registers (FF), LUTs, and DSP48 (DSP) resources (Xilinx dedicated multiplier/add units).
Maintaining the full accuracy of floating-point types is an ideal implementation but implementing full
floating-point accuracy requires a significant amount of hardware.
For this particular design, the entire range of the floating-point types is not required. The design is
using considerably more resources than what is required. In the next step, you will learn how to
compare designs with different data types inside the Simulink environment.
1. At the command prompt, type open Lab2_2.slx to open the design shown below.
In this design, the floating-point implementation is captured alongside an identical fixed point design.
2. In the MATLAB Command Window enter MyCoeffs = xlfda_numerator('FDATool').
3. Double-click the instance Gateway In2 to confirm the data is being sampled as 16-bit fixed-point
value.
4. Click Cancel to exit the Properties Editor.
5. Click the Run simulation button to simulate the design and confirm instance Spectrum Analyzer
SysGen Fixed shows the filtered output.
As you will see if you examine the output of instance FIR-Fixed-Point (shown in Figure 40: Lab2_2
Design) System Generator has automatically propagated the input data type through the filter and
determined the output must be 43-bit (with 28 binary bits) to maintain the resolution of the signal.
This is based on the bit-growth through the filter and the fact that the filter coefficients (constants in
instance FIR-Fixed-Point) are 16-bit.
6. In the MATLAB Command Window, enter sum(abs(MyCoeffs)) to determine the absolute
maximum gain using the current coefficients.
Taking into account the positive and negative values of the coefficients the maximum gain possible is
1.2070 and the output signal should only ever be slightly smaller in magnitude than the input signal,
which is a 16-bit signal. There is no need to have 15 bits (43-28) of data above the binary point.
You will now use the Reinterpret and Convert blocks to manipulate the fixed-point data to be no
greater than the width required for an accurate result and produce the most hardware efficient design.
7. Right-click with the mouse anywhere in the canvas and select Xilinx BlockAdd.
8. In the Add Block entry box, type Reinterpret.
9. Double-click the Reinterpret component to add it to the design.
10. Repeat the previous three steps for these components:
a. Convert
b. Scope
11. In the design, select the Gateway Out2 instance.
a. Right-click and use Copy and Paste to create a new instance of the Gateway Out block.
b. Paste twice again to create two more instances of the Gateway Out (for a total of three new
instances).
12. Double-click the Scope component.
a. In the Scope properties dialog box, select File > Number of Inputs > 3.
b. Select View > Configuration Properties and confirm that the Number of input ports is 3.
TIP: You may need to zoom in and adjust the scale in View > Configuration
Properties to view the signals in detail.
The Reinterpret and Convert blocks have not been configured at this point and so all three signals are
identical.
The Xilinx Reinterpret block forces its output to a new type without any regard for retaining the
numerical value represented by the input. The block allows for unsigned data to be reinterpreted as
signed data, or, conversely, for signed data to be reinterpreted as unsigned. It also allows for the
reinterpretation of the data's scaling, through the repositioning of the binary point within the data.
In this exercise you will scale the data by a factor of 2 to model the presence of additional design
processing which may occur in a larger system. The Reinterpret block may also be used to scale down.
17. Double-click the Reinterpret block to open the Properties Editor.
18. Select Force Binary Point.
19. Enter the value 27 in the input field Output Binary Point and click OK.
The Xilinx Convert block converts each input sample to a number of a desired arithmetic type. For
example, a number can be converted to a signed (two's complement) or unsigned value. It also allows
the signal quantization to be truncated or rounded and the signal overflow to be wrapped, saturated, or
to be flagged as an error.
In this exercise, you will use the Convert block to reduce the size of the 43-bit word back to a 16-bit
value. In this exercise the Reinterpret block has been used to model a more complex design and scaled
the data by a factor of 2. You must therefore ensure the output has enough bits above the binary point
to represent this increase.
20. Double-click the Convert block to open the Properties Editor.
21. In the Fixed-Point Precision section, enter 13 for the Binary Point and click OK.
22. Save the design.
23. Click the Run simulation button to simulate the design.
24. Double-click the Scope to examine the signals.
TIP: You may need to zoom in and adjust the scale in View > Configuration
Properties to view the signals in detail.
In the figure below you can see the output from the filter (Growth) has values between plus and minus
1. The output from the Reinterpret block moves the data values to between plus and minus 2. In this
detailed view of the waveform, the final output (Convert) shows no difference in fidelity, when
compared to the reinterpret results, but uses only 16 bits.
Notice, as compared to the results in Step 1 (Figure 38: Lab2_1 Synthesis Results) these results show
approximately
45% more Flip-Flops
20% more LUTs
30% more DSP48s
However, this design contains both the original floating-point filter and the new fixed-point version: the
fixed-point version therefore uses approximately 75-50% fewer resources with the acceptable signal
fidelity and design performance.
36. Exit the Vivado Design Suite.
37. Exit the Lab2_2.slx worksheet.
Summary
In this lab, you learned how floating-point types provide a high degree of accuracy but cost many more
resources to implement in an FPGA. You also learned how the System Generator blockset can be used
to both implement a design using more efficient fixed-point data types and compensate for any loss of
accuracy caused by using fixed-point types.
The Reinterpret and Convert blocks are powerful tools which allow you to optimize your design without
needing to perform detailed bit-level optimizations. You can simply use these blocks to convert
between different data types and quickly analyze the results.
The following solutions directory contains the final System Generator (*.slx) files for this lab. The
solutions directory does not contain the IP output from System Generator or the files and directories
generated when Vivado is executed.
C:/SysGen_Tutorial/Lab2/solution
Introduction
In this lab exercise, you will learn how to efficiently implement designs with multiple data rates using
multiple clock domains.
Objectives
After completing this lab, you will be able to:
Understand the benefits of using multiple clock domains to implement multi-rate designs.
Understand how to isolate hierarchies using FIFOs to create safe channels for transferring
asynchronous data.
How to implement hierarchies with different clocks.
Procedure
This exercise has three primary parts.
In Step 1, you will learn how to create hierarchies between the clock domains.
In Step 2, you will learn how to add FIFOs between the hierarchies.
In Step 3, you will learn how to add separate clock domains for each hierarchy.
This opens the Simulink design shown in the following figure. This design is composed of three basic
parts:
The channel filter digitally converts the incoming signal (491.52 MSPS) to near baseband (61.44
MSPS) using a classic multi-rate filter: the use of two half-band filters followed by a decimation
of 2 stage filter, which requires significantly fewer coefficients than a single large filter.
The output section gain-controls the output for subsequent blocks which will use the data.
The gain is controlled from the POWER_SCALE input.
The System Generator environment automatically propagates the different data rates through the
design. When a multi-rate design such as this is implemented in hardware, the most optimal
implementation is to use a clock at the same frequency as the data; however, the clock is abstracted
away in this environment. The following methodology demonstrates how to create this ideal
implementation in the most efficient manner.
To efficiently implement a multi-rate (or multi-clock) design using System Generator you should
capture each part running at the same data rate (or clock frequency) in its own hierarchy with its own
System Generator token. The separate hierarchies should then be linked with FIFOs.
The current design has two obvious, and one less obvious, clock domains:
The gain control input POWER_SCALE could be configurable from a CPU and therefore can run
at the same clock frequency as the CPU.
The actual gain-control logic on the output stage should run at the same frequency as the
output data from the FIR. This will allow it to more efficiently connect to subsequent blocks in
the system.
The less obvious region is the filter-chain. Remember from Lab 1 that complex IP provided with
System Generator, such as the FIR Compiler, automatically takes advantage of over-clocking to
provide the most efficient hardware. For example, rather than use 40 multipliers running at 100
MHz, the FIR Compiler will use only 8 multipliers if clocked at 500 MHz (= 40*100/500). The
entire filter chain can therefore be grouped into a single clock domain. The first FIR Compiler
instance will execute at the maximum clock rate and subsequent instances will automatically
take advantage of over-sampling.
You will start by grouping these regions into different hierarchies.
5. Select all the blocks in the filter chain – all those to be in the same clock domain, including the
FDATool instances - as shown below.
6. Select Create Subsystem, also as shown in the figure below, to create a new subsystem.
7. Select the instance name subsystem and change this to DDC to obtain the design shown.
8. Select the components in the output path and create a subsystem named Gain Control.
9. Finally, select the Gateway In instance POWER_SCALE and Constant to create a new subsystem
called CTRL. The final grouped design is shown below.
When this design is complete, the logic within each subsystem will execute at different clock
frequencies. The clock domains might not be synchronous with each other. There is presently nothing
to prevent incorrect data being sampled between one subsystem and another subsystem.
In the next step you will create asynchronous channels between the different domains to ensure data
will asynchronously and safely cross between the different clock domains when the design is
implemented in hardware.
There are two data paths in the design where FIFOs are required:
You will now connect up the control logic signals to ensure the data is safely passed between domains.
From the CTRL block a write enable is required. This is not currently present and needs to be
created.
From the DDC block a write enable is required. The data_tvalid from the final FIR stage may be
used for this.
The Gain Control must generate a read enable for both FIFOs. You will use the empty signal
from the FIFOs and invert it; if there is data available, this block will read it.
7. Double-click the CTRL block to open the subsystem.
8. Right-click in the canvas and use Xilinx BlockAdd to add these blocks:
a. Delay (Xilinx)
b. Relational
9. Select instance Out1 and make a copy (use Ctrl-C and Ctrl-V to cut and paste).
10. Double-click the Relational block to open the Properties Editor.
11. Use the Comparison drop-down menu to select a!=b and click OK.
12. Connect the blocks as shown in the following figure.
This will create an output strobe on Out2 which will be active for one cycle when the input changes. This
will be used as the write-enable from CTRL to the Gain Control (the FIFO block at the top level).
13. Click the Up to Parent toolbar button to return to the top level.
14. Double-click the instance Gain Control to open the subsystem.
15. Right-click in the canvas and use Xilinx BlockAdd to add these blocks:
a. Inverter
b. Inverter (for a total of two inverters)
c. Delay (Xilinx)
16. Select the instance Out1 and make a copy Out3 (use Ctrl-C and Ctrl-V to cut and paste).
a. Rename Out3 to DDC_Read
17. Select instance Out1 and make a copy Out3 (use Ctrl-C and Ctrl-V to cut and paste).
a. Rename Out3 to CTRL_Read
18. Select instance In1 and make a copy In4 (use Ctrl-C and Ctrl-V to cut and paste).
a. Rename In4 to CTRL_Empty
19. Connect the blocks as shown in the following figure.
The FIFO empty signal from the top-level Gain Control FIFO (FIFO) block is simply an inverter
block used to create a read-enable for the top-level DDC FIFO (FIFO1). If the FIFO is not empty,
the data will be read.
Similarly, the FIFO empty signal from the top-level DDC FIFO (FIFO1) is inverted to create a FIFO
read-enable.
This same signal will be used as the new data_tvalid (which was In2). However, since the FIFO
has a latency of 1, this signal must be delayed to ensure this control signal is correctly aligned
with the data (which is now delayed by 1 through the FIFO).
20. Use the Up to Parent toolbar button to return to the top level.
This shows the control signals are now present at the top level.
23. Click the Run simulation button to simulate the design and confirm the correct operation – you will
see the same results as Step 1 action 4.
In the next step, you will learn how to specify different clock domains are associated with each
hierarchy.
Summary
In this lab, you learned how to create separate hierarchies for portions of the design which are to be
implemented with different clock rates. You also learned how to isolate those hierarchies using FIFOs to
ensure safe asynchronous transfer of the data and how to specify the clock rates for each hierarchy.
The following solutions directory contains the final System Generator (*.slx) files for this lab. The
solutions directory does not contain the IP output from System Generator or the files and directories
generated when Vivado is executed.
C:/SysGen_Tutorial/Lab3/solution
The results from Step1 are provided in file Lab3_1_sol.slx
The results from Step2 are provided in file Lab3_2_sol.slx
The final results from Step3 are provided in file Lab3_3_sol.slx
Introduction
In this lab, you will learn how to use workspace variables to easily parameterize your System Generator
designs.
Objectives
After completing this lab, you will be able to use workspace variables to create paramaterizable and
customizable designs.
Procedure
In this lab you will review how a design is parameterized using workspace variables.
TIP: You may need to zoom in and adjust the scale in View > Configuration
Properties to view the signals in detail.
In the figure below you can review the output which shows a standard impulse response from the filter.
In this case the peak value is approximately 50.
You will now replace some of the attributes of this design with workspace variables. First, you need to
define some workspace variables.
6. In the MATLAB Command Window:
a. Enter MyCoeffs = fir1(30, 0.5)
b. Enter num_bits = 24
c. Enter bin_pt = 8
7. In design Lab4_1, double-click the Gateway In block to open the Properties Editor.
8. In the Fixed-Point Precision section, replace 16 with num_bits and replace 14 with bin_pt, as
shown below.
12. In the Implementation tab of the Properties Editor, use the Quantization drop-down menu to
select Maximize_Dynamic_Range.
13. Click OK to save and exit the Properties Editor.
14. Save the design.
15. Press the Run simulation button to simulate the design.
When simulation completes, note the input to the FIR is now a 24-bit fixed-point data type. This is now
defined by the workspace variables num_bits and bin_pt and can now be easily updated directly
from the MATLAB console or from a script executed in the console.
16. Double-click the Scope to examine the signals.
TIP: You may need to zoom in and adjust the scale in View > Configuration
Properties to view the signals in detail.
The impulse response is now defined by the values on MyCoeffs and only has a peak value of
approximately 0.5.
17. In the Lab4_1 design use File > Close > Close Model to exit the Lab4_1 design.
18. In the MATLAB console type bdclose all.
19. In the MATLAB console type clear to remove the variables from the workspace.
20. At the command prompt, type open Lab4_1.slx
21. Click the Run simulation button to simulate the design.
This results in a numbers of errors since the workspace variables are no longer defined.
22. Exit the Lab4_1.slx Simulink worksheet.
Summary
In this lab, you learned how to use workspace variables to enhance your overall efficiency when using
System Generator.
Solutions to this lab can be found in the following location:
C:/SysGen_Tutorial/Lab4/solution
Introduction
In this lab you will be creating a simple Finite State Machine (FSM) using the MCode block to detect a
sequence of binary values 1011. The FSM needs to be able to detect multiple transmissions as well, such
as 10111011.
Objectives
After completing this lab, you will be able to create a Finite State Machine using the MCode block in
System Generator.
Procedure
In this lab you will create the control logic for a Finite State Machine using M-code. You will then
simulate the final design to confirm the correct operation.
5. Edit the default MATLAB function to include the function name state_machine and the input din
and output matched.
6. You can now delete the sample M-code.
7. After you make the edits, use Save As to save the MATLAB file as state_machine.m to the Lab5
folder.
a. In the MCode Properties Editor, use the Browse button to ensure that the MCode block is
referencing the local M-code file (state_machine.m).
8. In the MCode Properties Editor, click OK.
You will see the MCode block assume the new ports and function name.
9. Now connect the MCode block to the diagram as shown below:
You are now ready to start coding the state machine. The bubble diagram for this state machine is
shown in the following figure. This FSM has five states and is capable of detecting two sequences in
succession.
10. Edit the M-code file, state_machine.m, and define the state variable using the Xilinx xl_state
data type as shown below. This requires that you declare a variable as a persistent variable. The
xl_state function requires two arguments: the initial condition and a fixed-point declaration.
Because you need to count up to 4, you need 3 bits.
persistent state, state = xl_state(0,{xlUnsigned, 3, 0});
11. Use a switch-case statement to define the FSM states shown. A small sample is provided below to
get you started.
Note: You need an otherwise statement as your last case.
switch state
case 0
if din == 1
state = 1;
else
state = 0;
end
matched = 0;
12. Save the M-code file and run the simulation. The waveform should look like the following figure.
You should notice two detections of the sequence.
Summary
In this exercise you learned how to create control logic using M-Code. The final design may be used to
create an HDL netlist, in the same manner as designs created using the Xilinx Blocksets.
Introduction
In this lab exercise you will import an RTL design into System Generator as a black box.
A black box allows the design to be imported into System Generator even though the
description is in Hardware Description Language (HDL) format.
Objectives
After completing this lab, you will be able to:
5. Right-click the design canvas, select Xilinx BlockAdd, and add a Black Box block to this subsystem.
A browser window opens, listing the VHDL source files that can be associated with the black box.
6. From this window, select the top-level VHDL file transpose_fir.vhd. This is illustrated in the
following figure:
9. Double click the Black Box block to open this dialog box:
11. Move to the design’s top level and run the simulation by clicking the Run simulation button ;
then double-click the Scope block.
12. Notice the black box output shown in the Output Signal scope is zero. This is expected because the
black box is configured to be Inactive during simulation.
13. From the Simulink Editor menu, select Display > Signals & Ports > Port Data Types to display the
port types for the black box.
14. Compile the model (Ctrl-D) to ensure the port data types are up to date.
Notice that the black box port output type is UFix_26_0. This means it is unsigned, 26-bits wide, and
has a binary point 0 positions to the left of the least significant bit.
15. Open the configuration M-function transpose_fir_config.m and change the output type from
UFix_26_0 to Fix_26_12. The modified line (line 26) should read:
dout_port.setType('Fix_26_12');
Continue the following steps to edit the configuration M-function to associate an additional HDL
file with the black box.
16. Locate line 65: this_block.addFile('transpose_fir.vhd');
17. Immediately above this line, add the following: this_block.addFile('mac.vhd');
18. Save the changes to the configuration M-function and close the file.
19. Click the design canvas and recompile the model (Ctrl-D).
Your Transpose FIR Filter Black Box subsystem should display as follows:
20. From the Black Box block parameter dialog box, change the Simulation mode field from Inactive to
Vivado Simulator and then click OK.
21. Move to the top-level of the design and run the simulation.
22. Examine the scope output after the simulation has completed.
Notice the waveform is no longer zero. When the Simulation Mode was Inactive, the Output Signal
scope displayed constant zero. Now, the Output Signal shows a sine wave as the results from the
Vivado Simulation.
23. Right click the Output Signal display and select Configuration Properties. In the Main tab, set Axis
Scaling to the Auto setting. You should see a display similar to that shown below.
Summary
In this exercise you learned how to model blocks in System Generator using HDL by incorporating an
existing VHDL RTL design. You learned the importance of matching the data types of the System
Generator model with those of the RTL design and how the RTL design is simulated within System
Generator.
Solutions to this lab can be found in the following location:
C:/SysGen_Tutorial/Lab6/solution
Introduction
The System Edition of the Vivado® Design Environment includes the Vivado HLS feature, which has the
ability to transform C/C++ design sources into RTL. System Generator has a Vivado HLS block in the
Xilinx Blockset/Control Logic and Xilinx Blockset/Index libraries that enables you to bring in C/C++
source files into a System Generator model.
Objectives
After completing this lab, you will be able to incorporate a design, synthesized from C, C++ or SystemC
using Vivado HLS, as a block into your MATLAB design.
Procedure
In this exercise you will first synthesize a C file using Vivado HLS. You will operate within a Vivado DSP
design project, using a design file from MATLAB along with an associated HDL wrapper and constraint
file. In Step 2, you incorporate the output from Vivado HLS into MATLAB and use the rich simulation
features of MATLAB to verify that the C algorithm correctly filters an image.
4. Expand the Source folder in the Explorer pane (left-hand side) and double-click the file
MedianFilter.cpp to view the contents of the C++ file as shown in the following figure.
Now you will package the source for use in System Generatorfor.
When the Export RTL process completes, Vivado HLS displays this message:
Finished export RTL.
8. Exit Vivado HLS.
9. Connect the input and output ports of the block as shown in the following figure.
10. Navigate into the Noisy Image sub-system and double-click the Image From File block lena.png
to open the Source Block Parameters dialog box.
11. Use the Browse button to ensure the file name correctly point to the file lena.jpg as shown
below.
13. Use the toolbar button Up to Parent to return to the top level.
14. Save the design.
15. Simulate the design and verify the image is filtered, as shown in the following figures.
Summary
In this lab exercise you were able to take a filter written in C++, synthesize it with Vivado HLS and
incorporate the design into MATLAB. This process allows you to use any C, C++ or SystemC design and
create a custom block for use in your designs.
This exercise showed you how to import the RTL design generated by Vivado HLS and use the design
inside MATLAB.
Introduction
In this lab, you will learn how AXI interfaces are implemented using System Generator. You will save the
design in IP catalog format and use the resulting IP in the Vivado IP Integrator environment. Then you
will see how IP Integrator enhances your productively by supplying connection assistance when you use
AXI interfaces.
Objectives
After completing this lab, you will be able to:
Procedure
This exercise has four primary parts.
In Step 1, you will review how AXI interfaces are implemented using System Generator.
In Step 2, you will create a Vivado project for your System Generator IP.
In Step 3, you will create a design in IP Integrator using the System Generator IP.
In Step 4, you will implement the design and generate an FPGA bitstream (the file used to
program the FPGA).
1. Invoke System Generator and use the Current Folder browser to change the directory to
C:\SysGen_Tutorial\Lab8.
2. Type open Lab8_1.slx in the Command Window.
This opens the design shown in the following figure.
This design uses a number of AXI interfaces. You will review these shortly.
Using AXI interfaces allows a design exported to the Vivado IP Catalog to be efficiently integrated
into a larger system using IP Integrator.
It is not a requirement for designs exported to the IP Catalog to use AXI interfaces.
This design uses the following AXI interfaces:
An AXI4-Stream interface is used for ports s_axis_source_*. All Gateway In and Out signals are
prefixed with the same name (s_axis_source_), ensuring they are grouped into the same
interface. The suffixes for all ports are valid AXI4-Stream interface signal names (tready, tvalid,
tlast and tdata).
Similarly, an AXI4-Stream interface is used for ports m_axis_dout_*.
An AXI4-Lite interface is used for the remaining ports. You can confirm this using the following
steps:
3. Double-click Gateway In instance decrypt (or any of reset, Keys[63:32], Keys[31:0], or parity_err).
TIP: You will have to manually type /IPI_Project in the Project location box to
create the IPI_Project directory.
2. In the Create Block Design dialog box, click OK to accept the default name.
You will first create an IP repository for the System Generator IP and add the IP to the repository.
3. Click the IP Setting button as shown below.
4. In the Repository Manager tab, click the Add button (+) to add a repository.
5. Navigate to C:\SysGen_Tutorial\Lab8\sys_gen_ip\ip.
6. With folder ip selected, click Select to create the new repository as shown below.
13. Leave Apply Board Preset selected and click OK. This will ensure the design is automatically
configured to operate on the ZC702 evaluation board.
14. Right-click anywhere in the block diagram and select Add IP.
1. Return to the Project Manager view by clicking Project Manager in the Flow Navigator.
2. In the Sources browser in the main workspace pane, a Block Diagram object called design_1 is at
the top of the Design Sources tree view.
3. Right-click this object and select Generate Output Products.
4. In the Generate Output Products dialog box, click Generate to start the process of generating the
necessary source files.
5. When the generation completes, right-click the design_1 object again, select Create HDL
Wrapper, and click OK (and let Vivado manage the wrapper) to exit the resulting dialog box.
The top level of the Design Sources tree becomes the design_1_wrapper.v file. The design is now
ready to be synthesized, implemented, and to have an FPGA programming bitstream generated.
6. In the Flow Navigator, click Generate Bitstream to initiate the remainder of the flow.
7. Click Yes to generate the synthesis and implementation files.
8. In the dialog that appears after bitstream generation has completed, select Open Implemented
Design and click OK.
9. Exit the Vivado IDE.
The next tutorial: Lab 9: Using a System Generator Design with a Zynq-7000 AP SoC, shows how this
design may be further processed using the Vivado IDE to implement this design with software on a
Xilinx ZC702 evaluation board.
Summary
In this lab, you learned how AXI interfaces are added to a System Generator design and how a System
Generator design is saved in IP Catalog format, incorporated into the Vivado IP Catalog, and used in a
larger design. You also saw how IP Integrator can substantially increase productivity with connection
automation and hints when AXI interfaces are used in your design.
The following solutions directory contains the final System Generator (*.slx) files for this lab. The
solutions directory does not contain the IP output from System Generator or the files and directories
generated when Vivado is executed.
C:/SysGen_Tutorial/Lab8/solution
Introduction
In this lab, you will learn how to export your Vivado design with System Generator IP to a software
environment and use driver files created by System Generator to quickly implement your project on a
Xilinx evaluation board, running hardware with software in the same design.
Objectives
After completing this lab, you will be able to:
Understand how to export your Vivado design with System Generator IP to a software
environment (SDK).
Understand how System Generator automatically creates software driver files for AXI4-Lite
interfaces.
Understand how to integrate the System Generator driver files into your software application.
Procedure
This exercise has two primary parts.
In Step 1, you will review the AXI4-Lite interface and associated C drivers.
In Step 2, you will export your Vivado design to a software environment and run it on a board.
This exercise uses the same design as Lab 8: Using AXI Interfaces and IP Integrator.
1. Invoke System Generator and use the Current Folder browser to change the directory to:
C:\SysGen_Tutorial\Lab9.
2. At the command prompt, type open Lab9_1.slx.
This opens the design shown in the following figure.
This design uses a number of AXI interfaces. These interfaces were reviewed in Lab 8 and the review is
repeated here with additional details on the AXI4-Lite register addressing.
Using AXI interfaces allows a design exported to the Vivado IP Catalog to be efficiently
integrated into a greater system using IP integrator.
It is not a requirement for designs exported to the IP Catalog to use AXI interfaces.
The design uses the following AXI interfaces:
An AXI4-Stream interface is used for ports s_axis_source_*. All Gateway In and Out signals
are prefixed with same name (s_axis_source_) ensuring they are grouped into the same
interface. The suffix for all ports are valid AXI4-Stream interface signal names (tvalid, tlast
and tdata).
An AXI4-Lite interface is used for the remaining ports. You can confirm this by performing the
following steps:
11. Open file lab9_1_hw.h to review which addresses the ports in the AXI4-Lite interface were
automatically assigned.
12. Open file lab9_1.c to review the C code for the driver functions. These are used to read and write
to the AXI4-Lite registers and can be incorporated into your C program running on the Zynq-7000
CPU. The function to write to the decrypt register is shown in the figure below.
The driver files are automatically included when the System Generator design is added to the IP
Catalog. The procedure for adding a System Generator design to the IP Catalog is detailed in Lab 8. In
the next step, you will implement the design
This creates the project, creates the IPI design and builds the implementation (RTL synthesis, followed
by place and route). This may take some time to complete (same as the final step of lab8).
When it completes:
3. Click Open Implemented Design in the Flow Navigator pane.
4. From the Vivado File menu select Export > Export Hardware.
5. In the Export Hardware dialog box make sure the Include Bitstream option is enabled.
Leave everything as local to the project.
6. Click OK to export the hardware.
14. Power up the ZC702 board so you can program the FPGA.
Make sure the board has all the connections to allow you to download the bitstream on the FPGA
device, and make sure switches SW10 and SW16 are set correctly. Refer to the documentation that
accompanies the ZC702 development board.
15. Click XilinxTools > Program FPGA.
The Done LED (DS3) goes on.
16. Select the SDK Terminal tab at the bottom of the workspace.
17. To set up the terminal in the SDK Terminal tab, click the Connect icon and perform the following:
a. Select Connection Type > Serial.
b. Select the COM port to which the USB UART cable is connected. On Windows, if you are not
sure, open the Device Manager and identify the port with the Silicon Labs driver under Ports
(COM & LPT).
c. Change the Baud Rate to 115200.
d. Click OK to exit the Terminal Settings dialog box.
e. Check that terminal is connected by message in tab title bar.
18. Right-click application project Des_Test in the Project Explorer pane.
a. Select Run As > Launch on Hardware.
19. Switch to the SDK Terminal tab and confirm that Hello World was received.
20. Expand the container Des_Test and then expand the container src.
21. Double-click the helloworld.c file.
22. Replace the contents of this file with the contents of the file hello_world_final.c from the lab9
directory.
23. Save the helloworld.c source code.
24. Right-click application project Des_Test in the Explorer pane, and select Run As > Launch on
Hardware.
Note: If a window opens containing the text “debug session already exists”, click OK in that
window.
25. Review the results in the SDK Terminal tab (shown below).
Summary
In this lab, you learned how to export your Vivado design containing System Generator IP to the SDK
software environment and integrate the driver files automatically created by System Generator to run
the application on the ZC702 board. You then viewed the result of the acceleration.
The following solutions directory contains the final System Generator (*.slx) files for this lab. The
solutions directory does not contain the IP output from System Generator, the files and directories
generated when Vivado is executed, or the SDK workspace.
C:/SysGen_Tutorial/Lab9/solution