Decade counter

Build a decade counter that counts from 0 through 9, inclusive, with a period of 10. The reset input is synchronous, and should reset the counter to 0.
题目

题目网站

 1 module top_module (
 2     input clk,
 3     input reset,        // Synchronous active-high reset
 4     output [3:0] q);
 5 always @(posedge clk)begin
 6     if(reset || q >= 4'd9)begin   //这里是什么意思?
 7             q<=4'b0;
 8         end
 9         else begin
10             q<=q+1'b1;
11         end
12     end
13 
14 endmodule

再写:

构建一个十进制计数器,从0-9,循环

对于注释“if(reset || q >= 4'd9)begin //这里是什么意思?”,这里等于是将两种情况,一个是重置,一个是循环到头,两者一起写了

module top_module (
    input clk,
    input reset,        // Synchronous active-high reset
    output [3:0] q);
    always@(posedge clk)begin
        if(reset)begin
           q<=0; 
        end
        else begin
            if(q==4'd9)begin
                q<=0;
            end
            else begin
                q<=q+1'b1;
            end
        end
    end
endmodule
posted @   江左子固  阅读(40)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
点击右上角即可分享
微信分享提示