我正在嘗試開發一種自動駕駛汽車。我有一個傳感器來計算我們汽車車輪的圈數。當圈數達到一個特定的輸入數字時,它應該改變狀態,但if語句似乎沒有工作。不是比較這兩個數字,而是輸入else語句,直到輸入vueltas全部爲「1」。如果我更改了代碼,並寫入if(vueltas < 15),它就可以工作。但我需要的數字是可以改變的。這是代碼,我希望程序保持相同的狀態,直到這個輸入數字的圈數爲止。我已經證明輸入的數字是正確的,並且是15。elsif(obst ='1')是在汽車檢測到障礙物的情況下,但這與這個問題無關。VHDL - if <語句不起作用
注:vueltas在西班牙
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
--use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Circuito is Port (
clk : in STD_LOGIC;
ir1 : in STD_LOGIC;
ir2 : in STD_LOGIC;
moverCoche : in STD_LOGIC;
angulo : in STD_LOGIC_VECTOR(4 downto 0);
vMaxCurva : in STD_LOGIC_VECTOR(4 downto 0);
posInicial : in STD_LOGIC_VECTOR(9 downto 0);
vueltasCurva : in STD_LOGIC_VECTOR(9 downto 0);
vueltasRecta : in STD_LOGIC_VECTOR(9 downto 0);
obst : in STD_LOGIC;
servoOut : out STD_LOGIC;
motorOut : out STD_LOGIC;
vueltasLed : out STD_LOGIC_VECTOR(9 downto 0);
vueltasDentroDeCircuito : out STD_LOGIC_VECTOR(11 downto 0);
revolucionesPorSeg : out STD_LOGIC_VECTOR(11 downto 0));
end Circuito;
architecture Behavioral of Circuito is
component motor_pwm_clk32kHz is Port (
clk : in STD_LOGIC;
entrada : in STD_LOGIC_VECTOR(4 downto 0);
salida : out STD_LOGIC);
end component;
component servo_pwm_clk32kHz is Port (
clk : in STD_LOGIC;
pos : in STD_LOGIC_VECTOR(4 downto 0);
servo : out STD_LOGIC);
end component;
component Contador_Vueltas is Port (
out1 : in STD_LOGIC; --Negro: 1 Blanco: 0
out2 : in STD_LOGIC; --Negro: 1 Blanco: 0
vueltas : out STD_LOGIC_VECTOR (9 downto 0);
rst : in STD_LOGIC;
clk : in STD_LOGIC);
end component;
component revoluciones is Port (
clk : in STD_LOGIC;
vueltasDentroDeCircuito : in STD_LOGIC_VECTOR(11 downto 0);
revoluciones : out STD_LOGIC_VECTOR(11 downto 0));
end component;
signal posServo, posMotor: STD_LOGIC_VECTOR(4 downto 0);
signal vueltas : STD_LOGIC_VECTOR(9 downto 0);
signal primeraVuelta : STD_LOGIC := '1';
signal sigReiniciarVueltas : STD_LOGIC;
signal sigVueltasDentroDeCircuito : STD_LOGIC_VECTOR(11 downto 0);
signal sigVueltasInicioEstado : STD_LOGIC_VECTOR(11 downto 0);
--signal sigVueltasRecta : unsigned := to_integer(unsigned(vueltasRecta));
--constant sigVueltasRecta : STD_LOGIC_VECTOR(9 downto 0) := "0000011110";
--constant sigVueltasCurva : STD_LOGIC_VECTOR(9 downto 0) := "0000011110";
signal flag : STD_LOGIC := '0';
signal Qt: STD_LOGIC_VECTOR(3 downto 0);
SUBTYPE STATE_TYPE IS STD_LOGIC_VECTOR(3 downto 0);
SIGNAL STATE: STATE_TYPE;
CONSTANT s0 : STATE_TYPE := "0000";
CONSTANT s1 : STATE_TYPE := "0001";
CONSTANT s2 : STATE_TYPE := "0010";
CONSTANT s3 : STATE_TYPE := "0011";
CONSTANT s4 : STATE_TYPE := "0100";
CONSTANT s5 : STATE_TYPE := "0101";
CONSTANT s6 : STATE_TYPE := "0110";
CONSTANT s7 : STATE_TYPE := "0111";
CONSTANT s8 : STATE_TYPE := "1000";
begin
UUT_Motor: motor_pwm_clk32kHz Port Map (
clk => clk,
entrada => posMotor,
salida => motorOut);
UUT_Servo: servo_pwm_clk32kHz Port Map (
clk => clk,
pos => posServo,
servo => servoOut);
UUT_ContadorVueltas: Contador_Vueltas Port Map (
clk => clk,
rst => sigReiniciarVueltas,
vueltas => vueltas,
out1 => ir1,
out2 => ir2);
UUT_Revoluciones: revoluciones Port Map(
clk => clk,
vueltasDentroDeCircuito => sigVueltasDentroDeCircuito,
revoluciones => revolucionesPorSeg
);
process(clk, moverCoche)
begin
if (moverCoche = '0') then
Qt <= s0;
sigReiniciarVueltas <= '1';
sigVueltasDentroDeCircuito <= (others => '0');
posServo <= "10000";
posMotor <= "10000";
elsif (clk'event and clk = '1') then
case Qt is
--Quieto
when s0 =>
posServo <= "10000";
posMotor <= "10000";
sigReiniciarVueltas <= '0';
Qt <= s1;
--Recta1
when s1 =>
sigReiniciarVueltas <= '0';
posServo <= "10000";
posMotor <= vMaxCurva; --Min: 10011
sigVueltasDentroDeCircuito <= ("00" & vueltas);
if (unsigned(vueltas) >= unsigned(vueltasRecta)) then
Qt <= s2;
sigReiniciarVueltas <= '1';
elsif (obst = '1') then
Qt <= s8;
else
-- sigVueltasRecta <= vueltasRecta;
Qt <= s1;
end if;
-- Curva1
when s2 =>
sigReiniciarVueltas <= '0';
posServo <= angulo;
posMotor <= vMaxCurva;
sigVueltasDentroDeCircuito <= posInicial + ("00" & vueltas);
if (unsigned(vueltas) >= unsigned(vueltasCurva)) then
sigReiniciarVueltas <= '1';
Qt <= s3;
elsif (obst = '1') then
Qt <= s8;
else
Qt <= s2;
end if;
--Recta2
when s3 =>
sigReiniciarVueltas <= '0';
posServo <= "10000";
posMotor <= vMaxCurva; --Min: 10011
sigVueltasDentroDeCircuito <= posInicial + vueltasCurva + ("00" & vueltas);
if (unsigned(vueltas) >= unsigned(vueltasRecta)) then
sigReiniciarVueltas <= '1';
Qt <= s4;
elsif (obst = '1') then
Qt <= s8;
else
Qt <= s3;
end if;
--Curva2
when s4 =>
sigReiniciarVueltas <= '0';
posServo <= angulo;
posMotor <= vMaxCurva;
sigVueltasDentroDeCircuito <= posInicial + vueltasCurva + vueltasRecta + ("00" & vueltas);
if (unsigned(vueltas) >= unsigned(vueltasCurva)) then
sigVueltasDentroDeCircuito <= (others => '0');
sigReiniciarVueltas <= '1';
Qt <= s4;
elsif (obst = '1') then
Qt <= s8;
else
Qt <= s1;
end if;
--Mantener Quieto
when s5 =>
posMotor <= "10000";
Qt <= s5;
when others =>
if(obst = '1') then
posMotor <= "00000";
--sigReiniciarVueltas <= '0';
Qt <= s8;
else
Qt <= s1;
end if;
end case;
vueltasDentroDeCircuito <= sigVueltasDentroDeCircuito;
vueltasLed <= vueltasRecta;
end if;
end process;
end Behavioral;
請參閱[如何創建最小,完整和可驗證示例](http://stackoverflow.com/help/mcve)。你的問題不允許你的讀者重現你的問題。 – user1155120