@vareshkaa

Как реализовать светофор на vhdl?

Здравствуйте. Задание реализовать светофор. 10 секунд горит один светодиод("красный"), затем на 3 секунды загорается еще один светодиод(красный+желтый), затем зеленый на 5 секунд, потом 3 секунды мигает со скважностью 2 и переключается на красный.
Получился такой код(без мигания пока что), но проект не собирается. Никак не могу понять свою ошибку. Надеюсь на вашу помощь. Спасибо
вот код:
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
use ieee. std_logic_arith.all;

entity kurs is 
port
    (
        srst    : in std_logic;
        clk     : in  std_logic;                        --СИНХРА
        dout    : out std_logic_vector (2 downto 0)    --ВЫХОД СОСТОЯНИЯ СФЕТОФОРА
    );
end entity;

architecture Behavioral of kurs is
TYPE state_type IS (RED,YELLOW,GREEN,GREEN_M);
signal next_state, state : state_type; --СИГНАЛЫ ГДЕ ХРАНЯТСЯ ДАННЫЕ О СОСТОЯНИИ СВЕТОФОРА
signal enR,enG,enGM,enY, enCR, enCG, enCY, enCGM, led : std_logic;
signal counterR,counterY,counterG, counterGM : std_logic_vector (29 downto 0):= (others => '0');
signal tempout : std_logic_vector (2 downto 0);

component lab72 is
Port ( clk : in STD_LOGIC;
dout : out STD_LOGIC);
end component lab72;

begin

process (state, enR, enY, enG, enGM) begin
next_state<=RED;
case state is
    when RED =>
    enCR <= '1';
    if(enR='1') then 
    next_state <= YELLOW;    
    else 
    next_state <= RED;
    end if;
    
    when YELLOW => 
    enCY <= '1';                                       -- ПЕРЕКЛЮЧАЕМ С ЗЕЛЕНОГО 
    if(enY='1') then
    next_state <= GREEN;  
    else
    next_state <= YELLOW;
    end if;  
                  
    when GREEN =>
    enCG <= '1';
    if(enG='1') then
    next_state<=GREEN_M;
    else
    next_state <= GREEN;
    end if;
    
    when GREEN_M=>
    enCGM <= '1';
    if (enGM='1') then
    next_state<=RED;
    else
    next_state <= GREEN_M;
    end if;
    
    when others =>
    next_state <= RED;
end case;              
end process;

process(clk) begin
if rising_edge(clk) then
state<=next_state;
end if;
end process;

process (clk) begin
 if rising_edge(clk) then
   if unsigned(counterR)=1000000000 then
   counterR <= (others => '0');
   enR<='1';
   elsif   (enCR ='1') then
   counterR <= unsigned(counterR)+1; 
   enR<='0';
 end if; 
 end if;
end process;

process (clk) begin
 if rising_edge(clk) then
   if unsigned(counterY)=300000000 then
   counterY <= (others => '0');
   enY<='1';
   elsif (enCY ='1') then
   counterY <= unsigned(counterY)+1; 
   enY<='0';
 end if; 
 end if;
end process;

process (clk) begin
 if rising_edge(clk) then
   if unsigned(counterG)=500000000 then
   counterG <= (others => '0');
   enG<='1';
   elsif (enCG='1') then
   counterG <= unsigned(counterG)+1; 
   enG<='0';
 end if; 
 end if;
end process;

process (clk) begin
 if rising_edge(clk) then
   if unsigned(counterGM)=300000000 then
   counterGM <= (others => '0');
   enGM<='1';
   elsif (enCGM='1') then
   counterGM <= unsigned(counterGM)+1; 
   enGM<='0';
 end if; 
 end if;
end process;

out_proc : process (state) begin --определение, что выводить

tempout (2 downto 0) <= (others =>'0');

    if (state) = RED then
    tempout(2 downto 0) <= "001";
    elsif (state) = YELLOW then
    tempout(2 downto 0) <= "011";
    elsif (state) = GREEN then
    tempout(2 downto 0) <= "100";
    elsif (state) = GREEN_M then
    tempout(2 downto 0) <= led & "00";
    end if;
end process;

process (clk) begin --сброс
  if rising_edge(clk) then
    if srst = '1' then
      state   <= RED;
      enCR    <= '1';
      dout(0) <= '1' ;
     else
      state <= next_state;
      dout <= tempout;  
    end if;
  end if;
end process;

end Behavioral;
  • Вопрос задан
  • 509 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы