Subscribe Us

Header Ads

Write RTL and Test bench for N-bit Johnson counter.

 RTL 

//'johnson counter

 

module johnson_counter(rst,clk,q);

 

parameter N=4;

input rst,clk;

output reg [N-1:0]q;

 

 

always @(posedge clk)

begin

       if(rst)

            q<=4'b1000;

        else

            begin

                q<={~q[0],q[N-1:1]};

            end

end    

endmodule

 


 TEST BENCH

//'johnson counter test bench

 

module johnson_counter_tb();

 

reg rst,clk;

wire [3:0]q;

 

 

johnson_counter JC(rst,clk,q);

 

initial

    begin

    clk=0;

    forever #5 clk=~clk;

    end

 

task initiaize();

    begin

        #5;

        rst=0;

        clk=0;

    end

endtask

 

task reset();

    begin  

    @(negedge clk)

    rst=1'b1;

    @(negedge clk)

    rst=1'b0;

    end

endtask

 

 

initial

begin

    initiaize;

    reset;

       

    #50;

    reset

   

    #50;

end

 

initial

$monitor("Input rst=%b,clk=%b, Output q=%b",rst,clk,q);

 

initial

#250 $finish;

 

endmodule


Post Your doubt in mail.👇👇👇

  E-Mail:-denilvaghasiya17@gmail.com


Post a Comment

0 Comments