1
0
mirror of https://github.com/pConst/basic_verilog.git synced 2025-01-14 06:42:54 +08:00
basic_verilog/set_reset_comb.sv
2019-12-13 13:19:49 +03:00

67 lines
1.9 KiB
Systemverilog

//--------------------------------------------------------------------------------
// set_reset_comb.sv
// Konstantin Pavlov, pavlovconst@gmail.com
//--------------------------------------------------------------------------------
// INFO --------------------------------------------------------------------------------
// Synchronous SR trigger, but has a combinational output that changes
// "with no delay" after inputs
// No metastable state. RESET signal dominates here
// | | +---+ | | | | | | SET
// | | | | | | | | | |
// +------------+ +--------------------------------+
// | | | | | | | | | |
// | | | | | | +---+ | | RESET
// | | | | | | | | | |
// +----------------------------+ +----------------+
// | | | | | | | | | |
// | | | +---------------+ | | Q output, original
// | | | | | | | | | | set_reset.sv
// +----------------+ | | | +----------------+
// | | | | | | | | | |
// | | +---------------+ | | | Q output, this module
// | | | | | | | | | | set_reset_comb.sv
// +------------+ | | | +--------------------+
// | | | | | | | | | |
// | | | | | | | | | |
/* --- INSTANTIATION TEMPLATE BEGIN ---
set_reset_comb SR1 (
.clk( clk ),
.nrst( 1'b1 ),
.s( ),
.r( ),
.q( ),
.nq( )
);
--- INSTANTIATION TEMPLATE END ---*/
module set_reset_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( s ) q_reg = 1'b1;
if( r ) q_reg = 1'b0;
end
end
assign q = (s || q_reg) && ~r;
assign nq = ~q;
endmodule