Exams/review2015 count1k_HDLbits(详解) 周期计数器典例

1、Build a counter that counts from 0 to 999, inclusive, with a period of 1000 cycles. The reset input is synchronous, and should reset the counter to 0.

构建一个计数范围为0到999(含0到999)的计数器,周期为1000个周期。重置输入是同步的,应将计数器重置为0。

思路:

分别设置个位、十位、百位的三个变量one\ten\hun进行计数,到9进1。

如果直接q+1来计周期,不会符合十进制的进位标准。

最终q= one + ten*10 +hun*100;

module top_module (
    input clk,
    input reset,
    output [9:0] q);
    reg [3:0] one,ten,hun; 
    always @(posedge clk)
        begin
            if(reset) begin one<=0;ten<=0;hun<=0; end
            else 
                begin
                    if(hun==4'd9&&ten==4'd9&&one==4'd9) begin hun<=0; ten<=0;one<=0; end
                    else if(ten==4'd9&&one==4'd9) begin hun<=hun+1;ten<=0;one<=0; end
                    else if(one==4'd9) begin one<=0; ten<=ten+1; end
                    else one<=one+1;
                end
        end
assign q = one + ten*10 +hun*100;
    
endmodule

理理思路还是比较简单的

冲冲冲

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值