FPGA Central - World's 1st FPGA / CPLD Portal

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > Verilog

Verilog comp.lang.verilog newsgroup / usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-29-2007, 12:34 PM
vinoth
Guest
 
Posts: n/a
Default read hex data from a file

Hi..

how do i read hex data from a file..say for example the file
contains the following data...
e46e16c5891b3c295ed5f6c1db0087c3320
I want to read 32 bits at a time...
can anyone give me a suggestion..

Reply With Quote
  #2 (permalink)  
Old 03-29-2007, 04:41 PM
[email protected]
Guest
 
Posts: n/a
Default Re: read hex data from a file

On 29 Mar, 11:34, "vinoth" <jesuraj.vin...@gmail.com> wrote:
> Hi..
>
> how do i read hex data from a file..say for example the file
> contains the following data...
> e46e16c5891b3c295ed5f6c1db0087c3320
> I want to read 32 bits at a time...
> can anyone give me a suggestion..


Is the file you are reading binary, or is it a text file contain the
hex values?
Does the format of the data in the file have to be exactly as you have
defined, or can it be broken up with whitespace (for example)?

e46e16c5
891b3c29
5ed5f6c1
etc

If it's a text file and you can control the format, then look up
$fscanf (Verilog 2001 only - much the same as the C function of the
same name) or $readmemh.
If it's a binary file then you have to use $fread (Verilog 2001 only).


Reply With Quote
  #3 (permalink)  
Old 03-30-2007, 07:24 AM
morpheus
Guest
 
Posts: n/a
Default Re: read hex data from a file

The best way to read this as a file would be to define the bit width
of the pattern you are trying to read:
For example if your hex data is 32 bits wide, your file should store
values as follows
12345678
23456789
abcdef12, etc. Save this file as a "<filename>.dat" and store it in
the simulation working directory.
You will need to initialize your memory array in your code as follows
reg <bit width:0> memory <array size>;
Now, use the $readmemh command to read this file. Remember, the
different entries in your file should be separated by whitespace.

Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Verilog 2001 File I/O: read large file? Davy Verilog 15 04-07-2006 04:03 AM
Call a file and read data from it [email protected] Verilog 4 02-27-2006 07:38 PM
Verilog $fread Does Not Read Full File Dave Gowans Verilog 3 11-12-2005 04:03 PM
[Verilog] How to read data from a file? Davy Verilog 0 07-07-2005 01:51 PM
How to read from file in Verilog Stew Verilog 2 11-08-2004 08:27 PM


All times are GMT +1. The time now is 03:10 AM.


Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
Copyright 2008 @ FPGA Central. All rights reserved