【发布时间】:2016-05-21 14:41:24
【问题描述】:
我正在尝试制作一个四位向上/向下模10 计数器。 Button1 - 向上计数,Button2 - 向下计数。我正在尝试使用rising_edge 命令来执行此操作,但是对于我无法使用按钮定义的两个信号被按下。所以在下一个版本的程序中,我想使用 if 语句检测按钮。
library IEEE;
use IEEE.std_logic_1164.all, IEEE.numeric_std.all;
ENTITY counter is
generic (n:natural :=4);
port(
button1: in std_logic;
button2: in std_logic;
clear: in std_logic;
C : out std_logic;
OUT1 : out std_logic_vector(n-1 downto 0)
);
END counter;
ARCHITECTURE beh of counter is
begin
p0:process (button1, clear) is
variable count: unsigned (n-1 downto 0);
begin
if clear = '1' then
count:= (others=>'0');
elsif button1='1' then
count:=count+1;
elsif count=10 then
count:=(others=>'0');
C<='1';
else C<='0';
end if;
if button2='1' then
count:=count-1;
if count=0 then
count:=(others=>'1');
C<='1';
else C<='0';
end if;
end if;
OUT1<=std_logic_vector(count);
end process p0;
end architecture beh;
在 Quartus 程序中编译没有错误,但在仿真中不起作用。 我会非常乐意提供帮助。 :)
【问题讨论】:
-
尝试在您的敏感度列表中添加
button2。 -
打算用这个来编程和FPGA吗?如果是这样,那么你离你需要的地方还有很长的路要走。
-
我没有 FPGA 开发套件,所以虽然我现在想运行仿真。我将 button2 添加到灵敏度列表中,但模拟仍然不起作用。
-
您永远无法使用此代码对 FPGA 进行编程。计数器是一个顺序电路:任何硬件计数器都需要一个时钟。因此,您拥有的是 VHDL 中的一些任意“程序”,您可能会或可能无法开始工作。但是 VHDL 是一种HW 描述语言,而不是一种软件编程语言,所以我猜你在某些时候是针对硬件的。所以,我建议你谷歌“vhdl counter”看看它是怎么做的,也看看我的回答here。