Fixing VHDL Errors for Traffic Light System

In summary: The entity Traffic does not have any input signals for Sec5, Sec2, Sec1, or globalReset. Additionally, there are missing semicolons in the process for the state machine and some typos such as "nextsate" instead of "nextstate" and "GedRed" instead of "RedGreen". In summary, the code for the Traffic entity is missing input signals and there are some typos in the process for the state machine.
  • #1
JOZ
8
0
Hi I've got a problem with VHDL code its comming up with a lot of errors saing that there's undefined symbols, so I am pretty sure that the error is to do with defining things/instantiation, below is all the code for both the files that are being used
Code:
----------------------------------------------------------------------------------
--  Traffic.vhd
--
-- Traffic light system to control an intersection
--
-- Skeleton - Add your comments here!
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;

entity Traffic is
   Port ( Reset      : in   STD_LOGIC;
          Clock      : in   STD_LOGIC;
          
          -- for debug
          debugLED   : out  std_logic;
          
          -- Car and pedestrian buttons
          CarEW              : in   STD_LOGIC; -- Car on EW road
          CarNS              : in   STD_LOGIC; -- Car on NS road
          PedEW              : in   STD_LOGIC; -- Pedestrian moving EW (crossing NS road)
          PedNS              : in   STD_LOGIC; -- Pedestrian moving NS (crossing EW road)           
          -- Light control
          LightsEW           : out STD_LOGIC_VECTOR (1 downto 0); -- controls EW lights
          LightsNS           : out STD_LOGIC_VECTOR (1 downto 0)  -- controls NS lights
          
          );
end Traffic;

architecture Behavioral of Traffic is

  -- Encoding for lights
  constant RED   : std_logic_vector(1 downto 0) := "00";
  constant AMBER : std_logic_vector(1 downto 0) := "01";
  constant GREEN : std_logic_vector(1 downto 0) := "10";
  constant WALK  : std_logic_vector(1 downto 0) := "11";Component Timer
  Port ( clr : in  STD_LOGIC;
         clock : in  STD_LOGIC;
         globalReset : in  STD_LOGIC;
         load : in  STD_LOGIC;
         Sec5 : out  STD_LOGIC;
         Sec2 : out  STD_LOGIC;
         Sec1 : out  STD_LOGIC);
end Component;

Begin
T1 : Timer PORT MAP (
    clr => clr,
    clock => clock,
    globalReset => globalReset,
    load => load,
    Sec5 => Sec5,
    Sec2 => Sec2,
    Sec1 => sec1,
    );
   type StateType is (GreenRed, AmberRed, RedGreen, RedAmber, WalkRed, RedWalk, RedGed, GedRed);

signal state, nextstate : StateType;
HPedEW            :STD_LOGIC; -- Hold value of PedEW
HPedNS            :STD_LOGIC; -- Hold value of PedNS
  debugLed <= reset; -- Show reset status on FPGA LED

  LightsEW <= RED;
  LightsNS <= GREEN;

   
----process which changes to the next state on the clock edge
ChangeState:
process(globalReset, Clock)
begin
    if (globalReset = '1') then
        state <= GreenRed;
    elsif rising_edge(clock) then   
        if(HPedNS='0') then
            HPedNS<=PedNS;
        end if;
        if(HPedEW='0') then
            HPedEW<=PedEW;
        end if;
        state <= nextstate;
    end if;
