【问题标题】:VHDL - Incrementing Register Value on Push Button EventVHDL - 增加按钮事件的寄存器值
【发布时间】:2013-01-24 03:49:35
【问题描述】:

我对 VHDL 非常陌生,正在尝试弄清楚如何在 Altera Cyclone II 上做一些相当基本的事情。 FPGA 有四个按钮 - 其中两个需要被编程来增加和减少选定的寄存器 (0-F),另外两个需要被编程来增加和减少将在的值 (从 00 到 FF)那个寄存器。这是我目前所拥有的:

entity raminfr is
    port (
        clk : in std_logic;
        we : in std_logic;
        a : in unsigned(3 downto 0);
        di : in unsigned(7 downto 0);
        do : out unsigned(7 downto 0)
    );
end raminfr;

architecture rtl of raminfr is
type ram_type is array (0 to 15) of unsigned(7 downto 0);
signal RAM : ram_type;
signal read_a : unsigned(3 downto 0);

begin

process (clk)
begin
    if rising_edge(clk) then
        if we = '1' then
            RAM(to_integer(a)) <= di;
        end if;
        read_a <= a;
    end if;
end process;

do <= RAM(to_integer(read_a));

end rtl;

有人可以提供一些基本的示例代码来说明如何对按钮进行编程吗?

【问题讨论】:

    标签: vhdl fpga intel-fpga


    【解决方案1】:

    您可以在时钟 process 中进行简单的边沿检测,然后对上升沿做出反应。例如:

    signal lastButtonState    : std_logic := '0';
    
    process(clk)
    begin
      if(rising_edge(clk)) then
        if(buttonState = '1' and lastButtonState = '0') then      --assuming active-high
          --Rising edge - do some work...
        end if;
        lastButtonState <= buttonState;
      end if;
    end process;
    

    为了让一切正常工作,您需要确保您的按钮以某种方式去抖动。许多开发板为此都有一个硬件 RC 电路,否则您需要在代码中执行此操作(虽然这并不难 - 网上应该有很多这样的示例)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-03
      相关资源
      最近更新 更多