VHDL-在按钮事件时递增寄存器值 [英] VHDL - Incrementing Register Value on Push Button Event

查看:128
本文介绍了VHDL-在按钮事件时递增寄存器值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对VHDL还是很陌生,并且正在尝试弄清楚如何在Altera Cyclone II上做一些相当基础的事情. FPGA有四个按钮-其中两个按钮需要编程以增大和减小所选寄存器(0-F),而两个按钮需要编程以增大和减小将要存入的值(从00到FF).该寄存器.这是我到目前为止的内容:

I am very new to VHDL and am trying to figure out how to do something fairly basic on an Altera Cyclone II. The FPGA has four push buttons - two of them need to be programmed to increase and decrease the selected register (0-F), and the two need to be programmed to increase and decrease the value (from 00 to FF) that will be in that register. Here is what I have so far:

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;

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

Could someone provide some basic sample code as to how to go about programming the push buttons?

推荐答案

您可以在时钟控制的process中执行简单的边缘检测,然后仅对上升沿做出反应.例如:

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;

为使所有功能正常运行,您需要确保按某种方式消除按键的抖动.许多开发板都为此提供了一个硬件RC电路,但否则,您需要在代码中完成它(虽然并不难-网上应该有很多这样的例子).

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).

这篇关于VHDL-在按钮事件时递增寄存器值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