当前位置:   article > 正文

VHDL实现计数器_vhdl计数器

vhdl计数器

10进制同步计数器

  1. LIBRARY IEEE;
  2. USE IEEE.STD_LOGIC_1164.ALL;
  3. USE IEEE.STD_LOGIC_UNSIGNED.ALL;
  4. ENTITY cnt10 IS
  5. PORT(clk:IN STD_LOGIC;
  6. data:OUT STD_LOGIC_VECTOR(3 DOWNTO 0);
  7. co:OUT STD_LOGIC);
  8. END cnt10;
  9. ARCHITECTURE cnt10_behavior OF cnt10 IS
  10. SIGNAL temp1:STD_LOGIC;
  11. SIGNAL cnt:STD_LOGIC_VECTOR(3 DOWNTO 0);
  12. BEGIN
  13. PROCESS(clk)
  14. BEGIN
  15. IF(clk'EVENT AND clk='1')THEN --一个时钟信号
  16. IF(cnt="1001")THEN --10进制
  17. cnt<="0000";
  18. temp1<='0';
  19. ELSIF(cnt="1000")THEN
  20. temp1<='1';
  21. cnt<=cnt+1;
  22. ELSE
  23. cnt<=cnt+1;
  24. END IF;
  25. END IF;
  26. END PROCESS;
  27. co<=temp1;
  28. data<=cnt;
  29. END cnt10_behavior;

16进制异步计数器

  1. --定义底层文件:异步复位的D触发器
  2. LIBRARY IEEE;
  3. USE IEEE.STD_LOGIC_1164.ALL;
  4. ENTITY dtrigger IS
  5. PORT(d,clk,r:IN STD_LOGIC;
  6. q,dq:OUT STD_LOGIC);
  7. END dtrigger;
  8. ARCHITECTURE dtrigger_behavior OF dtrigger IS
  9. BEGIN
  10. PROCESS(clk,r)
  11. BEGIN
  12. IF(r='0')THEN
  13. q<='0';
  14. qd<='1';
  15. ELSIF(cp'EVENT AND clk='1')THEN
  16. q<=d;
  17. qd<=NOT d;
  18. END IF;
  19. END PROCESS;
  20. END dtrigger_behavior;
  1. --顶层文件,元件例化
  2. LIBRARY IEEE;
  3. USE IEEE.STD_LOGIC_1164.ALL;
  4. ENTITY count16 IS
  5. PORT(clk:IN STD_LOGIC;
  6. r:IN STD_LOGIC;
  7. q:OUT STD_LOGIC_VECTOR(3 DOWNTO 0));
  8. END count16;
  9. ARCHITECTURE count16_behavior OF count16 IS
  10. COMPONENT dtrigger
  11. PORT(d,clk,r:IN STD_LOGIC;
  12. q,dq:OUT STD_LOGIC);
  13. END COMPONENT;
  14. SIGNAL temp:STD_LOGIC_VECTOR(4 DOWNTO 0);
  15. BEGIN
  16. temp<=clk;
  17. G1:FOR i IN 0 TO 3 GENERATE
  18. dtriggerx:dtrigger PORT MAP(temp(i+1),temp(i),r,q(i),temp(i+1));
  19. END GENERATE G1;
  20. END count16_behavior;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/467451
推荐阅读
相关标签
  

闽ICP备14008679号