EmbDev.net

Forum: FPGA, VHDL & Verilog Help with VHDL


von Jaden (Guest)


Rate this post
useful
not useful
Hello,

I'm quite new to VHDL and trying to create a simple UART transmission in 
VHDL code.

This is my code:
1
entity UART is 
2
  port ( din  : in bit_vector( 7 downto 0) ;
3
       send : in std_logic ;
4
       tx  : out bit ) ;
5
end UART;
6
7
architecture arc_UART of UART is
8
begin
9
  process
10
    constant bit_time : time := 8680 ns ;  -- 1/115200 [baud]
11
  begin
12
    tx <= '1' ;                -- idle state  
13
    wait until falling_edge(send) ;       -- wait until send
14
    tx <= '0' ; wait for bit_time ;       -- start bit
15
    for i in 0 to 7 loop
16
      tx <= din(i) ; wait for bit_time ; -- send 8 data bits
17
    end loop ;
18
    tx <= '1' ; wait for bit_time ;       -- stop bit
19
  end process;
20
end arc_UART;

But the problem is that when I run a Model-sim simulation, it doesn't 
work as expected.


What could be the problem here?

Thank you

von Lothar M. (Company: Titel) (lkmiller) (Moderator)


Rate this post
useful
not useful
Jaden wrote:
> it doesn't work as expected.
What do you expect and what happens instead?

> What could be the problem here?
You know that "wait for" is not synthesizable on real hardware like a 
FPGA?

von U.G. L. (dlchnr)


Rate this post
useful
not useful
I suppose you need something like a loadable shift register plus a 
baudrate generator (clock divider),
which generates the shift clock (sclk) from your system clock.
1
ShiftRegister : process                                                                         
2
begin                                                                                        
3
  wait until rising_edge(sclk);                                                          
4
  if (load = '1') then
5
    sr(7 downto 0) <= din(7 downto 0);
6
    tx <= '0';
7
  else                                                                 
8
    sr(6 downto 0) <= sr(7 downto 1);
9
    sr(7) <= '1';                                                  
10
    tx <= sr(0);                                                                          
11
  end if;                                                                                    
12
end process;

Please log in before posting. Registration is free and takes only a minute.
Existing account
Do you have a Google/GoogleMail account? No registration required!
Log in with Google account
No account? Register here.