After the 9-bit counter ref_timer in the first always block in the program counts to 0, it returns to 511, and when it is called again, it decrements from the set count value. The ref_timer value in the second block will remain at the lowest value after the first decrement ends, and will decrement from the set count value when it is called again. I want to know the difference, thanks for the answer!


module ref_timer(

        input clk,

        input rst_n,

        input INIT_REQ,

        

        output REF_REQ1,

        output REF_REQ2

);


// reg define

        reg ref_req1;

    reg ref_req2;

        reg [8:0] ref_timer;

        reg [8:0] ref_timer2;


always@(posedge clk or negedge rst_n)begin

        IF(!rst_n)begin

                ref_timer <= 0;

                ref_req1 <= 0;

        end 

        else begin

                if(INIT_REQ == 1) begin

                        ref_timer <= 9'd50;

                        ref_req1        <=0;

                end

                else

                        ref_timer <= ref_timer - 1'd1;

                

                if (ref_timer == 1)

                        ref_req1 <= 1;

        end 

end 


always@(posedge clk or negedge rst_n)begin

        if(!rst_n)begin

                ref_timer2 <= 0;

                ref_req2 <= 0;

        end 

        else begin

                if(INIT_REQ == 1) begin

                        ref_timer2 <= 9'd50;

                        ref_req2        <=0;

                end

                else if(ref_timer2 == 1)

                        ref_req2 = 1'd1;

                else

                        ref_timer2 <= ref_timer2 - 1'd1;

        end 

end


// assign define 

        assign REF_REQ1 = ref_req1;

        assign REF_REQ2 = ref_req2;


endmodule 

image.png

image.png

Reply