alikaradag
Newbie level 6
- Joined
- Nov 9, 2014
- Messages
- 11
- Helped
- 1
- Reputation
- 2
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 122
Hi all ,
Pleas, I need help with my code. I need to generate 25 seconds (green red signal ) and 4 seconds (yellow signal ). There should be a car sensor too. The code should be based on 24 MHz frequency.
Am not good about vhdl, BUT I really really did my best to write the code bellow. The problem is I couldn't get the four states outputs. I only get the first Green Red state while the other three states are not there!!
Please, any advice or assistance.
code is :
Pleas, I need help with my code. I need to generate 25 seconds (green red signal ) and 4 seconds (yellow signal ). There should be a car sensor too. The code should be based on 24 MHz frequency.
Am not good about vhdl, BUT I really really did my best to write the code bellow. The problem is I couldn't get the four states outputs. I only get the first Green Red state while the other three states are not there!!
Please, any advice or assistance.
code is :
Code VHDL - [expand] 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 library ieee; use ieee.std_logic_1164.all; ENTITY traffic_traffic IS PORT( CLK: in std_logic; LIGHTS: buffer std_LOGIC_VECTOR(5 downto 0)); END traffic_traffic; ARCHITECTURE circuit OF traffic_traffic IS TYPE STATE_TYPE IS (S0, S1, S2, S3); SIGNAL state: STATE_TYPE := s0; signal GrayCode : std_LOGIC_VECTOR (1 downto 0); SIGNAL state_outputs : std_LOGIC_VECTOR (3 downto 0); SIGNAL trigger_long : std_LOGIC_VECTOR (1 downto 0); SIGNAL trigger_short : std_LOGIC_VECTOR (1 downto 0); BEGIN PROCESS (GrayCode) BEGIN CASE GrayCode IS WHEN "00" => state <= s0; WHEN "01" => state <= s1; WHEN "11" => state <= s2; WHEN "10" => state <= s3; WHEN others => state <= s0; END CASE; end process; process (state) begin CASE state IS WHEN s0 => state_outputs <= "0001"; WHEN s1 => state_outputs <= "0010"; WHEN s2 => state_outputs <= "1000"; WHEN s3 => state_outputs <= "0100"; WHEN others => state_outputs <= "0001"; END CASE; END PROCESS; process (state_outputs) begin CASE state_outputs IS WHEN "0001" => lights <= "100001"; WHEN "0010" => lights <= "010001"; WHEN "1000" => lights <= "001100"; WHEN "0100" => lights <= "001010"; WHEN others => lights <= "100001"; END CASE; END PROCESS; process (lights) begin CASE lights IS WHEN "100001" => trigger_long <= "10"; WHEN "010001" => trigger_short <= "01"; WHEN "001100" => trigger_long <= "10"; WHEN "001010" => trigger_short <= "01"; WHEN others => trigger_long <= "10"; END CASE; END PROCESS; END ; library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; -- the Timer for the traffic light controller. entity timer is PORT(clk: in std_logic; reset: in bit; LIGHTS: out std_LOGIC_VECTOR(5 downto 0)); END timer; architecture arc of timer is TYPE STATE_TYPE IS (S0, S1, S2, S3); SIGNAL state: STATE_TYPE := s0; signal count: integer := 24000000; signal trigger_long: integer := 600000; signal trigger_short: integer := 96000; signal car_detec: integer range 0 to 1; BEGIN PROCESS (CLK,reset, state, trigger_short, trigger_long, car_detec) BEGIN IF (reset = '0') THEN IF(CLK'EVENT AND CLK = '1') and car_detec = 1 THEN CASE state IS WHEN s0 => IF count < 24000000 / 40 THEN state <= s0; count <= count + 1; ELSE state <= s1; count <= 0; END IF; WHEN s1 => IF count < 24000000 / 250 THEN state <= s1; count <= count +1; ELSE state <= s2; count <= 0; END IF; WHEN s2 => IF count < 24000000 / 40 THEN state <= s2; count <= count + 1; ELSE state <= s3; count <= 0; END IF; WHEN s3 => IF count < 24000000 / 250 THEN state <= s3; count <= count + 1; ELSE state <= s3; count <= 0; END IF; WHEN others => state <= s0; END CASE; END IF; END IF; END PROCESS; end arc;
Last edited by a moderator: