2020-09-23 18:49:30 -05:00
|
|
|
//-----------------------------------------------------
|
|
|
|
// Design Name : D-type Flip-flop with Write Enable
|
|
|
|
// File Name : ff_en.v
|
|
|
|
// Function : D flip-flop with asyn reset and set
|
|
|
|
// Coder : Xifan TANG
|
|
|
|
//-----------------------------------------------------
|
|
|
|
module DFF_EN (
|
|
|
|
/* Global ports go first */
|
|
|
|
input SET, // set input
|
|
|
|
input RST, // Reset input
|
|
|
|
input WE, // Write Enable
|
|
|
|
input CK, // Clock Input
|
|
|
|
/* Local ports follow */
|
|
|
|
input D, // Data Input
|
2020-09-23 19:28:45 -05:00
|
|
|
output Q, // Q output
|
2020-09-23 18:52:59 -05:00
|
|
|
output QB // QB output
|
2020-09-23 18:49:30 -05:00
|
|
|
);
|
|
|
|
//------------Internal Variables--------
|
|
|
|
reg q_reg;
|
|
|
|
|
|
|
|
//-------------Code Starts Here---------
|
|
|
|
always @ ( posedge CK or posedge RST or posedge SET)
|
2020-09-23 19:28:45 -05:00
|
|
|
if (RST) begin
|
2020-09-23 18:49:30 -05:00
|
|
|
q_reg <= 1'b0;
|
|
|
|
end else if (SET) begin
|
|
|
|
q_reg <= 1'b1;
|
|
|
|
end else if (WE) begin
|
|
|
|
q_reg <= D;
|
|
|
|
end
|
|
|
|
|
2020-09-23 18:52:59 -05:00
|
|
|
`ifndef ENABLE_FORMAL_VERIFICATION
|
2020-09-23 18:49:30 -05:00
|
|
|
// Wire q_reg to Q
|
|
|
|
assign Q = q_reg;
|
2020-09-23 18:52:59 -05:00
|
|
|
assign QB = ~q_reg;
|
|
|
|
`else
|
|
|
|
assign Q = 1'bZ;
|
|
|
|
assign QB = !Q;
|
|
|
|
`endif
|
2020-09-23 18:49:30 -05:00
|
|
|
|
|
|
|
endmodule //End Of Module
|