Проект лифта в VHDL компилируется, но не работает в симуляции
Я пытаюсь сделать лифт в VHDL, чтобы быть реализованным на FPGA. Он имеет 0-12 этажей, имеет кнопки для перемещения вверх / вниз снаружи, в зависимости от того, в каком направлении вы хотите идти, и кнопки внутри. Сначала я проверяю, работают ли внешние кнопки, реализация для внутренней части такая же. Сейчас он компилируется, но сигнал симуляции падает.
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.numeric_std.all;
entity lift is
port (
CLK: in bit; --clock initialized by the waveform, for now
iUP: in std_logic_vector (3 downto 0); --input from FPGA
iDOWN: in std_logic_vector (3 downto 0); --output
iBUTTON: in std_logic_vector (3 downto 0); --input from inside the elevator
W: in BIT; --weight s
DOOR: in BIT; --door opened or not
ETAJ: out std_logic_vector (12 downto 0):="0000000000001"); --output to LCD
end lift;
architecture mama of lift is
signal directie: bit := '1'; --direction of lift, 1 up / 0 down
signal pozitie: natural := 0; --position of lift, 0-12
signal sus: bit; --up
signal jos: bit; --down
signal UP: std_logic_vector(12 downto 0) :="0000000000000"; --vector for the outside inputs that ask to go up
signal DOWN: std_logic_vector(12 downto 0) :="0000000000000"; --same as above, but down
begin
merge: process (UP, DOWN, pozitie) --process to determine if the lift goes up or down
variable i : std_ulogic; --the vector with the outside inputs has 1 if the button is pressed, 0 otherwise
variable j : std_ulogic;
begin
for i in pozitie+1 to 12 loop
if UP(i) = '1' then
sus <= '1';
end if;
end loop;
for j in pozitie-1 to 0 loop
if DOWN(j) = '1' then
jos <= '1';
end if;
end loop;
end process merge;
conv: process(iUP, iDOWN) --converts input from binary to int
begin
UP(to_integer(unsigned(iUP)))<='1';
DOWN(to_integer(unsigned(iDOWN)))<='1';
end process conv;
moovit: process (UP, DOWN, iBUTTON) --the moving process
variable i : std_ulogic;
begin
if directie='1' then --if direction is up and it has to go up
while sus='1' loop
if CLK'EVENT and CLK='1' and UP(pozitie)='1' then
UP(pozitie)<='0';
DOWN(pozitie)<='0';
end if;
pozitie <= pozitie + 1;
end loop;
else
while jos='1' loop
if CLK'EVENT and CLK='1' and DOWN(pozitie)='1' then
DOWN(pozitie)<='0';
UP(pozitie)<='0';
end if;
pozitie <= pozitie - 1;
end loop;
end if;
end process;
end mama;
1 ответ
В вашем коде есть много вещей, которые не совместимы с синтезом. Или, по крайней мере, я не уверен, что это сработает. Например
merge: process (UP, DOWN, pozitie)
[...]
for i in pozitie+1 to 12 loop
if UP(i) = '1' then
Вы используете цикл for с переменной длиной. Это легко в процессоре, но вы пишете HDL (Hardware Description Language): как, по-вашему, будет работать переменное количество логических элементов?
В этом случае вам следует использовать компаратор. Например:
if unsigned(iDOWN) < pozitie then
jos <= '1';
Тогда посмотри на свой синхронизированный процесс. Вы, кажется, знаете, как ввести часы с CLK'EVENT and CLK='1'
, Но вы положили заявление внутри if
заявления и даже while
заявление! Опять же: как вы ожидаете, что это будет реализовано в оборудовании?
Обычный процесс синхронизации часов выглядит так:
clk_process: process(clk)
begin
if rising_edge(clk) then
[synchronous statement]
end if;
end process;
ps drop use ieee.std_logic_unsigned.all;
если вы уже используете numeric_std
,