Draw an image using FPGA

Overview

We gonna use FPGA to draw images. Because the memory is limited, we should resize our images to a smaller resolution. And I will pick 200x112.

Firstly, we should write the image bits to the ROM. For simplicity, we use the pure green image. And then design our drawing logic. Thanks to our graphics design pattern, we don't need to change too much beside the "Drawing Logic". In Drawing Logic, we read the pixel RGB values from ROM and decide what to output. And that's it. Let's dive into the details.

Write image RBG bits to ROM

We will use vivado's built-in ROM ip core, and it's easy to write an image to the ROM. However, we need to convert the image to coe format. It's not quite hard. And here is the converted file of the image below. [green.coe]

Use built-in ROM ip core

Name it "rom", set memory type as "Single Port ROM"

Specify the memory size

Use our coe file to initialize memory content

Drawing Logic

We need to read the memory every pixel clock. The image size is smaller than the screen size, so we should specify the location and area of our image. The other part of the screen should painted as background color. [painter_720p.sv]

Third-party rgb2dvi ip core

We gonna use third-party ip cores. IP cores are just reusable modules. It's easy to add third party ip cores into your project.

Add Repository, i.e., add third-party ip cores

The repository is at rgb2dvi, comes from digilent/vivado-library.

Use the "RGB to DVI Video Encoder"

Leave it at the default settings

Generate pixel clock and 5x pixel clock

Put it all together

Here is top.sv. The full code is at hdmi_draw_image.

The output is look like this.

Try your image (Optional)

Resize your image

We have to resize the image to fit into the limited memory. There are many useful website that can resize your image for free. Just google it.

Convert your image to coe format

It's easy to use python pillow library to convert a image to coe format. Here is the template:

It's not complete, feel free to modify it.

Now you can use the coe file to inititalize ROM. You may need to change the drawing logic parameters if you want to change the resolution or the image position.

Guess what is it? [test.coe]

References

Last updated