FPGARelated.com
Forums

Xilinx, VHDL, Verilog, ModelSim, BMP

Started by Brad Smallridge ●November 16, 2004
I would eventually like to be able to read a BMP file directly into the 
ModelSim simulator.  I understand now with VHDL the only file you can read 
are text files.  Is there a way to read in binary data in another way, 
perhaps by using Verilog?

Brad Smallridge


Hi Brad,

Brad Smallridge wrote:
> I would eventually like to be able to read a BMP file directly into the > ModelSim simulator. I understand now with VHDL the only file you can read > are text files. Is there a way to read in binary data in another way, > perhaps by using Verilog?
It depends where your time is most profitably spent - VHDL can handle binary file IO, but the question is if you want to write your own BMP library in VHDL, or if you can obtain one at a cost you find acceptable. There are many variants in BMP, compression types, colour widths, the works... I'd be more inclined to use some existing (free) tool like the ImageMagick suite to convert your input BMP into a trivial RAW format, either ASCII or binary, and read those into your test benches. You can of course automate the conversion process with scripts, so it doesn't have to be fiddly at all. Regards, John
Hi,

Well, let me know if you figure this one out.  I had
a similar issue -- I wanted a Verilog simulation to
write out a TIFF file.  I couldn't find a way to write
out a binary file, so wrote out ASCII data values to
text file and then post-processed it into a binary
TIFF file using a small program I wrote in C.

Hoping there's a better way...
Eric

Brad Smallridge wrote:
> > I would eventually like to be able to read a BMP file > directly into the ModelSim simulator. I understand > now with VHDL the only file you can read are text files. > Is there a way to read in binary data in another way, > perhaps by using Verilog? > > Brad Smallridge
Brad Smallridge wrote:
> I would eventually like to be able to read a BMP file directly into the > ModelSim simulator.
Here's one possibility: http://groups.google.com/groups?q=vhdl+char_array -- Mike Treseler
On Tue, 16 Nov 2004 16:57:01 -0800, "Brad Smallridge"
<bradsmallridge@dslextreme.com> wrote:

>I would eventually like to be able to read a BMP file directly into the >ModelSim simulator. I understand now with VHDL the only file you can read >are text files. Is there a way to read in binary data in another way, >perhaps by using Verilog?
VHDL certainly can read binary data; Mike Treseler's example is excellent, and starting from it made reading my binary data very easy. If you can constrain the BMP files you want to read to a specific format (24bits/pixel is probably simplest) go for it, otherwise you may have to interpret many different formats, which is a bit more work... - Brian
Mike Treseler <mike_treseler@comcast.net> wrote in message news:<df6dnalj_9evUQfcRVn-pw@comcast.com>...

> Here's one possibility: > http://groups.google.com/groups?q=vhdl+char_array > > -- Mike Treseler
VERY good example !!! will help me a lot !! just one remark: shouldn't it be function spew(i_arg : integer) return char_array is variable result : char_array(0 to i_arg-1); variable index : char_index; begin for i in 0 to i_arg-1 loop index := i mod (char_index'right + 1); -- <<<<<<<<<< ?? result(i) := character'val(index); end loop; return result; end function spew; to get full 8-Bit numbers ? ** Jochen Frensch **
Looks promising.
How do I generate the test file char_file.bin ? 


Belay that silly question. Duh.
The program generates char_file.bin

> How do I generate the test file char_file.bin ?
Jochen Frensch wrote:

>>Here's one possibility: >>http://groups.google.com/groups?q=vhdl+char_array >> >> -- Mike Treseler > > VERY good example !!! > > will help me a lot !!
Thanks, I'm happy to hear about it.
> just one remark: shouldn't it be > > function spew(i_arg : integer) return char_array is > variable result : char_array(0 to i_arg-1); > variable index : char_index; > begin > for i in 0 to i_arg-1 loop > index := i mod (char_index'right + 1); -- <<<<<<<<<< ?? > result(i) := character'val(index); > end loop; > return result; > end function spew; > > to get full 8-Bit numbers ?
To cover all 256 characters, yes! Notice there is a seam in my hex file between FE and 100, and I think you have the fix. Try it and see. -- Mike Treseler
> Hi, > > Well, let me know if you figure this one out. I had > a similar issue -- I wanted a Verilog simulation to > write out a TIFF file. I couldn't find a way to write > out a binary file, so wrote out ASCII data values to > text file and then post-processed it into a binary > TIFF file using a small program I wrote in C.
The attached code is kind of kludge, but it works, with modelsim 5.8e anyway. HTH, Jim jimwu88NOOOSPAM@yahoo.com (remove capital letters) http://www.geocities.com/jimwu88/chips module wr_bin (); reg [7:0] data; integer fd; integer i; initial begin fd = $fopen("test.bin", "wb"); for (i = 0; i < 256; i = i + 1) begin data = i; if (data == 0) begin $fwriteb(fd, "%u", data); $fseek(fd, 1, 0); end else $fwriteb(fd, "%c", data); end $fclose(fd); $display("Done"); $finish; end endmodule