-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsr_flipflop.v
More file actions
53 lines (41 loc) · 819 Bytes
/
sr_flipflop.v
File metadata and controls
53 lines (41 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
module sr_flipflop(q, qbar, s, r, clk);
output reg q, qbar;
input s, r, clk;
/* Behavioral Model
always @(posedge clk) begin
case({s, r})
2'b00: q = q;
2'b01: q = 0;
2'b10: q = 1;
2'b11: q = 1'bx;
endcase
qbar = ~q;
end
*/
/* Dataflow */
assign q = 0;
always @(posedge clk) begin
q = s | (~r)*q; //If you use +, it will take 1 + 1 = 10, and MSB will be rejected. So, use bitwise or "|".
qbar = ~q;
end
endmodule
/* Testbench
module testbench;
reg clk, s, r;
wire q, qbar;
sr_flipflop ff(q, qbar, s, r, clk);
initial begin
clk = 1'b0;
forever #10 clk = ~clk;
end
initial begin
s = 0; r = 0;
#100 s = 0; r = 1;
#100 s = 1; r = 0;
#100 s = 1; r = 1;
end
initial begin
$monitor(" S = %b R = %b Q = %b Qbar = %b", s, r, q, qbar);
end
endmodule
*/