Verilog file operations

M

maxascent

Guest
Hi

I want to write some data to a file using Verilog. This file will be a JPE
file so the data in the file needs to be the actual data I write. I hav
tried using $fwrite but the data ends up as ASCII when I look at it in
hex editor. So if I write 0xFF it ends up as 66 66 in the file. Can anyon
tell me how to do this?

Thanks

Jon

---------------------------------------
Posted through http://www.FPGARelated.com
 
I want to write some data to a file using Verilog. This file will be a JPEG
file so the data in the file needs to be the actual data I write. I have
tried using $fwrite but the data ends up as ASCII when I look at it in a
hex editor. So if I write 0xFF it ends up as 66 66 in the file. Can anyone
tell me how to do this?
Try google.. here is what I found (last post using character binary mode)
http://www.velocityreviews.com/forums/t22651-binary-file-io-in-modelsim.html
 
I want to write some data to a file using Verilog. This file will be a
JPEG
file so the data in the file needs to be the actual data I write. I have
tried using $fwrite but the data ends up as ASCII when I look at it in a
hex editor. So if I write 0xFF it ends up as 66 66 in the file. Can anyone
tell me how to do this?
Just a guess: maybe there is hwrite()?
 
Morten Leikvoll wrote:
I want to write some data to a file using Verilog. This file will be a
JPEG
file so the data in the file needs to be the actual data I write. I have
tried using $fwrite but the data ends up as ASCII when I look at it in a
hex editor. So if I write 0xFF it ends up as 66 66 in the file. Can
anyone
tell me how to do this?

Try google.. here is what I found (last post using character binary mode)
http://www.velocityreviews.com/forums/t22651-binary-file-io-in-modelsim.html


$fwrite uses the same format string as $write, so it's important to use
the correct format. Obviously if you do something like:

reg [7:0] foo = 8'hFF;
$fwrite ("%x", foo);

You'll get hex characters in the file. I haven't tried this but if you
use a string or character type instead you should just get the binary
data in the file. Note that this only works for multiples of 8 bits:

reg [7:0] foo = 8'hFF;
$fwrite ("%c", foo);

reg [23:0] bar = 24'h123456;
$fwrite ("%s", bar);

HTH,
Gabor
 
"maxascent" <56@embeddedrelated> writes:

I want to write some data to a file using Verilog. This file will be a JPEG
file so the data in the file needs to be the actual data I write. I have
tried using $fwrite but the data ends up as ASCII when I look at it in a
hex editor. So if I write 0xFF it ends up as 66 66 in the file. Can anyone
tell me how to do this?
integer fd;

initial begin
fd = $fopen("data.out","wb");
$fwrite(fd,"%u",32'h61_62_00_63);
$fclose(fd);
end

//Petter
--
..sig removed by request.
 
After some experimenting and searching the web, the following works.

file_out = $fopen("test.jpg", "wb");
$fwriteb(file_out, "%c", ram_byte);

Thanks

Jon

---------------------------------------
Posted through http://www.FPGARelated.com
 

Welcome to EDABoard.com

Sponsor

Back
Top