【发布时间】: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;
【问题讨论】: