Counter

Design
module counter(clk, rst, count);
    input clk,rst;
    output [3:0] count;
    reg      [3:0] counter;

    always@(posedge clk or negedge rst)
    begin
        if(rst == 1'b0)
            counter <= 4'b0;
        else
            counter <= counter + 4'b1;
     end
            assign count = counter;
endmodule

Testbench
module counter_tb
    reg t_clk,t_rst;
    wire [3:0] t_count;

    counter counter_tb(.clk(t_clk),
                                   .rst(t_rst),
                                   .count(t_count)
                                    );
    initial
        begin
            t_clk = 0;
            forever #10 t_clk = ~t_clk;
        end

    initial
        begin
            t_rst = 1'b0;

            #10
             t_rst = 1'b1;
         end
endmodule

Comments

Popular posts from this blog

2X1 Multiplexer