题解 | #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

全部评论

相关推荐

不愿透露姓名的神秘牛友
06-18 22:30
点赞 评论 收藏
分享
牛客848095834号:举报了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务