【问题标题】:Up/Down counter with push button带按钮的加/减计数器
【发布时间】:2020-03-19 06:14:36
【问题描述】:

我正在使用 FPGA 编写计时器。

我将使用七段显示来显示数字,但我还必须能够通过增加/减少来设置特定时间,然后一旦设置好,用另一个按钮时钟将开始下降。

signal lock 是为了防止计数以速度增加

manual 是一个按钮,

我想向上计数是可以的,但问题是我何时希望它向下计数。在模拟时我把sentido HIGH 然后我什么都没有得到并且不起作用。

library ieee;
use ieee.std_logic_1164.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity counter is
port(   clck, reset : in std_logic;
        limit   : in integer range 0 to 10;
        manual: inout std_logic;
        sentido: in std_logic;
        bitcount : out std_logic_vector(3 downto 0);
        clckout : out std_logic);
end counter;

architecture behavior of counter is
signal Cs : std_logic_vector(3 downto 0):="0000";
signal lock: std_logic;
begin   
Count : process(clck,reset,manual,lock,sentido)
    begin

            if(rising_edge(clck))then
             if (manual='0' and lock ='0') then
                      Cs<=Cs+1;
                       lock<='1';
             elsif(manual='1' and lock='1' ) then        
                     lock<='1';
             else
                     lock<='0';

                    end if; 
                    end if;

    if sentido = '1' then
                 Cs<=Cs-1;
                    end if;

            if (reset = '1') then
                    Cs <="0000";
                end if;
                if (Cs = "1010") then
                      Cs <= "0000";
                end if;
end process Count;
bitcount <=Cs;

end behavior;

【问题讨论】:

    标签: fpga stopwatch


    【解决方案1】:

    你的

    if sentido = '1'
    

    子句是异步的,它完全独立于时钟工作。这在大多数工具中是不可合成的,但可能会通过模拟器检查。

    以下所有条件都是如此。

    要解决这个问题,您应该将它们全部融合到您的 if(rising_edge(clck)) 子句中,如下所示:

    if(rising_edge(clck))then
            if (reset = '1') then
                Cs <="0000";
            elsif (manual='0' and lock ='0') then
                if sentido = '1' then
                    Cs<=Cs-1;
                    if (Cs = "0000") then --using previous state
                        Cs <= "1010";
                    end if;
                else
                    Cs<=Cs+1;
                    if (Cs = "1001") then --using previous state
                        Cs <= "0000";
                    end if;
                end if;
                lock<='1';
            elsif(manual='1' and lock='1' ) then        
                lock<='1';
            else
                lock<='0';
            end if; 
        end if;
    

    哦,还有一件事。您不应该在同步进程敏感度列表中包含除时钟之外的任何内容,无论如何它只会在时钟上更改任何内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-27
      • 2011-07-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多