Subscribe Us

Header Ads

Write rtl to design a 4 bit MOD -12 loadable binary synchronous up counter.

  

Write rtl to design a 4 bit MOD -12 loadable binary synchronous up counter.

RTL

//mod-12 synchronus and loadabe up counter

 

module mod_12_sync_up_load_counter(clk,load,rst,din,count);

 

parameter N=4;

input clk,rst,load;

input [N-1:0]din;

output reg [N-1:0]count;

 

always@(posedge clk)

    begin

            if(rst)

            count<=4'd0;

           

            else if (load)

            count<=din;

           

            else

                begin

                if(count==4'd11)

                count<=4'd0;

                   

                else

                count<=count+4'd1;

                end

    end

endmodule

 

Test bench

// mod 12 synchronus and loadabe up counter

 

module mod_12_sync_up_load_counter_tb();

 

reg rst,clk,load;

reg [3:0]din;

wire [3:0]count;

 

 

mod_12_sync_up_load_counter SA(clk,load,rst,din,count);

initial

    begin

    clk=0;

    forever #5 clk=~clk;

    end

 

task initiaize();

    begin

        #5;

        rst=0;

        clk=0;

        load=0;

        din=0;

    end

endtask

 

task reset();

    begin  

    @(negedge clk)

    rst=1'b1;

    @(negedge clk)

    rst=1'b0;

    end

endtask

 

task data(input [3:0]a);

    begin

        @(negedge clk)

        load=1;

        din=a;

        @(negedge clk)

        load=0;

    end

endtask

 

initial

begin

    initiaize;

    reset;

        repeat(13)

        @(negedge clk)

    #5;

    data(4'd14);

   

        repeat(13)

        @(negedge clk)

    #5;

    data(4'd5);

end

 

initial

$monitor("Input rst=%b,clk=%b,din=%b,load=%b Output count=%b",rst,clk,din,load,count);

 

initial

#500 $finish;

 

endmodule

 

 Post Your doubt in mail.👇👇👇

  E-Mail:-denilvaghasiya17@gmail.com


Post a Comment

0 Comments