UPGRADE YOUR BROWSER
We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!
05-02-2018 01:04 AM - edited 05-02-2018 01:39 AM
Introduction
This Video Beginner Series 3 shows how to input image data (from a PPM (ASCII) file) to a RTL simulation with Vivado Simulator (VSIM).
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Summary
4. Tutorial - Read file in RTL simulation with Vivado Simulator
05-02-2018 01:09 AM - edited 05-10-2018 12:09 AM
PPM file format
Portable PixMap (PPM) is a graphic format defined by the Netbm open-source project. This is an uncompressed picture file format thus it is quite straight forward to use it for RTL simulation.
The content of a PPM file is:
Note: A line starting with # is a comment line (not displayed in the picture)
Example with a small image:
The content of the PPM file (ASCII format) can be:
P3 3 3 255 #RED 255 0 0 #YELLOW 255 255 0 #GREEN 0 255 0 #WHITE 255 255 255 #CYAN 0 255 255 #BLACK 0 0 0 #BLUE 0 0 255 #MAGENTA 255 0 255 #RED 255 0 0
GIMP is an open source tool which can allow you to view PPM files. For example, if we create a PPM file with the previous data using a text editor (the PPM file is provided in the design files XVES0003/img/image_1.ppm), we can then view the small image with GIMP.
Note: To see the picture in GIMP you might need to zoom in.
05-02-2018 01:12 AM - edited 05-02-2018 01:39 AM
Reading files in VHDL
VHDL has the procedure FILE_OPEN to open an external file defined as below:
FILE_OPEN (Status, file, External_Name, Open_Kind);
This procedure has the following parameters:
When opened, a file can be read line by line using the procedure READLINE defined as below:
READLINE(file, line);
This procedure has the following parameters:
Then we can read each element of a line using the procedure READ defined as below:
READ(line, value);
This procedure has the following parameters:
Finally the file can be closed using FILE_CLOSE
FILE_CLOSE(file);
05-02-2018 01:15 AM - edited 05-02-2018 01:40 AM
Reading files in Verilog
Verilog has the system task $fopen to open a file in read mode defined as below
fd = $fopen (file_name, type);
This task has the following parameters:
And output:
When opened, a file can be read line by line using the task $fgets defined as below:
$fgets(str, fd);
This procedure has the following parameters:
Then we can read each element of a line using the task $sscanf defined as below:
$sscanf (str, format, arg);
This procedure has the following parameters:
Finally the file can be closed using the task $fclose
$fclose(fd);
05-02-2018 01:29 AM - edited 05-10-2018 12:10 AM
Tutorial - Reading file in RTL simulation with Vivado Simulator
Note: This tutorial is intended to be used only with Vivado 2018.1, in simulation only and only with the provided images
Build the Vivado project
1. Download the tutorial files and unzip the folde
2. Open Vivado 2018.1
3. In the tcl console, cd into the unzipped directory (cd <path>/XVES_0003)
4. In the tcl console, source the script:
5. In the Sources window you can see that the project only contains one file (tb_read_file) in the simulation sources (no Design Sources or Constraints files)
Add the input file to the project
6. Open the file XVES_0003/img/image_2.ppm with a text editor
Notes:
7. In Vivado, add this file to the simulation source files
8. Launch the behavioral simulation (Run Simulation > Run Behavioral Simulation)
9. In the tcl console you can find information printed by the test bench starting by “Note:”
Q1. Find the line printing the value of pixel 1 (Note: Pixel #1: …). What is the value for the 3 components (Red, Green and Blue)?
Q2. What color corresponds to these 3 values? Is it expected?
Q3. Confirm that only 9 pixels values are printed (size of the picture (3x3))
10. Close the simulation
11. Add the file XVES_0003/img/image_3.ppm to the project simulation source files
12. Open the test bench file in the text editor and find the following line:
constant file_path_c : string := "image_2.ppm";
reg[8*11:1] file_name = "image_2.ppm";
13. Change this line to:
constant file_path_c : string := "image_3.ppm";
reg[8*11:1] file_name = "image_3.ppm";
14. Launch the behavioral simulation
15. In the waveform window, you can see the size of the new image input as signal values
Q4. What is the width (hsize_s) and the height (vsize_s) of the new image input?
05-02-2018 01:32 AM - edited 06-20-2018 04:01 AM
What Next?