How to read from file in Verilog

S

Stew

Guest
I am writing a test bench in Verilog, and want to read in hex values as
stimulus. I can't seem to find a whole lot of documentation on how to do
this. I want to basically open a file in read only mode, read in the values
(preferable convert to hex) and load them into a register for processing.
I'm using Modelsim as a simulator.

Thanks in advance,

Stew
 
"Stew" <bob.junk@cox.net> wrote in message news:<NZWid.1054$0Y5.614@lakeread07>...
I am writing a test bench in Verilog, and want to read in hex values as
stimulus. I can't seem to find a whole lot of documentation on how to do
this. I want to basically open a file in read only mode, read in the values
(preferable convert to hex) and load them into a register for processing.
I'm using Modelsim as a simulator.
Try:

reg [7:0] temp[0:1023];
$readmemh("stimulus.dat", temp);

Where stimulus.dat contains:

23
a4
4b

etc.

Cheers,
Jon
 
"Stew" <bob.junk@cox.net> wrote in message news:<NZWid.1054$0Y5.614@lakeread07>...
I am writing a test bench in Verilog, and want to read in hex values as
stimulus. I can't seem to find a whole lot of documentation on how to do
this. I want to basically open a file in read only mode, read in the values
(preferable convert to hex) and load them into a register for processing.
I'm using Modelsim as a simulator.
Before Verilog-2001, the only way to do this was with the $readmemh
system task, which would read a text file containing hex numbers into
a Verilog memory. This would read all your stimulus into the memory
at once. Then you would step through the memory words one at a time,
applying them as stimulus.

With Verilog-2001, you have more flexibility available. You can use
$fopen and $fscanf much as you would in C, to read one vector at a
time out of an open file in a variety of possible formats. This would
take a little more effort to code, and you may not need the flexibility.
 

Welcome to EDABoard.com

Sponsor

Back
Top