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

FPGA Central

World's 1st FPGA Portal

 

Go Back   FPGA Groups > NewsGroup > VHDL

VHDL comp.lang.vhdl newsgroup / Usenet

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-28-2005, 09:32 PM
Brandon
Guest
 
Posts: n/a
Default Initialize array using file i/o procedure/function?

I would like my testbench to be able to load data from text i/o into
two 1-d arrays of type real, of any length.

I looked through the text i/o example in "The Designer's Guide to Vhdl"
by Ashenden, but I'm still a little fuzzy.

I generated the data in exponential format in Matlab into a text file:

-3.295898437500E-003 4.272460937500E-003
.... ...


I would declare the two procedure output arrays in my signal list of my
test-bed. I then plan on looping through each value in the arrays every
clock cycle:

-- test bench architecture types,signals
type ARRAYOFREAL_T is array (natural range <>) of real;
signal real_stuff: ARRAYOFREAL_T(LENGTH-1 downto 0);
signal imag_stuff: ARRAYOFREAL_T(LENGTH-1 downto 0)

-- define the procedure as follows, but not sure how to write
-- coe_fn is the filename string
-- re, im are the arrays of real I want to contain the loaded values
procedure is load_coe_from file(coe_fn: in string;
re: out ARRAYOFREAL_T; im: out ARRAYOFREAL_T) is
....
begin
....

end procedure load_coe;

Any thoughts? Thanks.

Reply With Quote
  #2 (permalink)  
Old 09-29-2005, 04:47 AM
Mike Treseler
Guest
 
Posts: n/a
Default Re: Initialize array using file i/o procedure/function?

Brandon wrote:
> I would like my testbench to be able to load data from text i/o into
> two 1-d arrays of type real, of any length.


> Any thoughts? Thanks.


Consider using vhdl constant arrays
instead of text i/o. This gives you
compile time and run time checks for free.

-- Mike Treseler
Reply With Quote
  #3 (permalink)  
Old 09-29-2005, 02:42 PM
Brandon
Guest
 
Posts: n/a
Default Re: Initialize array using file i/o procedure/function?

Well, the DUT is a filter, and I've already tested it with a general
constant array. Instead, I'm trying to get familiar with text i/o
because I would like my design to be able to load different coefficient
data from the text file. Depending on the application, it might be
necessary to change the coefficient set used by the filter.

For now, I'd like to just stick with one set of coefficients. The
test-bench would have a method to read the text file during
elaboration, parse through to get the values, and store them in a
constant array, which I can then access during my event process to load
the new filter coefficients.

Reply With Quote
  #4 (permalink)  
Old 09-29-2005, 04:15 PM
Brandon
Guest
 
Posts: n/a
Default Re: Initialize array using file i/o procedure/function?

Ok. Here is what I have inside my testbench entity, which I'm able to
compile. However, I am receiving an error when I try to load the
design. Note that the text file is located in the same directory as the
vhdl:

# Loading work.dut_tb(beh_ar)
# ** Error: (vsim-7) Failed to open VHDL file "cfir.coe" in rb mode.
# No such file or directory. (errno = ENOENT)
# Time: 0 ns Iteration: 0 Instance: /dut_tb

<SNIP>
....

-------------------------------------------------------------------------
-- load constant coefficient array process

-------------------------------------------------------------------------
load_coe: process
use std.textio.all;
file coe_file: text open read_mode is COE_FILE_NAME_C;

variable curLine_v : line;
variable curLineNum_v : natural := 0;
variable read_ok_v : boolean;
variable real_v : real;
variable imag_v : real;

begin
curLine_loop: while (curLineNum_v <= NUMTAPS_C-1) and
not (endfile(coe_file) ) loop
-- Read the current line
readline(coe_file,curLine_v);

-- Read real coefficient
read(curLine_v,real_v,read_ok_v);
if not read_ok_v then
report "fircplx_tb: Error reading real coefficient from line: "
& curLine_v.all
severity warning;
end if;

-- Read imag coefficient
read(curLine_v,imag_v,read_ok_v);
if not read_ok_v then
report "fircplx_tb: Error reading imag coefficient from line: "
& curLine_v.all
severity warning;
end if;

hre_array_s(curLineNum_v) <= real_v;
him_array_s(curLineNum_v) <= imag_v;
curLineNum_v := curLineNum_v+1;
next curLine_loop;
end loop curLine_loop;
wait;
end process load_coe;
end beh_ar;
</SNIP>

Reply With Quote
  #5 (permalink)  
Old 09-29-2005, 06:23 PM
Mike Treseler
Guest
 
Posts: n/a
Default Re: Initialize array using file i/o procedure/function?

Brandon wrote:
> Well, the DUT is a filter, and I've already tested it with a general
> constant array. Instead, I'm trying to get familiar with text i/o
> because I would like my design to be able to load different coefficient
> data from the text file. Depending on the application, it might be
> necessary to change the coefficient set used by the filter.


I prefer to use an editor macro or other
script to convert text to vhdl constant format.
VHDL is excellent for hardware description
and simulation, but it far below average for
text processing and parsing.

-- Mike Treseler
Reply With Quote
  #6 (permalink)  
Old 09-29-2005, 06:32 PM
Mike Treseler
Guest
 
Posts: n/a
Default Re: Initialize array using file i/o procedure/function?

Brandon wrote:
> Ok. Here is what I have inside my testbench entity, which I'm able to
> compile. However, I am receiving an error when I try to load the
> design. Note that the text file is located in the same directory as the
> vhdl:


Have your process write a test file and
see where it ends up. That's where cfir.coe
should be.

-- Mike Treseler
Reply With Quote
Reply

Bookmarks


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
Passing a function a reference to an associative array in System Verilog [email protected] Verilog 3 05-14-2007 07:13 PM
Passing file name to procedure. Niv VHDL 3 09-20-2005 06:13 PM
writing and instantiating .v file with function only thomasc Verilog 2 03-11-2005 02:20 AM
Initialize Blockram from file Daniel Köthe FPGA 3 05-19-2004 08:38 PM


All times are GMT +1. The time now is 12:20 PM.


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