Skip to content

Instantly share code, notes, and snippets.

@mmalinin
Created February 6, 2021 22:23
Show Gist options
  • Save mmalinin/cb005416752e9cc110f17b4c1d24a9e3 to your computer and use it in GitHub Desktop.
Save mmalinin/cb005416752e9cc110f17b4c1d24a9e3 to your computer and use it in GitHub Desktop.
module sync_counter_1bit_pn (input up,dn,clk,rst,output reg q,output wire next_up,next_dn);
wire nq,prev;
not(nq,q);
or(prev,up,dn);
and(next_up,up,q);
and(next_dn,dn,nq);
initial q <= 1'b0;
always @(posedge clk or negedge rst) begin
if(!rst) begin
q <= 1'b0;
end else begin
if(prev) begin
q <= nq;
end
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment