EmbDev.net

Forum: FPGA, VHDL & Verilog car taillights


Author: Dfd D. (dfd_d)
Posted on:

Rate this post
0 useful
not useful
I am trying to do a T-Bird tail light function using VHDL. I have been 
able to get the emergency (Hazard) and Left and right turn to work  and 
brake but can not get the when brake light and the lights in the 
direction of the turn function as before, the lights opposite the tail 
lights are all on

below is my code

so what i want to do is "When the brakes are on, and

when the hazard is on, it takes precedence and the tail lights all blink 
as before got this to work.
when the left or right turn signal is on, the lights in the direction of 
the turn function as before, the lights opposite the tail lights are all 
on. can't get this to work

 when the brakes are on and the hazard and left or right are not, the 
tail lights are all on. got this to work.
library IEEE;
use IEEE.std_logic_1164.all;

ENTITY tbird_lc is
  GENERIC(DIVISOR : positive := 10000000);
  PORT(clk           : IN  std_logic;
       rst           : IN  std_logic;
       left          : IN std_logic;
       right         : IN std_logic;
       haz           : in std_logic;
     brake         : IN std_logic; 
       left_tail_lt  : OUT std_logic_vector(3 downto 1);
       right_tail_lt : OUT std_logic_vector(1 to 3));
END tbird_lc;

ARCHITECTURE behavior OF tbird_lc IS

  TYPE state_type IS (IDLE, LR3, L1, L2, L3, R1, R2, R3,LB,LB1,LB2,LB3);
  SIGNAL present_state, next_state : state_type;
  CONSTANT leftoff : std_logic_vector(3 downto 1) := "000";
  CONSTANT left1on : std_logic_vector(3 downto 1) := "001";
  CONSTANT left2on : std_logic_vector(3 downto 1) := "011"; 
  CONSTANT left3on : std_logic_vector(3 downto 1) := "111";
  CONSTANT rightoff : std_logic_vector(3 downto 1) := "000";
  CONSTANT right1on : std_logic_vector(3 downto 1) := "100";
  CONSTANT right2on : std_logic_vector(3 downto 1) := "110";
  CONSTANT right3on : std_logic_vector(3 downto 1) := "111";
  
  signal sclk: std_logic;

BEGIN
 DIVIDER : entity work.clock_divider(behavior)
generic map (DIVISOR => DIVISOR)
port map (clk => clk, rst => rst, q => sclk);
 clocked : PROCESS(sclk,rst)
   BEGIN
     IF(rst='1') THEN 
       present_state <= idle;
    ELSIF(rising_edge(sclk)) THEN
      present_state <= next_state;
    END IF;  
 END PROCESS clocked;
 
 nextstate : PROCESS(present_state,left,right,haz, brake)
  BEGIN
     CASE present_state IS
       WHEN idle =>
         IF(haz = '1' OR(brake='1' and haz='1')OR (left = '1' AND right = '1')) THEN
           next_state <= LR3;
         ELSIF(left = '1') THEN
           next_state <= L1;
      ELSIF (left='1' and brake='1') THEN  --trying to make another state for left and brake
        next_state<=LB1;          
         ELSIF(right = '1') THEN
           next_state <= R1;
      ELSIF(brake='1' and haz='0' and left='0' and right='0')THEN
         next_state<=LR3;  
         ELSE
           next_state <= idle;
         END IF;
       WHEN LR3 =>
       IF(brake='1' and haz='0' and left='0' and right='0') THEN
        next_state<=LR3; 
      else
         next_state <= idle;
       END IF; 
       WHEN L1 =>
         IF(haz = '1' or (brake='1' and haz='1') ) THEN
           next_state <= LR3;
         ELSE
           next_state <= L2;
         END IF;
       WHEN L2 =>
         IF(haz = '1' or (brake='1' and haz='1') ) THEN
           next_state <= LR3;
         ELSE
           next_state <= L3;
         END IF;
       WHEN L3 =>
         next_state <= idle;
       WHEN R1 =>
         IF(haz = '1' or (brake='1' and haz='1')) THEN
           next_state <= LR3;
         ELSE
           next_state <= R2;
         END IF;
       WHEN R2 =>
         IF(haz = '1' or (brake='1' and haz='1')) THEN
           next_state <= LR3;
         ELSE
           next_state <= LB;
         END IF;
       WHEN R3 =>
         next_state <= idle;
     WHEN LB1 =>        --next state for left and brake 
       IF (left='1' and brake='1') THEN 
        next_state<=LB2; 
         else 
           next_state<=LB;     
      END IF; 
     WHEN LB2=>
       IF (left='1' and brake='1') THEN 
        next_state<=LB3; 
      ELSE
        next_state<=LB; 
      END IF; 
     WHEN LB3 =>
       next_state<= idle; 
       WHEN LB => 
           next_state<=LB;      
    END CASE;
  END PROCESS nextstate;

  output : PROCESS(present_state)
   BEGIN
     CASE present_state IS
       WHEN idle =>
         left_tail_lt <= leftoff;
         right_tail_lt <= rightoff;
       WHEN LR3 =>
         left_tail_lt <= left3on;
         right_tail_lt <= right3on;
       WHEN L1 =>
         left_tail_lt <= left1on;
         right_tail_lt <= rightoff;
       WHEN L2 =>
         left_tail_lt <= left2on;
         right_tail_lt <= rightoff;
       WHEN L3 =>
         left_tail_lt <= left3on;
         right_tail_lt <= rightoff;
       WHEN R1 =>
         left_tail_lt <= leftoff;
         right_tail_lt <= right1on;
       WHEN R2 =>
         left_tail_lt <= leftoff;
         right_tail_lt <= right2on;
       WHEN R3 =>
         left_tail_lt <= leftoff;
         right_tail_lt <= right3on;
      WHEN LB1 =>         --trying to do left and brake but working
         left_tail_lt <= left1on;
         right_tail_lt <= right3on;
       WHEN LB2 =>
         left_tail_lt <= left2on;
         right_tail_lt <= right3on;
       WHEN LB3 =>
         left_tail_lt <= left3on;
         right_tail_lt <= right3on;
    WHEN LB => 
      right_tail_lt <=right3on; 
      left_tail_lt<=leftoff; 
     END CASE;
 END PROCESS output;
 
END ARCHITECTURE behavior;

Author: P. K. (pek)
Posted on:

Rate this post
0 useful
not useful
Why do you one signle state machine, that codes everything?

You have a number of lights that are independant, so you shouldn't code 
them into one big state machine, creating dependancies where they don't 
really exist.

I doubt whether you even need a state machine. Maybe it is just enough 
to register the inputs for synchronisation and if required debounce them 
and afterwards do a pure combinational assignment. e.g:
brake_left <= '1'   when brake_registered_debounced = '1' else
              '0';
dir_left   <= blink when left_registered_debounced = '1' or
                         haz_registered_debounced = '1' else
              '0';
...

"blink" is an independantly generated (ever running) blinking signal 
running at your desired speed.

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [vhdl]VHDL code[/vhdl]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.