D Flip Flop(synchronous Reset)

 








Truth Table






Design

module d_ff_sync(d,clk,rst,q);

    input d,clk,rst;

    output q;

    reg      q;

    always@(posedge clk )

    begin

        if(rst == 1'b1)

            q <= 1'b0;

         else

             q <= d;

      end

endmodule


Testbench

module d_ff_sync_tb;

    reg t_d,t_clk,t_rst;

    wire t_q;

    d_ff_sync d_ff_sync_tb(.d(t_d),

                                            .clk(t_clk),

                                             .rst(t_rst),

                                              .q(t_q)

                                              );

    initial

         begin

              t_clk = 1'b0;

              t_rst = 1'b0;

               t_d  = 1'b0;

         end

      always #10 t_clk = ~t_clk;

      always #15 t_rst = ~t_rst;

      always #20 t_d = ~t_d;

initial

    begin

        $monitor("%t,t_d=%b,t_q=%b,t_q=%b",$time,t_d,t_q);

    end

endmodule

Comments

Popular posts from this blog

2X1 Multiplexer