-1

I am quite new to Verilog and trying to learn by writing the DSP blocks that I need for my work.

I am trying to write the variables of sub-modules to a txt/m file to use in matlab.

The top block is TB and the sub-module instance is named "sync_short_inst" as follows:

enter image description here

I am writing three variables in three different file: two variables from top block and one variable from sub-module, as copied at the end of this thread.

I am having problem writing the variable from sub-module in the file. The code compiles without error but when I run simulation, I get error and I don't get anything inside the file. when I comment the third $fwrite, the simulations has no problem but third $fwrite generates following error.

I would appreciate if someone could advice me how to fix the problem.

enter image description here

`timescale 1ns / 1ps

 module TB( );  
`include "common_params.v"

reg clock;
reg reset;
reg enable;

reg set_stb;
reg [7:0] set_addr;
reg [31:0] set_data;

reg signed [31:0] data_in;
reg input_strobe;
wire short_preamble_detected;

// RAM
//localparam RAM_SIZE = 1<<132;
reg [31:0] FileData [0:10000];   // 10000 words of size 32
reg [31:0] addr1;      
integer fID_i, fID_q, fID_mag_sq_av;



`define SAMPLE_FILE "SampleFile.txt"
sync_short  sync_short_inst(
    .clock(clock),
    .reset(reset),
    .enable(enable),

    .set_stb(set_stb),
    .set_addr(set_addr),
    .set_data(set_data),

    .sample_in(data_in),
    .sample_in_strobe(input_strobe),

    .short_preamble_detected(short_preamble_detected)
    );


initial 
    begin                       
        $display("Reading memory from...");
        $display(`SAMPLE_FILE);
        $readmemh(`SAMPLE_FILE, FileData);
        $display("Done.");   
        clock = 1'b0;
        reset = 1'b1;
        enable = 1'b0;
        input_strobe = 1'b0;

        # 20 
        reset = 1'b0;
        enable = 1'b1;
        set_stb = 1;
        # 20
        set_addr = SR_SKIP_SAMPLE;  // do not skip sample
        set_data = 0;

        input_strobe = 1'b1;
        # 20 input_strobe = 1'b0;  
        # 20 input_strobe = 1'b1;
    end

always @(posedge clock) 
    begin      
        if (reset)
            begin
                data_in <= 0;
                input_strobe <= 0;

                addr1 <= 0;
            end 
        else if (enable & input_strobe) 
            begin
                data_in <= FileData[addr1]; 
                addr1 <= addr1 + 'd1;
                $fwrite(fID_i,$signed(TB.data_in[31:16]),"\n");
                $fwrite(fID_q,$signed(TB.data_in[15:0]),"\n");
                //$fwrite(fID_mag_sq_av,$signed(TB.sync_short_inst.clock),"\n");    
                $display($signed(TB.sync_short_inst.clock));
            end

    end                                    


always #5 clock = !clock;
initial 
    begin
        fID_i =$fopen("IO_Files/file_i.m");  $fwrite(fID_i,"x=0; z=0; i=[... \n");
        fID_q =$fopen("IO_Files/file_q.m");  $fwrite(fID_q,"x=0; z=0; q=[... \n");
        fID_mag_sq_av= $fopen("IO_Files/file_mag_sq_av.m");  $fwrite(fID_mag_sq_av,"x=0; z=0; i=[... \n");  
        #80000
        $fwrite(fID_i,"]; clear x, clear z");  
        $fwrite(fID_q,"]; clear x, clear z"); 
        $fwrite(fID_mag_sq_av,"]; clear x, clear z");
        $fclose(fID_i);
        $fclose(fID_q);
        $fclose(fID_mag_sq_av);
    end 

endmodule

M.X
  • 195
  • 3
  • 12
  • Thank you for reply. I just added the TB code to the thread. $display($signed(TB.sync_short_inst.clock)); returns the same error too. – M.X Oct 07 '17 at 14:05
  • it returns the same error – M.X Oct 07 '17 at 16:51
  • Tried Vivado and it works. Shouldn't I trust on Active-HDL then? – M.X Oct 07 '17 at 22:08
  • it really looks like a simulator bug. It could probably be caused by bad error reporting and you can find your errors running it on a different simulator. if not, start commenting out some lines and try till you figure it out. – Serge Oct 09 '17 at 20:44

1 Answers1

1

I cannot reproduce yours issue on code you have posted on Active 10.1 nor on newest version. You need to post full sample on which it can be repeated.

Please contact vendor technical support to fix this issue.

tester
  • 11
  • 1