Saturday, 27 July 2013

Sensor Based Traffic Light Controller using FSM Technique (VHDL Code).






Sensor Based Traffic Light Controller using FSM Technique -


Output Waveform :   Sensor Based Single Way Traffic Light Controller.



VHDL Code-



-------------------------------------------------------------------------------
--
-- Title       : TLC_sensor
-- Design      : vhdl_upload2
-- Author      : Naresh Singh Dobal
-- Company     : nsdobal@gmail.com
-- VHDL Programs &  Exercise with Naresh Singh Dobal.
--
--
-------------------------------------------------------------------------------
--
-- File        : Sensor based single way traffic light controller.vhd



library IEEE;
use IEEE.STD_LOGIC_1164.all;

entity TLC_sensor is
     port(
         clk : in STD_LOGIC;
         sensor : in STD_LOGIC;
         r : out STD_LOGIC;
         y : out STD_LOGIC;
         g : out STD_LOGIC
         );
end TLC_sensor;

architecture TLC_sensor_arc of TLC_sensor is 

type color is (red,yellow,green);

signal p_state : color;
signal n_state : color;

begin

    present_state : process (clk) is
    begin
        if (rising_edge (clk)) then
            p_state <= n_state;
        end if;
    end process present_state ;
   
    next_state : process (p_state, sensor ) is
    begin
        case (p_state) is
            when red =>
            n_state <= green;
            r <= '1';
            y <= '0';
            g <= '0';
       
            when green =>
            if (sensor='1') then
                n_state <= green;
            else
                n_state <= yellow;
            end if;
            r <= '0';
            y <= '0';
            g <= '1';
           
            when yellow =>
            n_state <= red ;
            r <= '0';
            y <= '1';
            g <= '0';
   
        end case;
    end process next_state;

end TLC_sensor_arc;

0 comments :

Post a Comment

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes