forked from pConst/basic_verilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset_set_comb.sv
67 lines (55 loc) · 1.93 KB
/
reset_set_comb.sv
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
//--------------------------------------------------------------------------------
// reset_set_comb.sv
// Konstantin Pavlov, [email protected]
//--------------------------------------------------------------------------------
// INFO --------------------------------------------------------------------------------
// Synchronous SR trigger, but has a combinational output that changes
// "with no delay" after inputs
// No metastable state. SET signal dominates here
// | | +---+ | | | | | | SET
// | | | | | | | | | |
// +------------+ +--------------------------------+
// | | | | | | | | | |
// | | | | | | +---+ | | RESET
// | | | | | | | | | |
// +----------------------------+ +----------------+
// | | | | | | | | | |
// | | | +---------------+ | | Q output, original
// | | | | | | | | | | reset_set.sv
// +----------------+ | | | +----------------+
// | | | | | | | | | |
// | | +---------------+ | | | Q output, this module
// | | | | | | | | | | reset_set_comb.sv
// +------------+ | | | +--------------------+
// | | | | | | | | | |
// | | | | | | | | | |
/* --- INSTANTIATION TEMPLATE BEGIN ---
reset_set_comb RS1 (
.clk( clk ),
.nrst( 1'b1 ),
.s( ),
.r( ),
.q( ),
.nq( )
);
--- INSTANTIATION TEMPLATE END ---*/
module reset_set_comb(
input clk,
input nrst,
input s,
input r,
output q,
output nq
);
logic q_reg = 0;
always_ff @(posedge clk) begin
if( ~nrst ) begin
q_reg = 0;
end else begin
if( r ) q_reg = 1'b0;
if( s ) q_reg = 1'b1;
end
end
assign q = s || (q_reg && ~r);
assign nq = ~q;
endmodule