Skip to content

Instantly share code, notes, and snippets.

@bit-hack
Created January 5, 2020 14:34
Show Gist options
  • Save bit-hack/74bcdb7ed8e9c73f4f7805822f1cfc62 to your computer and use it in GitHub Desktop.
Save bit-hack/74bcdb7ed8e9c73f4f7805822f1cfc62 to your computer and use it in GitHub Desktop.
verilog power on reset
`timescale 1 ns / 1 ps
module power_on_reset(input in_clk, output out_rst);
reg [5:0] reset_cnt = 0;
wire resetn = &reset_cnt;
assign out_rst = !resetn;
always @(posedge in_clk) begin
reset_cnt <= reset_cnt + !resetn;
end
endmodule
module test_bench();
reg clk;
wire rst;
power_on_reset por(clk, rst);
initial begin
$dumpfile("dump.vcd");
$dumpvars;
clk <= 0;
#1000 $finish;
end
always @(*) begin
#1 clk <= ~clk;
end
reg [7:0] counter;
always @(posedge clk) begin
if (rst) begin
counter <= 0;
end else begin
counter <= counter + 8'd1;
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment