Created
April 28, 2012 16:36
-
-
Save kulp/2520122 to your computer and use it in GitHub Desktop.
staged Johnson (?) counter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module JCounter(input clk, input ce, output tick); | |
parameter STAGES = 6; | |
parameter SHIFTS = 10; | |
assign tick = stage[STAGES - 1].s[SHIFTS - 1]; | |
generate | |
genvar i; | |
for (i = 0; i < STAGES; i = i + 1) begin:stage | |
reg[SHIFTS-1:0] s = 1; | |
if (i == 0) begin:zero | |
always @(negedge clk) | |
if (ce) | |
stage[i].s <= { stage[i].s, stage[i].s[SHIFTS - 1] }; | |
end else begin:nonzero | |
always @(negedge clk) | |
if (stage[i - 1].s[SHIFTS - 1] | stage[i].s[SHIFTS - 1]) | |
if (ce) | |
stage[i].s <= { stage[i].s, stage[i].s[SHIFTS - 1] }; | |
end | |
end | |
endgenerate | |
endmodule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment