Skip to content
The Chat Archive
claude-2.0· Anthropic Arena Human Preference 55K

write VHDL UART transmitter. It should take 8-bit word as input, output clock is divided…

  1. User

    write VHDL UART transmitter. It should take 8-bit word as input, output clock is divided by configurable amount from the input clock. Transmit is started by writing one cycle high pulse to W std_logic input.

  2. Assistant

    Here is an example VHDL code for a simple UART transmitter:

    library ieee;
    use ieee.std_logic_1164.all;
    
    entity uart_tx is
      generic (
        CLK_FREQ : integer := 50_000_000; -- System clock frequency in Hz
        BAUD_RATE : integer := 115200);    -- Baud rate
      port (
        clk   : in std_logic;
        tx_en : in std_logic; -- Transmit enable (one clock pulse)
        din   : in std_logic_vector(7 downto 0); -- Input data
        tx    : out std_logic); -- UART output
    end uart_tx;
    
    architecture behavior of uart_tx is
    
      constant CLK_DIV : integer := CLK_FREQ / BAUD_RATE;
      
      signal tx_reg : std_logic;
      signal tx_cnt : integer range 0 to CLK_DIV-1 := 0;
      signal tx_bit : integer range 0 to 7 := 0; 
      
    begin
    
      tx_proc: process(clk)
      begin
        if rising_edge(clk) then
        
          if tx_en = '1' then
            tx_cnt <= 0;
            tx_bit <= 0;
          elsif tx_cnt = CLK_DIV-1 then
            tx_cnt <= 0;
            if tx_bit = 0 then
              tx_reg <= '0';
            elsif tx_bit < 8 then
              tx_reg <= din(tx_bit);
              tx_bit <= tx_bit + 1;
            else
              tx_reg <= '1'; -- Stop bit
            end if;
          else
            tx_cnt <= tx_cnt + 1;
          end if;
          
        end if;
      end process;
      
      tx <= tx_reg;
      
    end behavior;
    

    This transmits each input 8-bit word along with a start bit (logic 0) and stop bit (logic 1). The baud rate is configurable by changing the CLK_DIV constant. The transmit enable signal tx_en pulses for one clock cycle to begin transmission. A counter tx_cnt implements the clock divider, while tx_bit keeps track of the bit position during transmission.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.