Jump to content
  • 0

Zybo ROM


s223523

Question

Ho everyone,

I am working on a zybo to program a game. I am facing the task of image processing. I understand that the best way is using ROM to store coe file and use them, but I don't know how to convert an image to a coe file. Another question is if the 16 bit output of the single port ROM is already the encoding of the vga output or I need to makes some changes, and how to process the printing of the image. And I was also wondering if I can put more then one image in the ROM. 

 

Thank you

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

@s223523,

Games on a Zybo?  I love it!  Will you come back and post to the project vault when you are done?

As for the ROM ... I'm not quite certain what you want to do, so I'm going to need to make a lot of assumptions.  First, I'm going to assume that what you wish to do is in the FPGA side of the Zynq and not the Arm side.  Second, I'm going to assume that you want to use block RAM's within the FPGA as your read-only structures.  If this isn't what you mean, please pipe up.  (I suppose you might've meant the flash ... but that's *really* slow when you want to do high speed image processing.)

I recently went through a similar struggle trying to figure out how to create a UART test design that would print the Gettysburg address out the UART port.  The Gettysburg address itself is a constant, so I also wished to place it into a ROM.  The way to set a ROM is via a $readmemh command (well, from Verilog at least).  However, the data format necessary to support this command isn't nearly as well documented as I wished.  Worse, ISE doesn't seem to support $readmemh at all, so I ended up with two solutions: one for Verilator, and one for ISE.  You can find the example code in this project.  I used a small C++ program to create the data file for the $readmemh command (or it's ISE equivalent--a long list of initial statements ...).  The data file was then read in as part of this top-level Verilog module, although there's nothing preventing you from doing this in a submodule buried seven levels deep within your design.

Even though the example is for a UART, I think you will find within it just about all of the parts and pieces of what you want to do with a ROM within it.

Holler, though, if I mis-understood your question,

Dan

Link to comment
Share on other sites

@s223523

Apologies I didn't explain more earlier.

Here is some mostly functional VGA code for a personal project that I haven't had time to revisit recently (creating a "simple" text editor in HDL, it stopped moving forward when I started trying to write link lists in verilog), the code is fairly poorly commented, but it implements a ROM to look up pixels from a character table, ASCII and address within the pixel in, single bit color out. Note that the project itself is overly complicated and might not even be totally functional.

There are a few design decisions to make here. First, how many colors do you want to use? You don't have to have each pixel in the ROM have the same depth as the VGA bus, if you have spare cycles in the VGA loop, you can select a full color from based on the reduced version stored in the pixel memory. In my implementation, I chose to only handle black and white, with some additional logic to invert the color at the cursor. As such each of my pixels in the character memory is only a single bit deep, though I did pack several pixels into one address. You can absolutely store multiple images in one memory, as seen in the character memory, but it will be a lot easier to compute addresses into that memory if the images have a size of 2^N addresses. Line 68 of the linked file shows how I calculate the position of a particular horizontal line of pixels for an 8x8 character, just by appending the ASCII value and horizontal position together. The actual size of your memory, exactly how you address it, and how you use it's data depends heavily on what exactly you are trying to do.

Since I posted that project, I have been revising it some to take advantage of the Zybo, including using a dual port ram to store images, which the Zybo will fill up on startup, this gets into an entirely different level of complexity though, as it requires an AXI interface, or something else to communicate with the processor.

As for creating data files (COE or otherwise, depending on your ROM implementation), you will need to write some more code. The ways I have personally had some success doing this is to write a C program or Python script to parse an image file and turn it into an ascii hex file. (The file format used by the readmem commands is not too dissimilar to the COE format). Python has some decent libraries available for reading from different image formats, and is fairly easy to pick up if you don't already know it. As for C, I know that the Gimp image editor has an option to save an image as a C header, which removes about half of the problem, from there its just down to writing your data file in the correct format.

Hope this helps, 

Arthur

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...