Input from file and output to file - VHDL

Discussion in 'VHDL' started by Emel, Jan 19, 2006.

  1. Emel

    Emel Guest

    Hi,

    what is the easiest way of taking inputs from a file and writing
    outputs to a file? I need to take values from MATLAB. I also need to
    plot the outputs in MATLAB. Can anyone suggest an appropriate way of
    doing this?

    Thanks in advance.

    e.
    Emel, Jan 19, 2006
    #1
    1. Advertising

  2. Emel

    Duane Clark Guest

    Emel wrote:
    > Hi,
    >
    > what is the easiest way of taking inputs from a file and writing
    > outputs to a file? I need to take values from MATLAB. I also need to
    > plot the outputs in MATLAB. Can anyone suggest an appropriate way of
    > doing this?


    If you read and write the files as ascii, then you can do this in both
    Matlab and VHDL in a portable fashion. I generally prefer to use binary
    data files for this purpose. I don't think there is a standard for
    binary file formats in VHDL, but Modelsim at least reads and writes 4
    byte integers. I have no problem then importing that into Matlab and
    plotting it.

    But I have used the ascii method; sometimes it is nice to have an easily
    readable file. For example, in VHDL:

    constant telm_filename : String := "telm.out";
    begin
    data_ver_p: process is
    variable L : line;
    file telm_file : text open write_mode is telm_filename;
    begin
    loop
    wait until rising_edge(USER_CLK);
    if RX_SRC_RDY = '1' then
    RX_CNT <= RX_CNT + 1;
    hwrite(L, RX_DOUT);
    writeline(telm_file, L);
    deallocate(L);
    end if;
    end loop;
    end process data_ver_p;

    Then, in Matlab:

    fid = fopen(strcat(telm,'telm.out'),'r');
    for i = 1:range_samples
    j = int32(fscanf(fid,'%x',1));
    if j > 32767
    telm2_r(i) = j-65536;
    else
    telm2_r(i) = j;
    end
    j = int32(fscanf(fid,'%x',1));
    if j > 32767
    telm2_i(i) = j-65536;
    else
    telm2_i(i) = j;
    end
    end
    fclose(fid);
    Duane Clark, Jan 19, 2006
    #2
    1. Advertising

  3. Emel

    nish a

    Joined:
    Jan 29, 2010
    Messages:
    1
    actually i want to read an image (the pixel values) from the m-file using VHDL code.. how can i do that?
    nish a, Jan 29, 2010
    #3
    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. walala
    Replies:
    3
    Views:
    4,804
    walala
    Sep 18, 2003
  2. Krick
    Replies:
    1
    Views:
    1,455
    John C. Bollinger
    Aug 15, 2003
  3. afd
    Replies:
    1
    Views:
    8,324
    Colin Paul Gloster
    Mar 23, 2007
  4. Replies:
    2
    Views:
    1,466
  5. Amal
    Replies:
    1
    Views:
    1,747
    vipinlal
    Mar 4, 2010
Loading...

Share This Page