Why a signal cannot control the file IO operation?

Discussion in 'VHDL' started by fl, Oct 6, 2012.

  1. fl

    fl Guest

    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
     
    fl, Oct 6, 2012
    #1
    1. Advertising

  2. 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
     
    Nicolas Matringe, Oct 6, 2012
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. J Gao
    Replies:
    0
    Views:
    1,245
    J Gao
    Jul 28, 2003
  2. Mr. SweatyFinger

    why why why why why

    Mr. SweatyFinger, Nov 28, 2006, in forum: ASP .Net
    Replies:
    4
    Views:
    991
    Mark Rae
    Dec 21, 2006
  3. Mr. SweatyFinger
    Replies:
    2
    Views:
    2,258
    Smokey Grindel
    Dec 2, 2006
  4. david ullua
    Replies:
    13
    Views:
    695
  5. raan
    Replies:
    2
    Views:
    472
Loading...

Share This Page