2017-01-22 1 views
-2

나는 자율 주행 차를 개발하려고합니다. 나는 우리 차 바퀴 바퀴의 수를 세는 센서를 가지고있다. 랩 수가 특정 입력 번호에 도달하면 상태가 변경되지만 if 문은 작동하지 않는 것처럼 보입니다. 두 숫자를 비교하는 대신 입력 vuelta가 모두 '1'이 될 때까지 else 문을 입력합니다. 코드를 변경하고 if (vueltas < 15)라고 쓰면 작동합니다. 하지만 번호를 변경해야합니다. 이것은 코드입니다, 나는이 입력 번호의 랩 수만큼 프로그램을 같은 상태로 유지하길 원합니다. 나는 이미 입력 번호가 정확하고 15라는 것을 증명했다. elsif (obst = '1')는 차가 장애물을 감지 할 경우를 대비 한 것이지만이 문제는 중요하지 않다.VHDL - <문이 ​​작동하지 않는 경우

주 :이 std_logic_vector에 (<이 경우) 산술 비교를 수행 할 수 있지만 그 여부를 알 수로 스페인어

  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; 
+2

[최소 완전하고 검증 가능한 예제를 만드는 방법] (http://stackoverflow.com/help/mcve)을 참조하십시오. 귀하의 질문은 독자가 귀하의 문제를 재현하는 것을 허용하지 않습니다. – user1155120

답변

0

에서 vueltas의 = 바퀴는, 아마, 가장 좋은 방법이 아닙니다 기본 값은 부호가 있거나 부호가 없습니다. 산술 또는 비교가 필요한 경우 numeric_std 패키지의 unsigned 또는 signed 유형을 사용하십시오.

좋은 토론은 here입니다.

+0

여전히 작동하지 않습니다. 여전히 동일합니다. 코드를 변경했습니다. 내가 할 수있는 다른 변경 사항이 있습니까? – ainhoarru

+0

@ainhoarru 그건 사실이 아니야. 일반적으로'std_logic_vector'로 산술 연산을 할 수는 없지만,'std_logic_vector'와'<'및 유사한 연산자를 비교할 수 있습니다. 그러나 벡터의 길이가 다른 경우주의해야합니다. 이상한 결과가 발생합니다. –

+1

@MatthewTaylor 귀하의 의견을 반영하기 위해 제 대답을 편집했습니다. SLV에서 산술 비교를하는 것이 가능하다고 말하는 것은 맞지만 좋은 디자인 연습이라고는 생각하지 못했습니다. – gsm

관련 문제