我知道错误的含义以及错误的原因,但无法弄清楚如何以其他方式进行。
无法在 snake_driver 解析网络“snake[17]”的多个常量驱动程序。
(和其他人一样)
任务是我们在 std_logic_vector 中有一条“移动的蛇”,它是端到端的,当你按下按钮(切换信号)时,蛇会改变它的长度(2、3、4、5、6, 2, ...)
显然,蛇向量因此必须由监听切换的进程和监听时钟的进程来改变。当我将两者放在同一个进程中时,我得到一个错误,两个边缘检测不能在同一个进程中。
/\____ +--------------------+
toggle ----> change length |
| v |
| [snake register] =====> snake 17 downto 0
\/\/\/ | ^ |
clock ----> move one step |
+--------------------+
欢迎任何想法。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity snake_driver is
generic
(
LEN : integer := 18;
MAX_SNAKE_LEN : integer := 6
);
port
(
clk : in std_logic;
change : in std_logic;
output : out std_logic_vector(LEN-1 downto 0)
);
end snake_driver;
architecture Anaconda of snake_driver is
signal snake : std_logic_vector(LEN-1 downto 0) := (0 => '1', 1 => '1', others => '0'); -- two snake pieces
signal dir_right : boolean := FALSE; -- start left
begin
process(change)
variable data : std_logic_vector(LEN-1 downto 0); -- two snake pieces
variable snake_len : integer := 2; -- snake 2 long
begin
if rising_edge(change) then -- change snake length
-- add snake piece based on direction
data := snake; -- <-- here I tried to avoid the problem
-- by caching snake data. To no avail.
if snake_len = MAX_SNAKE_LEN then
snake_len := 2;
-- shorten to 2 len
if dir_right then
-- moving right, remove from left
data := std_logic_vector(unsigned(data) and shift_right(unsigned(data), MAX_SNAKE_LEN-2));
else
-- moving left, remove from right
data := std_logic_vector(unsigned(data) and shift_left(unsigned(data), MAX_SNAKE_LEN-2));
end if;
else
-- add one at the end
if dir_right then
-- moving right, add on left
data := std_logic_vector(unsigned(data) or shift_left(unsigned(data), 1));
else
-- moving left, add on right
data := std_logic_vector(unsigned(data) or shift_right(unsigned(data), 1));
end if;
end if;
snake <= data;
end if;
end process;
-- move snake on clock
process(clk)
-- variables in the process
variable data : std_logic_vector(LEN-1 downto 0);
begin
-- shift the snake
if rising_edge(clk) then
data := snake;
if dir_right then
-- right move
data(LEN-2 downto 0) := data(LEN-1 downto 1);
if data(0) = '1' then
dir_right <= FALSE; -- change direction
end if;
else
-- left move
data(LEN-1 downto 1) := data(LEN-2 downto 0);
if data(LEN-1) = '1' then
dir_right <= TRUE; -- change direction
end if;
end if;
snake <= data;
end if;
end process;
-- send changed data to output
output <= snake;
end Anaconda;