Create an FPGA VI and Project
To speed up the process of building our VI for debug, this tutorial leverages one of the example programs provided with the NI 6581 adapter module.
- Open NI 6581 Finite Acquisition and Generation – Simple.lvproj. You can locate this example by selecting Help » Find Examples to launch the NI Example Finder. Browse to Hardware Input and Output » FlexRIO » IO Modules » NI 6581 » NI 6581 Finite Acquisition and Generation – Simple.lvproj.
- To avoid inadvertently saving over this example, in the project window select File » Save As and Duplicate the project and dependencies.
Select Continue, then select an appropriate location and file name to save your new project. Close the original example project and open the duplicate that you just saved.
- Make some simple modifications to the FPGA VI to optimize your simulation experience.
The Modified VI, NI 6581 Acquisition and Generation Simple (FPGA) (Simulation).vi, is included in the ni6581simulationfiles.zip file attached to this tutorial for download.
If you wish to make the optimizations yourself, follow the steps below:
- Add a conditional disable structure from the Structures palette around the wait in the second frame.
- Right-click the top of the frame to add a sub-diagram. Right-click on each of the cases and select Edit Condition For This Subdiagram to edit the conditions that allow execution for each sub-diagram.
- The wait should execute when the FPGA_EXECUTION_MODE is equal to FPGA_TARGET and should not execute when it is THIRD_PARTY_SIMULATION. There no need to simulate the settling behavior of the NI 6581, and disabling this wait will speed up the simulation.
Configure the LabVIEW FPGA Module for Simulation
- Before you build a simulation export, configure the simulator. Go to Tools»Options»FPGA Module. Under Simulation, select ModelSim as the simulator. If ModelSim is installed correctly, LabVIEW should be able to find and populate the Simulator directory field. If it does not, you can set the value manually.
- Before creating simulation exports, you must also configure the FPGA simulation libraries. From the menu, select Tools»FPGA Module»Update FPGA Simulation Libraries. This compiles the VHDL libraries that the simulation model needs. You need to do this only once. Note: Updating the Simulation Libraries will take 5-10 Minutes.
- In LabVIEW 2011 and later, the FPGA Target must also be configured to execute on the third-party simulator before creating simulation exports. From the project view, right-click on the FPGA Target and select Execute VI on » Third-Party Simulator.
Verify or Add Simulation Support for the Adapter Module (CLIP Declaration Wizard)
To successfully simulate the VI, it is necessary to make sure the configured adapter module has simulation support. If the adapter module does not have a simulation model defined at the time of initiating the simulation export, an error will occur during code generation and you will not be able to simulate your VI. An error dialog is shown for reference in the figure below.
If a simulation model does not yet exist for the NI FlexRIO Adapter Module you want to simulate, then you must write a simulation model and use the CLIP declaration wizard to update the CLIP XML. The CLIP Declaration Wizard can be used to update the CLIP XML with new tags and version information required for simulation support. Once you have a simulation model in place for your adapter module you can continue with creating the simulation export. Creating a simulation model for any given FlexRIO Adapter Module requires detailed knowledge and understanding of the workings of the Adapter Module.
Note: NI does not provide simulation models for the NI FlexRIO Adapter Modules. The following steps walk through how to use the wizard to create a simulation model for the NI 6581. These steps also generically apply to creating simulation models for the NI 6583, NI 6584, and NI 6585 FlexRIO Adapter Modules.
- Before making any changes to the XML of the Socketed CLIP XML for your FlexRIO Adapter Module, you should create a backup which you can revert to if necessary. For the purposes of this tutorial we will actually modify the backup copy to avoid changing the original.
- Copy the NI6581Port folder from the following directory:
32-bit Windows:
C:\Program Files\National Instruments\Shared\FlexRIO\IO Modules\NI 6581\NI6581Port
64-bit Windows:
C:\Program Files (x86)\National Instruments\Shared\FlexRIO\IO Modules\NI 6581\NI6581Port - To the user directory:
Windows XP/2000:
C:\Documents and Settings\All Users\Shared Documents\National Instruments\FlexRIO\IO Modules\NI6581 Port
Windows 7/Vista:
C:\Users\Public\Documents\National Instruments\FlexRIO\IO Modules\NI6581 Port
- Once you have copied the CLIP to your user directory, right-click your FPGA target and select Properties to bring up the FPGA Target Properties dialog window.
- Select the Component-Level IP category. Using the buttons on the right, add the component-level IP for the NI 6581 by selecting the Add file icon and loading the XML from the new location for your CLIP.
- To update the XML using the wizard, select Modify File. This will launch a series of windows to guide you through updating the XML. For more details, see the Using the Configure Component-Level IP Wizard topic in the LabVIEW Help.
Although you will need to complete all 8 steps of the wizard, only the first page is covered here, as it covers the options related to simulation. The first page covers the CLIP declaration name and the source files. - For the NI 6581 Port, change the Declaration Name at the top to NI 6581 Port with Simulation. This will help to identify the CLIP in a later step.
-
For each synthesis file you can individually set the simulation behavior. The options are:
- Same as synthesis (default for vhd file extensions)
- User-defined
- Exclude from simulation model (default for non-simulatable file extensions such as .ngc).
Clicking Help will bring up more detailed information on these three options.
For any files that are pre-compiled or otherwise not able to be simulated, a new file must be created in order to allow simulation of that component of the CLIP. Once these simulation files are ready, the simulation behavior should be set to user-defined, and the simulation file(s) should be added.
For the NI 6581 Port CLIP, the synthesis files can be used directly for simulation, so keep the remaining default settings that the Wizard has selected, and click Next.
- Continue clicking Next to step your way through the wizard. On page 3, Generics and Syntax Check, the Next button will be grayed out. You will need to first click Check Syntax.
This will take a few seconds to verify all of the files and enable the Next button for you to proceed. Click the Next button.
- Continue clicking Next to step your way through the wizard. Complete the Wizard on page 9, XML Export, by clicking Finish. This will create a new .XML file with all of the simulation tags populated.
- You may get a warning that the XML is a newer version. Click OK to continue.
- Click OK to allow the save to continue and to overwrite the existing file since you are already working with a backup copy.
- Now you should have a CLIP which includes simulation support. However, the project is still configured to use the original CLIP. In the FPGA Target Properties, remove the CLIP that you added by highlighting it in the list and clicking the Remove File icon. Click OK to return to the Project Explorer.
- Right-click the IO Module and select Properties to reconfigure the IO Module to use the new CLIP with simulation support.
Ensure that the Enable IO Module checkbox is checked then select the NI 6581 from the list of available IO Modules. Under the Component Level IP list, change the selection from NI 6581 Port to NI 6581 Port with Simulation and click OK.
Create and Build Simulation Exports
- To create a simulation export, locate the build specification under FPGA Target. You use the build specification to create the simulation testbench and specify various options for it. To create the build specification, right-click Build Specifications under the FPGA Target and select New»Simulation Export.
- This opens a dialog box where you can configure simulation export settings. Notice that the build specification name is currently “My Simulation Export”. First, set the top-level VI to simulate by going to the Source Files tab, selecting NI 6581 Acquisition and Generation Simple (FPGA).vi, and clicking the Add Item button. Also, under the Source Files tab, you can specify different signals that will be automatically added to the simulation waveform. Leave these as the default value.
-
Go back to the Information tab and see that the build specification name has changed to match the name of your VI. Note that, under the Information tab, you can also set the top-level simulation model name and Destination directory. The top-level simulation model name is the name of the VHDL file that will be generated for the VI. Leave this field as the default value. You can specify where to generate simulation files in the destination directory.
Note: Ensure that the destination directory is not read-only. If the destination directory is read-only, it will prevent later steps of the tutorial from working correctly.
- The Model Fidelity tab contains information about the I/O fidelity level, bus model, and framework.
- Click Build to save the build specification and generate the testbench files. You should see a dialog window indicating when the simulation export has been successfully built. Click Done in that dialog window.
- Next, navigate to the simulation directory by right-clicking on the build specification and selecting Explore.
- Look at the folders generated in the simulation export directory.
The ModelSim folder contains files used by the ModelSim simulation tool. You do not need to view or edit any files in this folder. The niFpga folder contains VHDL files generated by the LabVIEW FPGA Module to implement the simulation model. These files are regenerated each time the simulation export is built and should not be modified.
The user directory contains files that you can edit, including the top-level testbench file. In this case, the file is named tb_NiFpgaSimulationModel.vhd. This file is a template to implement a testbench and will be described later. This file is only generated the first time the build specification is built and will not be overwritten by the LabVIEW FPGA Module. A copy of the template is generated on each build in the niFpga directory for reference.