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
@ 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
Rich (BB code):
if spaces= 5 then
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
Rich (BB code):
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity transceiver is -- name should not begin with a number
port(
clk : in std_logic;
reset : in std_logic;
rx : in std_logic;
uart_uit : out std_logic;
alarm_ledje1 : out std_logic;
alarm_ledje2 : out std_logic;
counter : buffer std_logic_vector (7 downto 0)
);
end ENTITY transceiver;
architecture functioneelgedrag of transceiver is
signal new_rx : std_logic;
signal prev_rx : std_logic;
signal niettesnel : std_logic;
signal spaces : unsigned(3 downto 0); --signaal variable (buffer)
signal baudrate : unsigned(7 downto 0);
signal aantal_hoge_bits : unsigned(7 downto 0);
signal klok_teller : unsigned(18 downto 0);
signal baud : unsigned(15 downto 0);
signal klokpulsen : unsigned(18 downto 0);
signal data : std_logic_vector(6 downto 0);
constant FREQUENTIEKRISTAL : natural := 1843200; -- Frequentie van het kristal
begin
-- if reset stays low
--rx is saved in new_rx & prev_rx
--if received bit=1 the counter goes up. the first 5 are of importance
------------------------------------------------------------------------------------------------------------
bitteller: process(clk,reset) --'U' detectie--
begin
if reset = '1' then
new_rx <= '0';
prev_rx <= '0';
elsif clk'event and clk='1' then
if rx='1' then --happens 5 times in a 'U'
--if baudrate = 0 then
uart_uit <='1';
data <= data & '1';
alarm_ledje1 <='1';
--end if; --if baudrate is unknown we detect it
end if;
end if;
end process bitteller;
klokteller: process(clk) -- 'U' lengte teller--
begin
if clk'event and clk='1' then
WHILE prev_rx = '0'and baudrate = 0 LOOP --if 'U' enters
klok_teller <= klok_teller+1; --timer starts if a space is detected
END LOOP; -- a 'U' has 5spaces
end if;
end process klokteller;
bami: process(clk) --convert bittime to baudrate--
begin
if clk'event and clk='1' then
spaces <= unsigned(data);
if spaces= 5 then ----<-- MY PROBLEM!!
alarm_ledje2 <='1';
-- Als de U herkent is de baudrate berekenen!
-- Aantal klokslagen mag een totaal 100 afwijken
--er zijn 5bits gemeten dus het aantal klokslagen is 5*tegroot
klokpulsen <= (others => '0');
if klok_teller > 14 and klok_teller < 18 then -- baudrate 115200
klokpulsen <= klokpulsen + 16;
elsif (klok_teller > 28 and klok_teller < 36) then -- baudrate 57600
klokpulsen <= klokpulsen + 32;
elsif (klok_teller > 42 and klok_teller < 54) then -- baudrate 38400
klokpulsen <= klokpulsen + 48;
elsif (klok_teller > 84 and klok_teller < 108) then -- baudrate 19200
klokpulsen <= klokpulsen + 96;
elsif (klok_teller > 168 and klok_teller < 216) then -- baudrate 9600
klokpulsen <= klokpulsen + 192;
elsif (klok_teller > 336 and klok_teller < 432) then -- baudrate 4800
klokpulsen <= klokpulsen + 384;
elsif (klok_teller > 672 and klok_teller < 864) then -- baudrate 2400
klokpulsen <= klokpulsen + 768;
elsif (klok_teller > 1344 and klok_teller < 1728) then -- baudrate 1200
klokpulsen <= klokpulsen + 1536;
elsif (klok_teller > 5376 and klok_teller < 6912) then -- baudrate 300
klokpulsen <= klokpulsen + 6144;
else klokpulsen <= klokpulsen + 1;
end if;
end if;
end if;
end process bami;
------------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------
end functioneelgedrag;