zoukankan      html  css  js  c++  java
  • VHDL设计----十进制计数器

    一、异步复位加法计数器

     代码:

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_unsigned.all;
    entity CNT10 is
        port(
            CLK,RST,EN: in std_logic;
            DOUT : out std_logic_vector (3 downto 0);
            COUT : OUT std_logic
        );
    end CNT10;
    architecture behav of CNT10 is
    begin
        process(CLK,RST,EN)
            variable Q : std_logic_vector (3 downto 0);
        begin
        if RST = '1' then Q := (others => '0');
        elsif CLK 'event and CLK = '1' then
                if EN = '1' then 
                    if Q < 9 then Q := Q + 1;
                    else Q := (others => '0');
                    end if;
                end if;
        end if;
        if Q = "1001" then COUT <= '1';
        else COUT <= '0'; 
        end if;
        DOUT <= Q;
        end process;
    end behav;

    仿真:

    RST信号与CLK信号无关,随时可以置零

    二、同步复位加法计数器

    代码:

    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_unsigned.all;
    entity CNT10 is
        port(
            CLK,RST,EN: in std_logic;
            DOUT : out std_logic_vector (3 downto 0);
            COUT : OUT std_logic
        );
    end CNT10;
    architecture behav of CNT10 is
    begin
        process(CLK,RST,EN)
            variable Q : std_logic_vector (3 downto 0);
        begin
        if CLK 'event and CLK = '1' then
            if RST = '1' then Q := (others => '0');
            else
                if EN = '1' then 
                    if Q < 9 then Q := Q + 1;
                    else Q := (others => '0');
                    end if;
                end if;
            end if;
        end if;
        if Q = "1001" then COUT <= '1';
        else COUT <= '0'; 
        end if;
        DOUT <= Q;
        end process;
    end behav;

    仿真:

    RST信号只有等到CLK信号的下一个上升沿到时才能清零

    三、总结

    所谓“同步”是指与系统时钟同步。同步复位是指当复位信号有效时,并不立刻生效,而是要等到复位信号有效之后系统时钟的有效边沿到达时才会生效;
    而异步复位则是立刻生效的,只要复位信号有效,无论系统时钟是怎样的,系统都会立即被复位。
    在用VHDL描述复位信号时,在系统时钟有效边沿到达之后才判断同步复位是否有效;而对异步复位的判断则与系统时钟无关。

     

    同步复位:
    IF clock'event AND clock='1' THEN
        IF reset='1' THEN
            -- 复位系统
        ELSE
            -- 正常运作
        END IF;
    END IF;
    异步复位:
    IF reset='1' THEN
        -- 复位系统
    ELSIF clock'event AND clock='1' THEN
        -- 正常运作
    END IF;
  • 相关阅读:
    php之static静态变量详解
    设计模式【代理模式】
    小牟Andorid下面MD5具体实现的思路总结
    ubuntu14.04安装MySQL
    Android手机定位技术的发展
    我不同意你,这是您的支持
    我要遵守11文章数据库设计指南
    quick-cocos2d-x游戏开发【3】——display.newSprite创建向导
    第二章 自己的框架WMTS服务,下载数据集成的文章1
    JSTL实现int数据的类型的长度
  • 原文地址:https://www.cnblogs.com/PythonFCG/p/8710898.html
Copyright © 2011-2022 走看看