题解 | #Johnson Counter#
Johnson Counter
https://www.nowcoder.com/practice/7ee6e9ed687c40c3981d7586a65bc22d
`timescale 1ns/1ns
module JC_counter(
input clk ,
input rst_n,
output reg [3:0] Q
);
reg [2:0]cnt;
always@(posedge clk or negedge rst_n)
if (rst_n == 1'b0)
cnt <= 3'b0;
else if (cnt == 3'd7)
cnt <= 3'b0;
else
cnt <= cnt + 1'b1;
always@(*)
if (rst_n == 1'b0)
Q <= 4'b0000;
else
case(cnt)
3'd0 : Q <= 4'b0000;
3'd1 : Q <= 4'b1000;
3'd2 : Q <= 4'b1100;
3'd3 : Q <= 4'b1110;
3'd4 : Q <= 4'b1111;
3'd5 : Q <= 4'b0111;
3'd6 : Q <= 4'b0011;
3'd7 : Q <= 4'b0001;
default : Q <= 4'b0000;
endcase
endmodule
