my first VHDL program

Discussion in 'Embedded Systems and Microcontrollers' started by gohan127, Mar 17, 2008.

  1. gohan127

    Thread Starter New Member

    Feb 12, 2008
    2
    0
    i'm making this VHDL design for a system that detects a serial 'U' coming in at pin 'rx' (binair you get 5x '10' after each other). after those 5 have passed he tells the average time it took for 1bit. my problem is that it doesn't work yet x D, no, seriously i can't get
    Code ( (Unknown Language)):
    1. if spaces= 5 then
    @ line 68
    to work i tried various ways to count to 5 and get it detected at the '5' mark. ..
    please have a look and help me correct my wrongs
    Code ( (Unknown Language)):
    1. library ieee;
    2. use ieee.std_logic_1164.all;
    3. use ieee.numeric_std.all;
    4.  
    5. entity transceiver is       -- name should not begin with a number
    6.   port(
    7.         clk   : in  std_logic;
    8.        reset : in  std_logic;
    9.        rx    : in  std_logic;
    10.        uart_uit : out std_logic;
    11.        alarm_ledje1 : out std_logic;
    12.        alarm_ledje2 : out std_logic;
    13.        counter : buffer std_logic_vector (7 downto 0)
    14.   );
    15. end ENTITY transceiver;
    16.  
    17. architecture functioneelgedrag of transceiver is
    18. signal new_rx           : std_logic;
    19. signal prev_rx          : std_logic;
    20. signal niettesnel           : std_logic;
    21. signal spaces           : unsigned(3 downto 0);             --signaal variable (buffer)
    22. signal baudrate             : unsigned(7 downto 0);
    23. signal aantal_hoge_bits : unsigned(7 downto 0);
    24. signal klok_teller          : unsigned(18 downto 0);
    25. signal baud             : unsigned(15 downto 0);
    26. signal klokpulsen           : unsigned(18 downto 0);
    27. signal data             : std_logic_vector(6 downto 0);
    28.  
    29. constant FREQUENTIEKRISTAL : natural := 1843200;  -- Frequentie van het kristal
    30. begin
    31.  
    32.         -- if reset stays low
    33.         --rx is saved  in new_rx & prev_rx
    34.         --if received bit=1 the counter goes up. the first 5 are of importance
    35. ------------------------------------------------------------------------------------------------------------
    36.         bitteller: process(clk,reset)                           --'U' detectie--
    37.         begin
    38.             if reset = '1' then
    39.             new_rx  <= '0';
    40.             prev_rx <= '0';
    41.             elsif clk'event and clk='1' then
    42.            
    43.             if rx='1' then                          --happens 5 times in a 'U'
    44.        
    45.         --if baudrate = 0 then
    46.        
    47.         uart_uit <='1';
    48.             data <= data & '1';
    49.             alarm_ledje1 <='1';
    50.             --end if;                           --if baudrate is unknown we detect it
    51.             end if;
    52.             end if;
    53.             end process bitteller;
    54.  
    55.         klokteller: process(clk)                            -- 'U' lengte teller--
    56.         begin
    57.         if clk'event and clk='1' then
    58.         WHILE prev_rx = '0'and baudrate = 0 LOOP                            --if 'U' enters
    59.         klok_teller <= klok_teller+1;                           --timer starts if a space is detected
    60.         END LOOP;                           -- a 'U' has 5spaces
    61.         end if;
    62.         end process klokteller;
    63.        
    64.        
    65.        
    66.         bami: process(clk)                          --convert bittime to baudrate--
    67.         begin
    68.         if clk'event and clk='1' then
    69.         spaces <= unsigned(data);
    70.         if spaces= 5 then                  ----<-- MY PROBLEM!!
    71.         alarm_ledje2 <='1';
    72.         -- Als de U herkent is de baudrate berekenen!
    73.         -- Aantal klokslagen mag een totaal 100 afwijken
    74.         --er zijn 5bits gemeten dus het aantal klokslagen is 5*tegroot
    75.         klokpulsen <= (others => '0');
    76.         if klok_teller > 14  and klok_teller <  18  then -- baudrate 115200
    77.         klokpulsen <= klokpulsen +      16;
    78.         elsif (klok_teller > 28  and klok_teller <  36)     then -- baudrate 57600
    79.         klokpulsen <= klokpulsen +      32;
    80.         elsif (klok_teller > 42  and klok_teller <  54)     then -- baudrate 38400
    81.         klokpulsen <= klokpulsen +      48;
    82.         elsif (klok_teller > 84  and klok_teller <  108)    then -- baudrate 19200
    83.         klokpulsen <= klokpulsen +      96;
    84.         elsif (klok_teller > 168     and klok_teller <  216)    then -- baudrate 9600
    85.         klokpulsen <= klokpulsen +      192;
    86.         elsif (klok_teller > 336  and klok_teller <     432)    then -- baudrate 4800
    87.         klokpulsen <= klokpulsen +      384;
    88.         elsif (klok_teller > 672  and klok_teller <     864)    then -- baudrate 2400
    89.         klokpulsen <= klokpulsen +      768;
    90.         elsif (klok_teller > 1344 and klok_teller <     1728)   then -- baudrate 1200
    91.         klokpulsen <= klokpulsen +      1536;
    92.         elsif (klok_teller > 5376 and klok_teller <     6912)   then -- baudrate 300
    93.         klokpulsen <= klokpulsen +      6144;
    94.         else klokpulsen <= klokpulsen +     1;
    95.         end if;
    96.         end if;
    97.         end if;
    98.         end process bami;
    99.        
    100. ------------------------------------------------------------------------------------------------------------       
    101.            
    102. ------------------------------------------------------------------------------------------------------------       
    103.  
    104.        
    105.  
    106.        
    107.  
    108.  
    109. end functioneelgedrag;
    110.  
    111.  
     
Loading...