Why a signal cannot control the file IO operation?


F

fl

Hi,
I use file I/O in my project. I would like to control the data file reading to a signal input port by another signal. Surprising me, the signal cannot control the data file reading. The simplified file is listed below. Could you help me out?

'start' is the signal to control the reading of input data file: infil.txt.
infil.txt contails some floating number, such as:
///////////
0.0
1.0
2.0
3.0
4.0
5.0
6.0
7.0
8.0
9.0
10.0
9.0
8.0
7.0
6.0
5.0
4.0
3.0
2.0
1.0
0.0
-1.0
-2.0
-3.0
-4.0
-5.0
-6.0
-7.0
-8.0
-9.0
-10.0
-9.0
-8.0
-7.0
-6.0
-5.0
-4.0
-3.0
-2.0
-1.0
-0.0
////////////

Thanks.


....................

-- =============================================================================
-- file name is : filEx.vhd (filExample= file example)
-- Author : Kim Petersen/HDC
-- Created: 00.03.22 last modified: 00.03.22
-- =============================================================================
-- Program read from an input file, called "infil.txt" that is saved in same
-- directory as the program. Format of data in input file is floating point.
-- The data read from the input file is multiplied with the value
-- 2.22222222222222.
-- The result of the multiplication is saved in an output file called
-- "utfil.txt"
--
-- Below the flow from input to output file for each value transferred
--
-- ------ ------ ------ ------ ------ ------ ------
-- clock | | | | | | | | | | | | |
-- ---- ------ ------ ------ ------ ------ ------
-- ^ ^ ^
-- | | |
-- | | Save multiplied value in output file
-- | Multiply read value with 2.22222222222222
-- Read value from input file
--
-- File can be simulated as is. Just run for time 12000 with command
-- "run 12000", true when modelsim used as simulator.
-- =============================================================================
LIBRARY STD;
USE STD.TEXTIO.ALL;
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;

ENTITY filEx IS

END filEx;
-- =============================================================================
-- ======1=========2=========3=========4=========5=========6=========7=========8
ARCHITECTURE TEST OF filEx IS

SIGNAL clock : BIT := '0'; -- ":='0'" included to avoid that clock
-- may hang up as unknown.
CONSTANT multValue : REAL := 2.22222222222222;
SIGNAL newValueRead : BOOLEAN := FALSE;
SIGNAL newValueToSave : BOOLEAN := FALSE;
SIGNAL dataReadFromFile : REAL;
SIGNAL dataToSaveToFile : REAL;
SIGNAL lineNumber : INTEGER:=1; -- add line number to output file
signal start : std_logic := '0';
-- =============================================================================
BEGIN

clock <= NOT(clock) AFTER 100 ns; -- create time behaviour
start <= '0', '1' after 100 ns, '0' after 400 ns, '1' after 800 ns, '0' after 1200 ns, '1' after 1600 ns;

-- ======1=========2=========3=========4=========5=========6=========7=========8
-- "readProcess" reads data from the input file. Read continues until EOF
-- detected. One data read at each rising edge on "clock".
-- ======1=========2=========3=========4=========5=========6=========7=========8
readProcess :
PROCESS
FILE inFile : TEXT IS IN "infil.txt";
VARIABLE inLine : LINE;
VARIABLE dataRead : REAL;

BEGIN

WAIT UNTIL clock = '1' AND clock'EVENT;
if (start = '1') then
IF (NOT ENDFILE(inFile)) THEN
READLINE(inFile, inLine);
-- Must read value into a variable and not a signal(real).
READ(inLine, dataRead);
-- Transfer read value into a "signal".
dataReadFromFile <= dataRead;
-- inform that new value is read from input file,
newValueRead <= TRUE;
ELSE
newValueRead <= FALSE; -- no new value read from input file
WAIT; -- wait for ever, since all data is read from input file
END IF;
end if;
END PROCESS readProcess;
-- ======1=========2=========3=========4=========5=========6=========7=========8
-- ======1=========2=========3=========4=========5=========6=========7=========8
-- "multProcess" Multiplies read data with value of constant "multValue".
-- ======1=========2=========3=========4=========5=========6=========7=========8
multProcess :
PROCESS(clock)
BEGIN
IF (clock'EVENT and clock='1') THEN
IF (newValueRead=TRUE) THEN
newValueToSave <= newValueRead;
dataToSaveToFile <= dataReadFromFile*multValue;
ELSE
newValueToSave <= FALSE;
END IF;
END IF;

END PROCESS multProcess;
-- ======1=========2=========3=========4=========5=========6=========7=========8
-- ======1=========2=========3=========4=========5=========6=========7=========8
-- ======1=========2=========3=========4=========5=========6=========7=========8
-- "writeProcess" Writes data into an external output file alled "utfil.txt".
-- As long as signal "newValueToSave" has value "true": One data is saved
-- at each rising edge of "clock".
-- ======1=========2=========3=========4=========5=========6=========7=========8
writeProcess :
PROCESS
FILE outFile : TEXT IS OUT "utfil.txt";
VARIABLE outLine : LINE;
BEGIN

WAIT UNTIL clock = '1' AND clock'EVENT;
IF (newValueToSave = TRUE) THEN
-- create line to write to file.
-- WRITE (line ; value(integer) ;
-- justified(side) ; field(width));
WRITE(outLine, lineNumber, right, 3);
WRITE(outLine, HT); -- HT is equal to a TAB-character, See
-- package "standard" for further information.

-- WRITE (line ; value(real ; justified(side)
-- field(width) ; digits(natural));
WRITE(outLine, dataToSaveToFile, right, 16, 12);

-- Write line to external file.
WRITELINE(outFile, outLine);
lineNumber <= lineNumber + 1;
END IF;

END PROCESS writeProcess;
-- ======1=========2=========3=========4=========5=========6=========7=========8
END TEST; -- end of file
 
Ad

Advertisements

N

Nicolas Matringe

Le 06/10/2012 04:21, fl a écrit :
Hi,
I use file I/O in my project. I would like to control the data file reading to a signal input port by another signal. Surprising me, the signal cannot control the data file reading. The simplified file is listed below. Could you help me out?

'start' is the signal to control the reading of input data file: infil.txt.

It probably works. You never reset your signal 'newValueRead' to false
unless you reach the end of the file so once you've started it stays
true whatever the value of 'start' is.

Nicolas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top