projet feux de carrefour VHDL
Répondre à la discussion
Affichage des résultats 1 à 8 sur 8

projet feux de carrefour VHDL



  1. #1
    invitef4879e8d

    projet feux de carrefour VHDL


    ------

    Bonjour je doit réaliser un feux de carrefour en vhdl.
    les feux doivent avoir 14 coups en vert, 1 en rouge, 2 en orange.
    2 passage piéton pris en compte qui passe le feu au rouge au bout de 3 coups
    J'ai deux solutions mais cela ne marche pas si quelqu'un peut m'aider :

    1er essaie:
    Code:
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;
    
    -- Uncomment the following library declaration if using
    -- arithmetic functions with Signed or Unsigned values
    --use IEEE.NUMERIC_STD.ALL;
    
    -- Uncomment the following library declaration if instantiating
    -- any Xilinx leaf cells in this code.
    --library UNISIM;
    --use UNISIM.VComponents.all;
    
    entity feux is
        Port ( REQV : in STD_LOGIC;
               REQH : in STD_LOGIC;
               H : in STD_LOGIC;
               raz : in STD_LOGIC;
               VH : out STD_LOGIC;
               YH : out STD_LOGIC;
               RH : out STD_LOGIC;
               VV : out STD_LOGIC;
               YV : out STD_LOGIC;
               RV : out STD_LOGIC;
               cp : out STD_LOGIC_VECTOR (3 downto 0));
    end feux;
    
    architecture Behavioral of feux is
    type state is (FVH,FYH,FRH,FVV,FYV,FRV);
    signal present_state, next_state : state;
    signal cpt : STD_LOGIC_VECTOR (3 downto 0);--compteur 4 bits
    begin
    
    process(cpt,present_state)
    begin
    
    case present_state is
    when FVH=> VH<='1'; YH<='0'; RH<='0'; VV<='0'; YV<='0'; RV<='1';               -- feu VERT voie HORIZONTALE-->feu ORANGE voie HORIZONTALE
      if cpt<="1110" then next_state<=FYH;
      end if;
    when FYH=> VH<='0'; YH<='1'; RH<='0'; VV<='0'; YV<='0'; RV<='1';              -- feu ORANGE voie HORIZONTALE-->feu ROUGE voie HORIZONTALE
      if cpt<="0010" then next_state<=FRH;
      end if;
    when FRH=> VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='0'; RV<='1';             -- feu ROUGE voie HORIZONTALE-->feu VERT voie VERTICAL
      if cpt<="0001" then next_state<=FVV;
      end if;
    when FVV=> VH<='0'; YH<='0'; RH<='1'; VV<='1'; YV<='0'; RV<='0';              -- feu VERT voie VERTICAL-->feu ORANGE voie VERTICAL
      if cpt<="1110" then next_state<=FYV;
      end if;
    when FYV=> VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='1'; RV<='0';              -- feu ORANGE voie VERTICALE-->feu ROUGE voie VERTICAL
      if cpt<="0010" then next_state<=FRV;
      end if;
    when FRV=> VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='0'; RV<='1';              -- feu ROUGE voie VERTICAL-->feu VERT voie HORIZONTALE
      if cpt<="0001" then next_state<=FVH;
      end if;
      end case;
      end process;
      
    process(H,raz) 
    begin 
    if (H'event and H = '1') then
    if raz ='1' then present_state<=FVH;
    else present_state<=next_state;
    end if;
    if present_state /= next_state then cpt<="0000"; -- incrémentation du compteur 
    end if;
    end if;
    
    end process;
    cp<=cpt;
    end Behavioral;
    
    2eme essaie :
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;
    
    -- Uncomment the following library declaration if using
    -- arithmetic functions with Signed or Unsigned values
    --use IEEE.NUMERIC_STD.ALL;
    
    -- Uncomment the following library declaration if instantiating
    -- any Xilinx leaf cells in this code.
    --library UNISIM;
    --use UNISIM.VComponents.all;
    
    entity feu is
        Port ( ReqV : in STD_LOGIC;
               ReqH : in STD_LOGIC;
               h : in STD_LOGIC;
               raz : in STD_LOGIC;
               VH : out STD_LOGIC;
               YH : out STD_LOGIC;
               RH : out STD_LOGIC;
               VV : out STD_LOGIC;
               YV : out STD_LOGIC;
               RV : out STD_LOGIC;
               q : out STD_LOGIC_VECTOR (3 downto 0));
    end feu;
    
    architecture Behavioral of feu is
    
    type StateType is (FVH,FYH,FRH,FVV,FYV,FRV); --on déclare les variable d'état
    signal couleur : StateType;
    signal qtemp : STD_LOGIC_VECTOR (3 downto 0);--compteur 4 bits
    begin
    
    state_comb : process(raz,ReqH,ReqV,couleur,h)
    begin 
    --if h'event and h='1' then qtemp<=qtemp+1 ; --coup d'horloge
    if raz='1' then qtemp<="0000"; --lancement des feux tricolores
    couleur<=FRV;
    
    elsif (ReqH='1' and couleur=FVH) then qtemp<="1011"; --gère la commande piéton voie horizontale
    --on donne la valeur 11, encore 3 coup et etats suivants ok
    elsif (ReqV='1' and couleur=FVV) then qtemp<="1011"; --gère la commande pièton voie vertical
    --on donne la valeur 11, encore 3 coup et etats suivants ok
    elsif (h'event and h='1') then
    qtemp <= qtemp + 1; 
    --14 coups pour passer le vert, 2 pour le orange et 1 pour le rouge
    case couleur is
    when FVH=>              -- feu VERT voie HORIZONTALE-->feu ORANGE voie HORIZONTALE
      if qtemp<="1110" then couleur<=FYH;
      qtemp<="0000";
      end if;
    when FYH=>              -- feu ORANGE voie HORIZONTALE-->feu ROUGE voie HORIZONTALE
      if qtemp<="0010" then couleur<=FRH;
      qtemp<="0000";
      end if;
    when FRH=>              -- feu ROUGE voie HORIZONTALE-->feu VERT voie VERTICAL
      if qtemp<="0001" then couleur<=FVV;
      qtemp<="0000";
      end if;
    when FVV=>              -- feu VERT voie VERTICAL-->feu ORANGE voie VERTICAL
      if qtemp<="1110" then couleur<=FYV;
      qtemp<="0000";
      end if;
    when FYV=>              -- feu ORANGE voie VERTICALE-->feu ROUGE voie VERTICAL
      if qtemp<="0010" then couleur<=FRV;
      qtemp<="0000";
      end if;
    when FRV=>              -- feu ROUGE voie VERTICAL-->feu VERT voie HORIZONTALE
      if qtemp<="0001" then couleur<=FVH;
      qtemp<="0000";
      end if;
      end case;
      end if;
      end process; 
    Q <= qtemp;
    
    
    VH<='1' when (couleur=FVH) else '0'; --valeurs de sortie selon les différents états
    YH<='1' when (couleur=FYH) else '0';
    RH<='1' when (couleur=FRH or couleur=FVV or couleur=FYV) else '0';
    VV<='1' when (couleur=FVV) else '0';
    YV<='1' when (couleur=FYV) else '0';
    RV<='1' when (couleur=FRV or couleur=FVH or couleur=FYH) else '0'; 
    
    end Behavioral;

    -----
    Dernière modification par Antoane ; 24/11/2018 à 18h12. Motif: Ajout de balises code

  2. #2
    JPL
    Responsable des forums

    Re : projet feux de carrefour VHDL

    Sujet déplacé en application de la règle suivante du forum de programmation : Règles participatives pour ce forum.
    Rien ne sert de penser, il faut réfléchir avant - Pierre Dac

  3. #3
    jiherve

    Re : projet feux de carrefour VHDL

    Bonsoir,
    Tout çà n'est pas trop clair de plus séparer le process synchrone de prise en compte des changement d’état de leur définition est peu judicieux, il manque un when others dans le case, le compteur n'est pas initialisé et ne compte jamais, essaye avec çà:
    Code:
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;
    
    
    entity feux is
        Port ( REQV : in STD_LOGIC;
               REQH : in STD_LOGIC;
               H : in STD_LOGIC;
               raz : in STD_LOGIC;
               VH : out STD_LOGIC;
               YH : out STD_LOGIC;
               RH : out STD_LOGIC;
               VV : out STD_LOGIC;
               YV : out STD_LOGIC;
               RV : out STD_LOGIC;
               cp : out STD_LOGIC_VECTOR (3 downto 0));
    end feux;
    
    architecture Behavioral of feux is
    type state is (FVH,FYH,FRH,FVV,FYV,FRV);
    variable  next_state : state;
    signal present_state: state;
    signal cpt : STD_LOGIC_VECTOR (3 downto 0);--compteur 4 bits
    begin
      
      process(H,raz) 
        begin 
          if raz ='1' then 
            present_state<=FVH;
            VH<='1'; YH<='0'; RH<='0'; VV<='0'; YV<='0'; RV<='1';
            cpt<="0000";
          elsif rising_edge(H) then
            case present_state is
              when FVH=> 
                VH<='1'; YH<='0'; RH<='0'; VV<='0'; YV<='0'; RV<='1';               -- feu VERT voie HORIZONTALE-->feu ORANGE voie HORIZONTALE
                if cpt<="1110" then 
                  next_state:=FYH;
                end if;
              when FYH=> 
                VH<='0'; YH<='1'; RH<='0'; VV<='0'; YV<='0'; RV<='1';              -- feu ORANGE voie HORIZONTALE-->feu ROUGE voie HORIZONTALE
                if cpt<="0010" then 
                  next_state:=FRH;
                end if;
              when FRH=> 
                VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='0'; RV<='1';             -- feu ROUGE voie HORIZONTALE-->feu VERT voie VERTICAL
                if cpt<="0001" then 
                  next_state:=FVV;
                end if;
              when FVV=>
                VH<='0'; YH<='0'; RH<='1'; VV<='1'; YV<='0'; RV<='0';              -- feu VERT voie VERTICAL-->feu ORANGE voie VERTICAL
                if cpt<="1110" then
                  next_state:=FYV;
                end if;
              when FYV=>
                VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='1'; RV<='0';              -- feu ORANGE voie VERTICALE-->feu ROUGE voie VERTICAL
                if cpt<="0010" then 
                  next_state:=FRV;
                end if;
              when FRV=> 
                VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='0'; RV<='1';              -- feu ROUGE voie VERTICAL-->feu VERT voie HORIZONTALE
                if cpt<="0001" then
                  next_state:=FVH;
                end if;
              when others =>
                null;
            end case;
            present_state <= next_state;
            if present_state /= next_state then 
              cpt<="0000"; -- incrémentation du compteur 
            else 
              cpt <= cpt+1;
            end if;
    
          end if;
       end process;
    end Behavioral;
    et indente cela aide la lecture et évite les bêtises!
    REQH et REQV ne servent à rien dans ce code.
    JR
    Dernière modification par jiherve ; 24/11/2018 à 20h47.
    l'électronique c'est pas du vaudou!

  4. #4
    invitef4879e8d

    Re : projet feux de carrefour VHDL

    Bonjour, merci de votre réponse et conseils. J'ai manipulé le code pour rajouter la demande piéton et sans utiliser next_state comme variable, à dire vraie j'ai jamais eu l'occasion de l'utiliser, quel en est l’intérêt ?
    J'ai toujours des problèmes lié sans doute au compteur, si vous pouvez y jeter un coup d’œil ? encore merci, ça m'a beaucoup aider à m'orienter !
    Code:
    library IEEE;
    use IEEE.STD_LOGIC_1164.ALL;
    use IEEE.STD_LOGIC_ARITH.ALL;
    use IEEE.STD_LOGIC_UNSIGNED.ALL;
    
    entity feux is
        Port ( REQV : in STD_LOGIC;
               REQH : in STD_LOGIC;
               H : in STD_LOGIC;
               raz : in STD_LOGIC;
               VH : out STD_LOGIC;
               YH : out STD_LOGIC;
               RH : out STD_LOGIC;
               VV : out STD_LOGIC;
               YV : out STD_LOGIC;
               RV : out STD_LOGIC;
               cpt :  out STD_LOGIC_VECTOR (3 downto 0));
    end feux;
    
    architecture Behavioral of feux is
    type state is (FVH,FYH,FRH,FVV,FYV,FRV);
    signal current_state, next_state : state;
    signal cpt_i : STD_LOGIC_VECTOR (3 downto 0);--compteur 4 bits
    begin
      
      process(h,raz,ReqV,ReqH) 
      begin
      if (raz='1') then   --raz activé alors compteur à 0 et feu rouge vertical
      current_state<=FRV; 
      cpt_i<="0000";
        elsif (ReqV='1' and current_state=FVV) then --pieton alors j'avance le compteur pour passer plus rapidement au rouge
        cpt_i<="1011";
          elsif (ReqH='1' and current_state=FVH) then
          cpt_i<="1011"; 
            elsif rising_edge(h) then 
             case current_state is
               when FVH=> VH<='1'; YH<='0'; RH<='0'; VV<='0'; YV<='0'; RV<='1';               -- feu VERT voie HORIZONTALE-->feu ORANGE voie HORIZONTALE
                if (cpt_i<="1110") then next_state<=FYH;
                end if;
               when FYH=> VH<='0'; YH<='1'; RH<='0'; VV<='0'; YV<='0'; RV<='1';              -- feu ORANGE voie HORIZONTALE-->feu ROUGE voie HORIZONTALE
                if (cpt_i<="0010") then next_state<=FRH;
                end if;
               when FRH=> VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='0'; RV<='1';             -- feu ROUGE voie HORIZONTALE-->feu VERT voie VERTICAL
                if (cpt_i<="0001") then next_state<=FVV;
                end if;
               when FVV=> VH<='0'; YH<='0'; RH<='1'; VV<='1'; YV<='0'; RV<='0';              -- feu VERT voie VERTICAL-->feu ORANGE voie VERTICAL
                if (cpt_i<="1110") then next_state<=FYV;
                end if;
               when FYV=> VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='1'; RV<='0';              -- feu ORANGE voie VERTICALE-->feu ROUGE voie VERTICAL
                if (cpt_i<="0010") then next_state<=FRV;
                end if;
               when FRV=> VH<='0'; YH<='0'; RH<='1'; VV<='0'; YV<='0'; RV<='1';              -- feu ROUGE voie VERTICAL-->feu VERT voie HORIZONTALE
                if (cpt_i<="0001") then next_state<=FVH;
                end if;
               when 
               others => null;
             end case;
            current_state<=next_state; 
              if current_state /= next_state then cpt_i<="0000"; -- l'etat n'est plus le même, initialisation du compteur à 0
                else cpt_i<=cpt_i+1; --sinon le compteur prend +1
                   end if;
                   end if; 
                   end process;
                   cpt<=cpt_i;
                   end behavioral;
    Nom : Capture.jpg
Affichages : 1892
Taille : 76,6 Ko et le test bench du code(juste la manipulation de la clock et du reset)

  5. A voir en vidéo sur Futura
  6. #5
    albanxiii
    Modérateur

    Re : projet feux de carrefour VHDL

    Bonjour,

    Citation Envoyé par jiherve Voir le message
    Code:
    architecture Behavioral of feux is
    type state is (FVH,FYH,FRH,FVV,FYV,FRV);
    variable  next_state : state;
    signal present_state: state;
    signal cpt : STD_LOGIC_VECTOR (3 downto 0);--compteur 4 bits
    begin
    Petite erreur ici.

    Je ne réponds pas à la question car je n'ai pas pu comprendre le fonctionnement attendu à partir du message #1.
    Et d'autre part, dans toutes les autres rubriques on sanctionne les messages qui balancent des solutions toutes faites. Heureusement votre exemple ne compile pas.
    Not only is it not right, it's not even wrong!

  7. #6
    jiherve

    Re : projet feux de carrefour VHDL

    Bonjour,
    en effet il n'y a pas que celle ci car j'ai juste réorganisé le code ainsi : if (cpt_i<="1110")
    est erroné il faudrait if (cpt_i ="1110") pour obtenir ce qui est espéré à ce que j'en comprend, cela vaut pour les autres if.
    Ceci dit il est difficile d'orienter les corrections sans les proposer, je laisse donc la main aux pédagogues.
    JR
    l'électronique c'est pas du vaudou!

  8. #7
    invitef4879e8d

    Re : projet feux de carrefour VHDL

    Bonsoir, merci en effet j'avais pas fait attention à cela. je n'est pas eu utiliser le next_state en variable,il me donne une erreur, je l'es laissé en signal. j'ai modifié certaines choses et réussi à obtenir ce que je voulais, j’ai juste un problème au niveau du compteur qui m’affichera 2 cycle supplémentaire par états..... et encore un peu de mal de voir le tout de manière structurelle ? merci

    Nom : Capture.jpg
Affichages : 1752
Taille : 85,3 Ko

  9. #8
    invitef4879e8d

    Re : projet feux de carrefour VHDL

    Bonsoir, je suis nouveau ici, je tacherais de faire attention à l'avenir, c'est principalement pour avoir des conseils ! merci pour l'erreur j'ai corrigé cela.

Discussions similaires

  1. Modélisation d'un carrefour routier à système de feux tricolore
    Par invitecccd0cae dans le forum Mathématiques du supérieur
    Réponses: 0
    Dernier message: 24/03/2015, 15h00
  2. feux de carrefour sous unitypro
    Par invite1499ca97 dans le forum Électronique
    Réponses: 5
    Dernier message: 02/01/2014, 17h55
  3. projet fin d'étude maquette carrefour de feux lié avec carte fpga
    Par invite66f9fc89 dans le forum Électronique
    Réponses: 2
    Dernier message: 22/03/2010, 09h39
Dans la rubrique Tech de Futura, découvrez nos comparatifs produits sur l'informatique et les technologies : imprimantes laser couleur, casques audio, chaises gamer...