找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 1922|回复: 1
打印 上一主题 下一主题
收起左侧

VHDL实现16位计数器(带源程序)

[复制链接]
跳转到指定楼层
楼主
计数器简介:
        计数器是数字系统中用得较多的基本逻辑器件。它不仅能记录输入时钟脉冲的个数,还可以实现分频、定时、产生节拍脉冲和脉冲序列等。例如,计算机中的时序发生器、分频器、指令计数器等都要使用计数器。 计数器的种类很多。按时钟脉冲输入方式的不同,可分为同步计数器和异步计数器;按进位体制的不同,可分为二进制计数器和非二进制计数器;按计数过程中数字增减趋势的不同,可分为加计数器、减计数器和可逆计数器。
       以下是VHDL代码和仿真:



  1. library ieee;
  2. use ieee.std_logic_1164.all;
  3. use ieee.std_logic_arith.all;
  4. use ieee.std_logic_unsigned.all;
  5. --------------------------------------------------------------------
  6. entity exp3 is
  7. port( clk,ret,en : in std_logic; --定义时钟、异步复位、同步使能信号
  8. cq : out std_logic_vector(3 downto 0); --计数结果
  9. cout : out std_logic --进位信号
  10. );
  11. end exp3;
  12. --------------------------------------------------------------------
  13. architecture behave of exp3 is
  14. begin
  15. process(clk,ret,en)
  16. variable cqi : std_logic_vector(3 downto 0);
  17. begin
  18. if ret='0' then cqi:=(others =>'0');-- 计数器异步复位
  19. elsif clk'event and clk='1' then--检测时钟上升沿
  20. if en='1' then--检测是否允许计数(同步使能)
  21. if cqi<15 then cqi:=cqi+1;
  22. else cqi:=(others =>'0');
  23. end if;
  24. end if;
  25. end if;
  26. if cqi>9 then cout<='1';--输出进位信号
  27. else cout<='0';
  28. end if;
  29. cq<=cqi;--计数值向端口输出
  30. end process;
  31. end behave;
复制代码

代码下载: 16位计数器.zip (238.31 KB, 下载次数: 9)

评分

参与人数 1黑币 +40 收起 理由
admin + 40 共享资料的黑币奖励!

查看全部评分

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

沙发
ID:228452 发表于 2022-7-29 22:57 | 只看该作者
Do you have code for 32 bit counter...
Something like HCTL-2032-SC
(32 bit counter with digital filter but obsolete chip)

    Thank you   
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表