end process ChangeState;-----state machine which chooses what the next state will be
StateMachine:
Process(state, CarEW, CarNS, HPedEW, HPedNS, Sec1, Sec2, Sec5)
begin
 -- default state is GreenRed

    case state is
        when GreenRed =>
        LightsNS <= GREEN;
        LightsEW <= RED;
            if ((HPedEW = '1') or (CarEW = '1')) and (Sec5='1')  then
                resetCount;
                nextstate <= AmberRed;
            elsif (HPedNS = '1') and ((Sec2='0') or ((HPedEW = '0') and (CarEW = '0')) then
                loadCount<=’1’;
                nextstate <= WalkRed;
            end if;        when WalkRed =>
        LightsNS <= WALK;
        LightsEW <= RED;

loadCount<=’0’;
            if(Sec5='1') then
                resetCount;
                nextstate <= GreenRed;
                HPedNS<='0';
            end if;        when AmberRed =>
        LightsNS <= AMBER;
        LightsEW <= RED;
            if(Sec1='1') then
                resetCount;
                nextsate<=RedGed
            end if;
       
        when RedGed =>
        LightsNS <= RED;
        LightsEW <= RED;
            if(Sec1='1') then
                resetCount;
                if (HPedEW = '1') then
                    loadCount<=’1’;
                    nextstate <= RedWalk;
                else
                    nextstate <= RedGreen;
                end if;
            end if;
        when RedGreen =>
        LightsNS <= RED;
        LightsEW <= GREEN;
            if ((HPedNS = '1') or (CarNS = '1')) and (Sec5='1')  then
                resetCount;
                nextstate <= RedAmber;
            elsif (HPedEW = '1') and ((Sec2='0') or ((HPedNS = '0') and (CarNS = '0')) then
                loadCount<=’1’;
                nextstate <= RedWalk;
            end if;        when RedWalk =>
        LightsNS <= RED;
        LightsEW <= WALK;
        loadCount<=’0’;
            if (Sec5='1') then
                resetCount;
                nextstate <= RedGreen;
                HPedEW <='0';
            end if;

        when RedAmber =>
        LightsNS <= RED;
        LightsEW <= AMBER;
            if(Sec1='1') then
                resetCount;
                nextstate<=GedRed
            end if;

        when GedRed =>
        LightsNS <= RED;
        LightsEW <= RED;
            if(Sec1='1') then
                resetCount;
                if (HPedNS = '1') then
                    loadCount<=’1’;
                    nextstate <= WalkRed;
                else
                nextstate <= GreenRed;
                end if;
            end if;       end case;
end process StateMachine;end;

The other files is:

Code:
----------------------------------------------------------------------------------
-- timer module
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;entity Timer is
   Port ( clr : in  STD_LOGIC;
          clock : in  STD_LOGIC;
          globalReset : in  STD_LOGIC;
          load : in  STD_LOGIC;
          Sec5 : out  STD_LOGIC;
          Sec2 : out  STD_LOGIC;
          Sec1 : out  STD_LOGIC);
end Timer;

architecture Behavioral of Timer is

signal count : natural range 0 to 501;

beginprocess(globalReset, clock) is
begin
   if globalReset = '1' then
     count <= 0;

   elsif (count <= 500)  and (rising_edge(clock)) then
     if clr = '1' then
    count <= 0;
     elsif load = '1' then
       count <= 200;
    load <= '0';
     else
       count <= count + 1;
     end if;
   end if;    if count >= 100 then Sec1 <= '1';
        else Sec1 <= '0';
    end if;
    if count >= 500 then Sec5 <= '1';
        else Sec5 <= '0';
    end if;
    if count >= 200 then Sec2 <= '1';
        else Sec2 <= '0';
    end if;
end process;

end Behavioral;
 
Physics news on Phys.org
  • #2
There seems to be missing signals in the top unit which connects to the signals from the component Timer
 

1. What are the common VHDL errors encountered when creating a traffic light system?

Some of the most common VHDL errors when creating a traffic light system include syntax errors, type mismatches, and missing semicolons. These errors can often be identified by the VHDL compiler and can be fixed by carefully checking the code for any typos or missing syntax elements.

2. How can I troubleshoot VHDL errors for a traffic light system?

The first step in troubleshooting VHDL errors for a traffic light system is to carefully review the error messages provided by the VHDL compiler. These messages often indicate the line number and type of error, which can help narrow down the issue. Additionally, it is helpful to double check the syntax and logic of the code to ensure it is correct.

3. Why is it important to fix VHDL errors for a traffic light system?

VHDL errors must be fixed for a traffic light system because they can prevent the code from being successfully compiled and synthesized. This ultimately leads to a malfunctioning traffic light system and can cause potential safety hazards if used in a real-world scenario.

4. Can I use any programming language to create a traffic light system?

While there are many programming languages that can be used to create a traffic light system, VHDL is often the preferred language for hardware design. VHDL is specifically designed for describing hardware systems and allows for precise control over timing and logic, making it well-suited for creating a traffic light system.

5. Are there any tools or resources available to help with fixing VHDL errors for a traffic light system?

Yes, there are various tools and resources available to help with fixing VHDL errors for a traffic light system. These include VHDL simulators and debuggers, as well as online forums and communities where experienced designers can offer advice and assistance. Additionally, many textbooks and online tutorials provide guidance on troubleshooting VHDL errors for different applications.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
5K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
11K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
6K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Electrical Engineering
Replies
6
Views
2K
  • Electrical Engineering
Replies
5
Views
4K
Replies
7
Views
13K
Back
Top