t flip flop - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

206


26
 
1
module tb;
2
    reg clk,rst,t;
3
    wire q;
4
    int delay;
5
    t_ff DUT(.*);
6
7
    always #5 clk=~clk;
8
    initial begin
9
        rst=1; clk=0; t=0;
10
    end
11
    initial begin
12
        @(posedge clk) rst=0;
13
        for(int i=0;i<20;i++)
14
            begin
15
                delay=$urandom_range(3,7);
16
                t=~t;
17
                #delay;
18
            end
19
        #20 $finish;
20
    end
21
    initial begin
22
        $dumpfile("file1.vcd");
23
        $dumpvars(1,tb);
24
    end
25
endmodule
26
xxxxxxxxxx
1
23
 
1
// Code your design here
2
module t_ff(clk,
3
            rst,
4
            t,
5
            q
6
            );
7
    input clk,rst,t;
8
    output reg q;
9
10
    always@(posedge clk or posedge rst)
11
        begin
12
            if(rst==1'b1)
13
                q<=0;
14
            else 
15
            begin
16
                if(t==1'b0)
17
                    q<=q;
18
                else
19
                    q<=~q;
20
            end
21
        end
22
23
endmodule
52 views and 0 likes     
A short description will be helpful for you to remember your playground's details
 
100:0