اطلاعیه

Collapse
No announcement yet.

خواندن یک فایل از حافظه در vhdl

Collapse
X
 
  • فیلتر
  • زمان
  • Show
Clear All
new posts

    خواندن یک فایل از حافظه در vhdl

    درود
    من می خواهم یک ماتریس را که در یک فایبل txt ذخیره کردم را در vhdl بخونم
    چه کنم؟؟؟
    کد زیر را چک کنید لطفا
    زمانم محدود است

    اضافه شده در تاریخ :
    من کد زیر را نوشتم
    فقط مشکیم اینه که چجوری اعداد را بگم جدا گانه بخونه و داخل آرایه ام بریزه
    لطفا اگر کسی با دستور READLINE یا READ کارکرده کمک کنه




    library ieee;
    use ieee.std_logic_1164.all;
    use IEEE.std_logic_signed.all;
    use std.textio.all;--need for use read
    entity matrix1 is
    port(clk:in std_logic);
    end matrix1;
    architecture mat_read of matrix1 is
    type px is array(511 downto 0,511 downto 0)of integer range 0 to 255;--array for save matrix
    signal pxmat:px;
    signal row,col:integer range 0 to 511:=0;--their show row and column
    begin
    process(clk)
    file data_out: text;
    variable fstatus: FILE_OPEN_STATUS;
    variable count: integer range 0 to 511:= 0;
    variable buf: LINE;-- buffer between the program and file
    begin
    file_open(fstatus, data_out, "mat.txt", read_mode);--open file and save it in data_out-------data_out and "mat" have same format
    if( clk'event and clk='1' )then
    readline(data_out,buf);--read from data_out and write in buf
    read(buf,count);--transfer into count
    pxmat(row,col)<=count;--transfer into array
    col<=col+1;--for change column
    if ((col=511)and(row<511))then--for chek and change row
    row<=row+1;
    col<=0;
    end if;
    end if;
    end process;
    end mat_read;


    ايميل من:peymankzv@gmail.com

    #2
    پاسخ : خواندن یک فایل از حافظه در vhdl

    با سلام

    فقط مشکیم اینه که چجوری اعداد را بگم جدا گانه بخونه و داخل آرایه ام بریزه
    داخل یه حلقه for داده ها رو از داخل فایلتون بخونید و بریزید داخل یه آرایه، بعد که تموم شد با توجه به نوع چینش داده ها داخل فایل، داده ها رو داخل یه متغیر(سیگنال) از نوع ماتریس بریزید.
    به عنوان مثال فرض کنید که میخواهیم مقادیر درایه های یه ماتریس 8در8 رو از داخل فایل بخونبم :



    process
    variable input : ord_32bit_vector(63 downto 0);
    variable l_in : line;
    variable temp_in : fp_32bit_vector (63 downto 0);
    variable k : integer:=0;

    begin

    for i in 0 to 63 loop
    readline(input_value_file,l_in);
    read(l_in,input(i));
    temp_in(i):=to_stdlogicvector(input(i));
    end loop;

    k:=0;
    for i in 0 to 7 loop
    for j in 0 to 7 loop
    data_in_mat(j,i)<=temp_in(k);
    k:=k+1;
    end loop;
    end loop;

    end process;

    دیدگاه


      #3
      پاسخ : خواندن یک فایل از حافظه در vhdl

      اقا مجتبی سپاس
      فقط این دو نوعی که شما تعریف کردید را من نمی شناسم و کامپایلر خطا می ده. باید از کتابخانه خاصی استفاده کنم؟
      چون کلا نمی شناسدش و خطای زیر را می ده
      Unknown identifier "ord_32bit_vector"
      در ضمن data_in_mat را یک ماتریس دوبعدی تعریف کردم
      ايميل من:peymankzv@gmail.com

      دیدگاه


        #4
        پاسخ : خواندن یک فایل از حافظه در vhdl

        خواهش میکنم.

        این کدی که گزاشتم به عنوان نمونه بود، بخشی از یک تست بنچ که یه جا استفاده کرده بودم،بود، من همونو کپی پیست کردم، تا شما ازش ایده بگیرید برای کاره خودتون.

        فایل های تست بنچی که گفتم رو براتون پلود کردم، ببینید کمکتون میکنه:

        http://vip.eca.ir/sharing/uploads/13782273141.rar

        دیدگاه


          #5
          پاسخ : خواندن یک فایل از حافظه در vhdl

          برنامتون را چک کردم
          سپاس فراوان
          من با کمک یکی دیگر از دوستان در تاپیک http://www.eca.ir/forum2/index.php?topic=82026.0 مشکل را حل کردیم و به برنامه ی زیر رسیدیم که در شبیه سازی جواب می دهد
          برای دوستان برنامه رو قرار می دم
          library IEEE;
          use ieee.std_logic_1164.all;
          use IEEE.std_logic_signed.all;
          use std.textio.all;-----------need for use read

          entity matrix3 is
          port( clk:in std_logic;
          outelement,outelement2:inout integer range 0 to 255);
          end matrix3;
          architecture mat_read3 of matrix3 is
          type px is array(511 downto 0,511 downto 0)of integer range 0 to 255;------array for save matrix
          type read_col is array(511 downto 0)of integer range 0 to 255;--------array for read column in each line
          signal read_column:read_col;
          signal pxmat:px;
          signal row,col:integer range 0 to 511:=0;------------their show row and column
          begin
          process
          file data_out: text;
          variable fstatus: FILE_OPEN_STATUS;
          variable count: integer range 0 to 511:= 0;
          variable buf: LINE;---------- buffer between the program and file

          begin
          file_open(fstatus, data_out,"mat2.txt", read_mode);-----------open file and save it in data_out-------data_out and "mat" have same format
          for iRow in 0 to 511 loop
          readline(data_out,buf);--------read from data_out and write in buf
          for iCol in 0 to 511 loop
          read(buf,count);--------transfer into count
          pxmat(iRow,iCol) <=count;------------transfer into array
          end loop;--col

          end loop;--row
          wait;
          end process;

          process (clk)

          begin
          if( clk'event and clk='1' )then
          if col/=511 then
          col<=col+1;
          else
          col<=0;
          if row/=511 then
          row<=row+1;
          else
          row<=0;
          end if;
          end if;
          outelement<=pxmat(row,col);
          end if;
          end process;
          end mat_read3;

          ايميل من:peymankzv@gmail.com

          دیدگاه


            #6
            پاسخ : خواندن یک فایل از حافظه در vhdl

            سلام میشه با این روند برنامه ضرب ماتریس از طریق خوندن دو فایل جدا و نوشتن نتیجه در یک فایل دیگه رو انجام داد؟

            دیدگاه

            لطفا صبر کنید...
            X