VHDL - Incrementing Register Value on Push Button Event

落爺英雄遲暮 提交于 2019-12-06 07:01:14

You can do a simple edge-detection in a clocked process, and then just react to rising edges. For instance:

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;

To get everything working correctly, you'll need to make sure that your pushbuttons are debounced in some way though. Many development boards have a hardware RC circuit for this, but otherwise you'll need to do it in your code (which isn't that hard though - there should be plenty examples of this around on the net).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!