Skip to content

Instantly share code, notes, and snippets.

@mwkmwkmwk
Created April 8, 2020 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwkmwkmwk/5c7a840e65e9282dd5d741e802296d83 to your computer and use it in GitHub Desktop.
Save mwkmwkmwk/5c7a840e65e9282dd5d741e802296d83 to your computer and use it in GitHub Desktop.
module \$dffes (CLK, RST, EN, D, Q);
parameter WIDTH = 0;
parameter CLK_POLARITY = 1'b1;
parameter EN_POLARITY = 1'b1;
parameter RST_POLARITY = 1'b1;
parameter RST_VALUE = 0;
input CLK, RST, EN;
input [WIDTH-1:0] D;
output reg [WIDTH-1:0] Q;
wire pos_clk = CLK == CLK_POLARITY;
wire pos_rst = RST == RST_POLARITY;
always @(posedge pos_clk) begin
if (EN == EN_POLARITY) begin
if (pos_rst)
Q <= RST_VALUE;
else
Q <= D;
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment