1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
| 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;
La DEUXIEME :
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;
Q : 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=> -- feu VERT voie HORIZONTALE-->feu ORANGE voie HORIZONTALE
if cpt<="1110" then next_state<=FYH;
cpt<="0000";
end if;
when FYH=> -- feu ORANGE voie HORIZONTALE-->feu ROUGE voie HORIZONTALE
if cpt<="0010" then next_state<=FRH;
cpt<="0000";
end if;
when FRH=> -- feu ROUGE voie HORIZONTALE-->feu VERT voie VERTICAL
if cpt<="0001" then next_state<=FVV;
cpt<="0000";
end if;
when FVV=> -- feu VERT voie VERTICAL-->feu ORANGE voie VERTICAL
if cpt<="1110" then next_state<=FYV;
cpt<="0000";
end if;
when FYV=> -- feu ORANGE voie VERTICALE-->feu ROUGE voie VERTICAL
if cpt<="0010" then next_state<=FRV;
cpt<="0000";
end if;
when FRV=> -- feu ROUGE voie VERTICAL-->feu VERT voie HORIZONTALE
if cpt<="0001" then next_state<=FVH;
cpt<="0000";
end if;
end case;
end process;
process(H,raz)
begin
if raz ='1' then present_state<=FVH;
elsif (H'event and H = '1') then present_state<=next_state;
-- reset du compteur si changement d'état
else cpt<=cpt+1;
end if;
end process;
Q<=cpt;
VH<='1' when (present_state=FVH) else '0'; --valeurs de sortie selon les différents états
YH<='1' when (present_state=FYH) else '0';
RH<='1' when (present_state=FRH or present_state=FVV or present_state=FYV) else '0';
VV<='1' when (present_state=FVV) else '0';
YV<='1' when (present_state=FYV) else '0';
RV<='1' when (present_state=FRV or present_state=FVH or present_state=FYH) else '0';
end Behavioral; |
Partager