Advertisement
some_kid

Stop light

Feb 9th, 2012
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.75 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- Entity: stopLightLogic
  3. -- Date: Jan 26, 2012
  4. -- Author:    
  5. --
  6. -- Description
  7. --------------------------------------------------------------------------------
  8. library ieee;
  9. use ieee.std_logic_1164.all;
  10.  
  11. entity stopLightLogic is
  12.     port(
  13.         clock   : in  std_logic;
  14.         reset   : in  std_logic;
  15.         lights1 : out std_logic_vector(2 downto 0); -- red yellow green
  16.         lights2 : out std_logic_vector(2 downto 0); -- red yellow grean
  17.         walk1   : out std_logic;        -- walk symbol
  18.         walk2   : out std_logic;        -- walk symbol
  19.         hand1   : out std_logic;        -- flashing stop hand
  20.         hand2   : out std_logic;        -- flashing stop hand
  21.         segs1   : out std_logic_vector(15 downto 0); -- walk countdown
  22.         segs2   : out std_logic_vector(15 downto 0) -- walk countdown
  23.     );
  24. end entity stopLightLogic;
  25.  
  26. architecture arch of stopLightLogic is
  27.     signal count : integer range 0 to 92;
  28. begin
  29.     counter : process(clock, reset)
  30.     begin
  31.         if reset = '0' or count = 92 then
  32.             count <= 0;
  33.         elsif rising_edge(clock) then
  34.             count <= count + 1;
  35.         end if;
  36.     end process;
  37.  
  38.     -- anything that runs when count changes
  39.     process(count)
  40.     begin
  41.         -- handle the lights for direction 1
  42.         if count = 0 then
  43.             lights1 <= "011";           -- red (reset)
  44.         elsif count < 30 then
  45.             lights1 <= "110";           -- green
  46.         elsif count < 45 then
  47.             lights1 <= "101";           -- yellow
  48.         else
  49.             lights1 <= "011";           -- red
  50.         end if;
  51.  
  52.         -- handle the lights for cross direction
  53.         if count < 46 or count = 91 then
  54.             lights2 <= "011";           -- red
  55.         elsif count < 76 then
  56.             lights2 <= "110";           -- green
  57.         else
  58.             lights2 <= "101";           -- yellow
  59.         end if;
  60.  
  61.         -- pedestrian signals
  62.         if count = 19 then
  63.             segs1 <= "1001111110011111"; -- 11
  64.         elsif count = 20 then
  65.             segs1 <= "1001111100000011"; -- 10
  66.         elsif count = 21 then
  67.             segs1 <= "1111111100001001"; -- 9
  68.         elsif count = 22 then
  69.             segs1 <= "1111111100000001"; -- 8
  70.         elsif count = 23 then
  71.             segs1 <= "1111111100011111"; -- 7
  72.         elsif count = 24 then
  73.             segs1 <= "1111111111000001"; -- 6
  74.         elsif count = 25 then
  75.             segs1 <= "1111111101001001"; -- 5
  76.         elsif count = 26 then
  77.             segs1 <= "1111111110011001"; -- 4
  78.         elsif count = 27 then
  79.             segs1 <= "1111111100001101"; -- 3
  80.         elsif count = 28 then
  81.             segs1 <= "1111111100100101"; -- 2
  82.         elsif count = 29 then
  83.             segs1 <= "1111111110011111"; -- 1
  84.         else
  85.             segs1 <= "1111111111111111"; -- off
  86.         end if;
  87.  
  88.         if count < 19 then
  89.             hand1 <= '1';
  90.         elsif count = 19 then
  91.             hand1 <= '0';
  92.         elsif count = 20 then
  93.             hand1 <= '1';
  94.         elsif count = 21 then
  95.             hand1 <= '0';
  96.         elsif count = 22 then
  97.             hand1 <= '1';
  98.         elsif count = 23 then
  99.             hand1 <= '0';
  100.         elsif count = 24 then
  101.             hand1 <= '1';
  102.         elsif count = 25 then
  103.             hand1 <= '0';
  104.         elsif count = 26 then
  105.             hand1 <= '1';
  106.         elsif count = 27 then
  107.             hand1 <= '0';
  108.         elsif count = 28 then
  109.             hand1 <= '1';
  110.         else
  111.             hand1 <= '0';
  112.         end if;
  113.  
  114.         -- pedestrian signals 2
  115.         if count = 65 then
  116.             segs2 <= "1001111110011111"; -- 11
  117.         elsif count = 66 then
  118.             segs2 <= "1001111100000011"; -- 10
  119.         elsif count = 67 then
  120.             segs2 <= "1111111100001001"; -- 9
  121.         elsif count = 68 then
  122.             segs2 <= "1111111100000001"; -- 8
  123.         elsif count = 69 then
  124.             segs2 <= "1111111100011111"; -- 7
  125.         elsif count = 70 then
  126.             segs2 <= "1111111111000001"; -- 6
  127.         elsif count = 71 then
  128.             segs2 <= "1111111101001001"; -- 5
  129.         elsif count = 72 then
  130.             segs2 <= "1111111110011001"; -- 4
  131.         elsif count = 73 then
  132.             segs2 <= "1111111100001101"; -- 3
  133.         elsif count = 74 then
  134.             segs2 <= "1111111100100101"; -- 2
  135.         elsif count = 75 then
  136.             segs2 <= "1111111110011111"; -- 1
  137.         else
  138.             segs2 <= "1111111111111111"; -- off
  139.         end if;
  140.  
  141.         if count < 65 then
  142.             hand2 <= '1';
  143.         elsif count = 65 then
  144.             hand2 <= '0';
  145.         elsif count = 66 then
  146.             hand2 <= '1';
  147.         elsif count = 67 then
  148.             hand2 <= '0';
  149.         elsif count = 68 then
  150.             hand2 <= '1';
  151.         elsif count = 69 then
  152.             hand2 <= '0';
  153.         elsif count = 70 then
  154.             hand2 <= '1';
  155.         elsif count = 71 then
  156.             hand2 <= '0';
  157.         elsif count = 72 then
  158.             hand2 <= '1';
  159.         elsif count = 73 then
  160.             hand2 <= '0';
  161.         elsif count = 74 then
  162.             hand2 <= '1';
  163.         else
  164.             hand1 <= '0';
  165.         end if;
  166.     end process;
  167.  
  168. end architecture arch;
  169.  
  170. -------------------------------------------------- timeline ------------------------------------------------------
  171. --              0sec    ->    30sec    ->    45sec    ->  46sec    ->    76sec    ->    91sec    ->    92sec
  172. --  lights1     green         yellow         red          red            red            red            reset timer
  173. --  lights2     red           red            red          green          yellow         red            reset timer
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement