目录

3.2.2.1 Four-bit binary counter(Count15)

3.2.2.2 Decade counter(Count10)

3.2.2.3 Decade counter again(Count1to10)

3.2.2.4 Show decade counter(Countslow)

3.2.2.5 Counter 1-12(Exams/ece241 2014 q7a)

3.2.2.6 Counter 1000(Exams/ece241 2014 q7b)

3.2.2.7 4-digit decimal counter(Countbcd)

3.2.2.8 12-hour clock(Count clock)


3.2.2.1 Four-bit binary counter(Count15)

module top_module (input clk,input reset,      // Synchronous active-high resetoutput reg [3:0] q);always @(posedge clk)beginif(reset == 1)beginq <= 4'b0;endelse beginq <= q + 1'b1; endendendmodule

3.2.2.2 Decade counter(Count10)

module top_module (input clk,input reset,        // Synchronous active-high resetoutput reg [3:0] q);always @(posedge clk)beginif(reset == 1)beginq <= 4'b0;endelse if(q == 9)beginq <= 4'b0; endelse beginq <= q + 1'b1; endend
endmodule

3.2.2.3 Decade counter again(Count1to10)

module top_module (input clk,input reset,output [3:0] q);always @(posedge clk)beginif(reset)beginq <= 4'b1;endelse if(q == 10)beginq <= 4'b1;endelse beginq <= q + 1'b1;end     endendmodule

3.2.2.4 Show decade counter(Countslow)

module top_module (input clk,input slowena,input reset,output reg [3:0] q);always @(posedge clk)beginif(reset)beginq <= 4'b0;endelse if(slowena)beginif(q == 4'd9)beginq <= 4'b0;endelse beginq <= q + 1'b1; endendendendmodule

3.2.2.5 Counter 1-12(Exams/ece241 2014 q7a)

module top_module (input clk,input reset,input enable,output [3:0] Q,output c_enable,output c_load,output [3:0] c_d
); //assign c_enable = enable;assign c_load = reset | ((Q == 4'd12) && enable == 1);assign c_d = c_load ? 4'b1 : 4'b0;count4 the_counter (clk, c_enable, c_load, c_d, Q);endmodule

3.2.2.6 Counter 1000(Exams/ece241 2014 q7b)

module top_module (input clk,input reset,output OneHertz,output [2:0] c_enable
); //wire [3:0] q0, q1, q2;assign c_enable ={((q1==4'd9) & (q0==4'd9)), (q0==4'd9), 1'b1};bcdcount counter0 (clk, reset, c_enable[0], q0);bcdcount counter1 (clk, reset, c_enable[1], q1);bcdcount counter2 (clk, reset, c_enable[2], q2);assign OneHertz = ((q2==4'd9) & (q1==4'd9) & (q0==4'd9));endmodule

3.2.2.7 4-digit decimal counter(Countbcd)

module top_module (input clk,input reset,   // Synchronous active-high resetoutput [3:1] ena,output [15:0] q);//申明低位到高位的寄存器,用作各个BCD计数器reg [3:0] cnt_0, cnt_1, cnt_2, cnt_3;//cnt_0计数器,个位always @(posedge clk)beginif(reset)begincnt_0 <= 4'b0;endelse if(cnt_0 == 4'd9)begincnt_0 <= 4'b0;endelse begincnt_0 <= cnt_0 + 1'b1; endend//cnt_1计数器,十位always @(posedge clk)beginif(reset)begincnt_1 <= 4'b0;endelse if(cnt_0 == 4'd9)beginif(cnt_1 == 4'd9)begincnt_1 <= 4'b0;endelse begincnt_1 <= cnt_1 + 1'b1; endendend//cnt_2计数器,百位always @(posedge clk)beginif(reset)begincnt_2 <= 4'b0;endelse if((cnt_1 == 4'd9) & (cnt_0 == 4'd9))beginif(cnt_2 == 4'd9)begincnt_2 <= 4'b0;endelse begincnt_2 <= cnt_2 + 1'b1; endendend//cnt_3计数器,千位always @(posedge clk)beginif(reset)begincnt_3 <= 4'b0;endelse if((cnt_2 == 4'd9) & (cnt_1 == 4'd9) & (cnt_0 == 4'd9))beginif(cnt_3 == 4'd9)begincnt_3 <= 4'b0;endelse begincnt_3 <= cnt_3 + 1'b1; endendend//物理连线assign q = {cnt_3, cnt_2, cnt_1, cnt_0};assign ena = {(cnt_2 == 4'd9)&(cnt_1 == 4'd9)&(cnt_0 == 4'd9), (cnt_1 == 4'd9)&(cnt_0 == 4'd9), (cnt_0 == 4'd9)};endmodule

3.2.2.8 12-hour clock(Count clock)


//时钟设计,分为时(01~12)、分(00~59)、秒(00~59)
module top_module(input clk,                    //上升沿检测input reset,             //同步复位,因此需要放在always块里面input ena,                 //ena为高电平才能进行时间加减output reg pm,             //pm   0-am  1-pm  当hh-mm-ss:11-59-59时,pm由0变到1output reg [7:0] hh,output reg [7:0] mm,output reg [7:0] ss); //sec设计 ss范围为00~59,此处的一秒为一个clk周期//不能把ss的8位直接拿来作为一个整体寄存器,否则12会输出为c//因此需要把这三个8位寄存器都分为2个4位的BCD计数器always @(posedge clk)beginif(reset)begin                //reset复位信号ss <= 8'b0;endelse if(ena)beginif((ss[7:4] == 4'd5) & (ss[3:0] == 4'd9))begin //当ss到59后下一个clk归0ss <= 8'b0;endelse begin              //需要考虑其中的两位BCD详细情况if(ss[3:0] == 4'd9)begin   //当ss的个位达到9需要归零,且ss的十位加1ss[3:0] <= 4'b0;ss[7:4] <= ss[7:4] + 1'b1;endelse beginss[3:0] <= ss[3:0] + 1'b1;endendendend//min设计 mm范围为00~59, clk的目的就是为了给mm归0always @(posedge clk)beginif(reset)begin               //reset复位信号 mm <= 8'b0;endelse if(ena & (ss[7:4] == 4'd5) & (ss[3:0] == 4'd9))begin  //当ena与ss达到59秒后,才可以后面操作加一if((mm[7:4] == 5) & (mm[3:0] == 9))beginmm <= 8'b0;endelse beginif(mm[3:0] == 4'd9)begin        //当mm的个位达到9需要归零,且mm的十位加1mm[3:0] <= 4'b0;mm[7:4] <= mm[7:4] + 1'b1;endelse beginmm[3:0] <= mm[3:0] + 1'b1; endendendend//hour设计 hh的范围为01~12always @(posedge clk)beginif(reset)begin             //reset复位信号 hh[7:4] <= 4'd1;hh[3:0] <= 4'd2;endelse beginif(ena & ((ss[7:4] == 4'd5) & (ss[3:0] == 4'd9)) & ((mm[7:4] == 5) & (mm[3:0] == 9)))beginif((hh[7:4] == 4'd1) & hh[3:0] == 2)beginhh[7:4] <= 4'd0;hh[3:0] <= 4'd1;endelse beginif(hh[3:0] == 4'd9)beginhh[3:0] <= 4'b0;hh[7:4] <= hh[7:4] + 1'b1;endelse beginhh[3:0] <= hh[3:0] + 1'b1;endendendendend//pmalways @(posedge clk)beginif(reset)beginpm <= 1'b0;endelse if((hh[7:4] == 4'd1) & (hh[3:0] == 4'd1) &(mm[7:4] == 4'd5) & (mm[3:0] == 4'd9) &(ss[7:4] == 4'd5) & (ss[3:0] == 4'd9))beginpm <= ~pm;           //当经过了12h后,pm进行翻转操作endend
endmodule

HDLbits 刷题答案practice——Counters相关推荐

  1. 【HDLBits 刷题】所有答案直达链接汇总

    写在前面 以下为HDLBits全部答案,有些题的解法不唯一,我的也许不是最优解,欢迎提出更好的想法,HDLBits总的来说比较适合初学者. HDLBits 答案汇总 Language [HDLBits ...

  2. 牛客网Veirlog刷题答案目录(持续更新)

    牛客网Veirlog刷题答案目录(持续更新) 基础篇 进阶篇 基础篇 1.VL1--四选一多路选择器 2.VL2--异步复位的串联T触发器 3.VL3--奇偶校验 4.VL4--移位运算与乘法 5.V ...

  3. SQL leetcode 刷题答案(二)

    承接上篇 SQL leetcode 刷题答案https://blog.csdn.net/hahaha66888/article/details/89925981 5.Big Countries sel ...

  4. 【HDLBits 刷题 9】Circuits(5)Finite State Manchines 1-9

    目录 写在前面 Finite State Manchines Fsm1 Fsm1s Fsm2 Fsm2s Fsm3comb Fsm3onehot Fsm3 Fsm3s Design a Moore F ...

  5. 【HDLBits 刷题 10】Circuits(6)Finite State Manchines 10-17

    目录 写在前面 Finite State Manchines Lemmings1 Lemmings2 Lemmings3 Lemmings4 Fsm onehot Fsm ps2 Fsm ps2dat ...

  6. 【HDLBits 刷题 11】Circuits(7)Finite State Manchines 18-26

    目录 写在前面 Finite State Manchines Fsm serialdata Fsm serialdp Fsm hdlc Design a Mealy FSM ece241 2014 q ...

  7. 【HDLBits 刷题 12】Circuits(8)Finite State Manchines 27-34

    目录 写在前面 Finite State Manchines 2014 q3c m2014 q6b m2014 q6c m2014 q6 2012 q2fsm 2012 q2b 2013 q2afsm ...

  8. HDLBits刷题合集—9 Arithmetic Circuits

    HDLBits刷题合集-9 Arithmetic Circuits HDLBits-66 Hadd Problem Statement 创建一个半加器.半加器将两个输入(不带低位的进位)相加产生和和向 ...

  9. 《LeetCode刷题答案》pdf出炉,学习者乐坏了

    很多朋友在后台留言说,刷LeetCode上的数据结构+算法题时难免会遇到困难,想要找一本答案题解做参考. 其实几个月之前,咱们这里已经分享过一本<LeetCode算法题的PDF版题解>,只 ...

最新文章

  1. I00002 打印九九乘法表
  2. Python编程快速上手-字典
  3. 面试了100个数据分析候选人以后,我总结出了这些面试问题
  4. sql语句Order by 报错列名不明确
  5. 判断两颗棵二叉树是否相等
  6. 看了就知道为什么别人C语言学习效率那么高了
  7. 即时通讯 我穿上球鞋
  8. PAT乙级1088 三人行 (20分)
  9. 转载 2012年游戏行业人才需求预测
  10. BZOJ1014 [JSOI2008]火星人
  11. Aladdin and the Flying Carpet(LightOJ - 1341)(欧拉筛 + 质因数分解)
  12. 上下协同,用友IPD的研发管理之道(下)
  13. 查公众号文章阅读量接口,简单版本
  14. Java面试宝典(2019版)
  15. [机器学习算法]支持向量机SVM原理简介
  16. C#:Invoke 和 BeginInvoke 的真正涵义
  17. 概率论与数理统计习题解答
  18. eclipse设置maven仓库为阿里云仓库
  19. 用scratch2.0编射击游戏
  20. Qt实现小型的超市收银系统

热门文章

  1. 【CF1389】E. Calendar Ambiguity(数论)
  2. Kali配置LNMP环境并搭建pikachu环境
  3. 基本数据类型和它们之间的运算规则
  4. 柏创机器人_【SU】20201228——20年度回顾 | 180个售楼处、示范区
  5. Oracle快速入门 | 黑马
  6. c语言8 8点阵,共阴共阳的疑问解答以及8*8LED点阵基础知识讲解
  7. 圣基茨旅游景点大盘点,当地人才知道的旅游胜地!
  8. 固定开头的电话号码的中间四位号码的屏蔽
  9. AV1源码分析(一)
  10. maven跳过Test进行打包