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!

cancel
Showing results for 
Search instead for 
Did you mean: 
Moderator
Moderator
744 Views
Registered: ‎11-09-2015

Video Beginner Series 14 - Creating a Pattern Generator using HLS (Part 1)

Introduction

 

This Video Beginner Series 14 shows how to create a Video Pattern Generator using Vivado HLS. The Video Pattern Generator will be created in C++ and validated using HLS Open CV library. It will then be converted to RTL (Verilog or VHDL) using Vivado HLS in the next Video Series.

 1.jpg

 

There are multiple User Guides to understand HLS. The main docs are UG998 - Introduction to FPGA Design with Vivado High-Level Synthesis, UG902 - Vivado Design Suite User Guide - High-Level Synthesis and UG871 - Vivado Design Suite Tutorial - High-Level Synthesis.

 

Note: This video series assumes that you have some knowledge in C/C++ coding.

 

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

 

Summary

 

1. Tutorial - Creating a Pattern Generator using Vivado HLS

2. What Next?

 

 


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
2 Replies
Moderator
Moderator
738 Views
Registered: ‎11-09-2015

Video Beginner Series 14 - Tutorial - Creating a Pattern Generator using Vivado HLS

Tutorial –Creating a Pattern Generator using Vivado HLS

 

Note 1: This tutorial is intended to be used only with Vivado 2018.1

 

Open the Vivado HLS project

 

  1. Download the tutorial files and unzip the folder

  2. Open Vivado HLS 2018.1

  3. Click on Open Project

  4. Open the project Video_Pattern_Generator from the unzipped folder

In this project, 3 files have been added:

  • A header filer video_pattern_generator.h
  • A source file video_pattern_generator.cpp containing the function to be synthesized as Video Pattern Generator
  • A source file video_pattern_generator_tb.cpp containing a test bench to test the functionality of the Pattern Generator in HLS

You can see the files in the Explorer window
2.png

 

Add the code to generate the image

The function video_pattern_generator does not contain any code to generate the video output but only the structure. We will add the code to generate a red video pattern.

  1. Open the source file video_pattern_generator.cpp from the explorer window

We can see that two variables are defined

 

     ap_axiu<24, 1, 1, 1> video;
     hls::rgb_8 pixel;

 

 

ap_axiu is a structure which contains all the signals needed for an AXI4-Stream interface. It will be representing the signals we are sending to the AXI4-Stream output of the core.

 

template<int D,int U,int TI,int TD>
struct ap_axiu{
     ap_uint<D> data;
     ap_uint<D/8> keep;
     ap_uint<D/8> strb;
     ap_uint<U> user;
     ap_uint<1> last;
     ap_uint<TI> id;
     ap_uint<TD> dest;
};

 

 

 

rgb_8 is a structure which contains the 3 RGB components. It will represent the pixel value we are setting on data signal of the AXI-Stream interface

 

typedef struct{
  unsigned char R;
  unsigned char G;
  unsigned char B;
}rgb_8;

 

 

 

  1. An image is an array of pixel. To give a value to each pixel we can use two for loops.
    Add the following for loops:
    //Add code for output video generation here
    for(int i = 0; i < HEIGHT; i++)
    {
             for(int j= 0; j < WIDTH; j++)
             {             
             }
    }

 

  1. In our example, the variable pixel is of type hls::rgb_8 which is a structure of 3 elements of type char.

    We can give a value for each color component of the pixels using the following code (in bold):
     for(int j= 0; j < WIDTH; j++)
    {
            pixel.R = 255;
            pixel.B = 0;
            pixel.G = 0;
    }
  1. Now can assign the pixel value to the data signal of the AXI4-Stream interface and send this to the output stream.
    for(int j= 0; j < WIDTH; j++)
    {
             pixel.R = 255;
             pixel.B = 0;
             pixel.G = 0; 
    
             // Assign the pixel value to the data output
             video.data = set_rgb_8_pixel_value(pixel);
    
             //Send video to stream
             m_axis_video << video;
    }

 

The code we have added will send the video data to the stream. However, this is not enough to be a video data on the AXI4-Stream. We also need to take care of the Start of Frame (tuser) and End Of Line signals

 

  1. Add the following code
    for(int j= 0; j < WIDTH; j++)
    {
            // Start of frame, assert tuser
            if((i==0)&&(j==0))
                   video.user=1;
            else
                   video.user=0;
     
            //End of line, assert tlast
            if(j==WIDTH-1)
                   video.last = 1;
            else
                   video.last = 0;
    
            pixel.R = 255;
            pixel.B = 0;
            pixel.G = 0;
    
            // Assign the pixel value to the data output
            video.data = set_rgb_8_pixel_value(pixel);
    
     
    
            //Send video to stream
            m_axis_video << video;
    
    }

 

Validate the C++ code

We can now test the code in C simulation and see if it is working

  1. Click on Project > Run C simulation or on the icon 5.png directly

  2. In the C simulation Dialog window, keep the default parameters and click OK
    3.png

 

  1. The test bench will generate an output image called out.png. We can open it from the explorer window under solution 1.
    4.png

 

  1. We can see that we the function has correctly generated a red pattern as expected
    6.png

 

Note: In the test bench, the function AXIvideo2IplImage()  is used to convert from the AXI4-Stream interface to the image. In Vivado HLS 2018.1, this function is not following the UG934 for color mapping. This means that the green and blue colors will be switched on the output image if the function to be synthesized is following UG934 (it is the case for the Video Pattern Generator we have created).

 

 


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**
Moderator
Moderator
730 Views
Registered: ‎11-09-2015

Video Beginner Series 14 - What Next?

What Next?

 

  • Do you have issues/questions following this Vivado Beginner Series?
    1. Search on the Xilinx forums for similar questions
    2. Create a new topic on the HLS Board or Video Board for your issue/question with the title starting with [Video Beginner Series 14] and followed by a quick description of your issue/question

 

  • You liked this Video Series?
    • You can give Kudos using the Kudos button  kudos.PNG
    • Make sure you are following the Xilinx Video Series topic to be informed when an new topic is published (Go to the Xilinx Video Series topic > Options > Subscribe)

subscribe.PNG

 


Florent
Product Application Engineer - Xilinx Technical Support EMEA
**~ Don't forget to reply, give kudos, and accept as solution.~**