HDLBits 系列(16)Something about Counter

举报
李锐博恩 发表于 2021/07/15 02:34:56 2021/07/15
【摘要】 目录 原题复现 题目1 我的设计 题目2 审题 我的设计 原题复现 题目1 一般的计数器我就不说了,这里看下面的要求: Build a decade counter that counts from 0 through 9, inclusive, with a period of 10. The reset input is synchronous, a...

目录

原题复现

题目1

我的设计

题目2

审题

我的设计


原题复现

题目1

一般的计数器我就不说了,这里看下面的要求:

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. We want to be able to pause the counter rather than always incrementing every clock cycle, so the slowena input indicates when the counter should increment.

我的设计

也就是计数不仅由时钟控制,还需要判断计数使能是否有效,在这里就是slowena,下面就设计一个计数器技术从0到9,且计数由使能控制。


  
  1. module top_module (
  2. input clk,
  3. input slowena,
  4. input reset,
  5. output [3:0] q);
  6. always@(posedge clk) begin
  7. if(reset) q <= 0;
  8. else if(slowena & q < 9) q <= q + 1;
  9. else if(slowena & q >= 9) q <= 0;
  10. end
  11. endmodule


题目2

再来一题稍微更难一点的计数器相关的题目:

Design a 1-12 counter with the following inputs and outputs:

Reset Synchronous active-high reset that forces the counter to 1

Enable Set high for the counter to run

Clk Positive edge-triggered clock input

Q[3:0] The output of the counter

c_enable, c_load, c_d[3:0] Control signals going to the provided 4-bit counter, so correct operation can be verified.

You have the following components available:

  • the 4-bit binary counter (count4) below, which has Enable and synchronous parallel-load inputs (load has higher priority than enable). The count4 module is provided to you. Instantiate it in your circuit.
  • logic gates

  
  1. module count4(
  2. input clk,
  3. input enable,
  4. input load,
  5. input [3:0] d,
  6. output reg [3:0] Q
  7. );

Module Declaration


  
  1. module top_module (
  2. input clk,
  3. input reset,
  4. input enable,
  5. output [3:0] Q,
  6. output c_enable,
  7. output c_load,
  8. output [3:0] c_d
  9. );

审题

如何设计这么一个计数器呢?

难点在于c_enable, c_load, c_d[3:0三个控制变量,我们先来看看他是什么意思吧。

这个计数器的功能是实现从1到12的计数,因此,如果复位reset有效,则计数复位为1,我们需要做的不是自己设计一个计数器,而是需要例化题目给的一个计数器,题目给的计数器需要有一个输入信号为load信号,我们需要产生一个load信号给予它,何时给予load信号有效呢?

当然是复位信号有效或者计数满(12)且计数使能有效;

因此,我们可以设计如下电路:

我的设计


  
  1. module top_module (
  2. input clk,
  3. input reset,
  4. input enable,
  5. output [3:0] Q,
  6. output c_enable,
  7. output c_load,
  8. output [3:0] c_d
  9. ); //
  10. //4-bit计数器的控制信号
  11. assign c_enable = enable;
  12. //带复位和置位,
  13. assign c_load = reset | (Q == 4'd12 & enable == 1'b1);
  14. // assign c_d = c_load ? 4'b1: 4'bx;
  15. assign c_d = 4'b1;
  16. count4 inst_count4
  17. (
  18. .clk(clk),
  19. .enable(c_enable),
  20. .load(c_load),
  21. .d(c_d),
  22. .Q(Q)
  23. );
  24. endmodule

 

 

 

文章来源: reborn.blog.csdn.net,作者:李锐博恩,版权归原作者所有,如需转载,请联系作者。

原文链接:reborn.blog.csdn.net/article/details/103230319

【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@huaweicloud.com
  • 点赞
  • 收藏
  • 关注作者

评论(0

0/1000
抱歉,系统识别当前为高风险访问,暂不支持该操作

全部回复

上滑加载中

设置昵称

在此一键设置昵称,即可参与社区互动!

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。

*长度不超过10个汉字或20个英文字符,设置后3个月内不可修改。