FPGA Player

好记性不如烂笔头

导航

modelsim读写TXT文件

 

integer step_file; //文件要定义成integer

         //open the file

Initial

Begin

step_file = $fopen("F:/Company/Src/txt/step.v","r");

      file_ekxdn =$fopen("F:/Company/Src/txt/ekxdn.v","w");

end

 

always #5 clk = !clk;

    //read data from file

    always @ ( posedge clk )//read from the file

begin

      if( cnt_test[2:0] == 0 )

                   begin

 

               $fscanf(step_file,"%d%d",ref01_i,ref01_q);

                      end

    end

 

    //write data to file

    wire signed[24:0]  ekxdn_i,ekxdn_q;

    always @( posedge clk )

    begin

      if( cnt_test[2:0] == 3'b111 )

        begin

     $fwrite(nx_coef_file,"%d%12d\n",nx01_coef_i,nx01_coef_q);

        end

end

读写文件的数据格式如下:

                       

 

以下点要注意:

1、可能由于加密的原因,读不了txt文件,只能读。V的了

2、打开文件的$fopen语句必须放在initial 中才可以

3、必须注意路径中斜杠的方向“/”

4、相对路径的设置(请参考积累中的“相对路径与绝对路径”)

5、如果读入的是有符号数,那么要把数据的类型定义为signed

 怎样关闭文件

读到文件结尾自动停止

txt文件格式如下

posted on 2016-06-13 09:08  中国的孩子  阅读(4116)  评论(0编辑  收藏  举报