design uart using vhdl

Upload: lizhi0007

Post on 18-Oct-2015

61 views

Category:

Documents


0 download

TRANSCRIPT

  • 5/27/2018 Design UART Using VHDL

    1/18

    ALSE - Sept 2001

    VHDL - Practical Example -

    Designing an UART

    Bertrand CUZEAU

    Technical Manager - ALSE

    ASIC / FPGA Design Expert

    Doulos HDL Instructor (Verilog-VHDL)

    [email protected]://www.alse-fr.com

    : 33.(0)1 45 82 64 01

    mailto:[email protected]://www.alse-fr.com/http://www.alse-fr.com/mailto:[email protected]
  • 5/27/2018 Design UART Using VHDL

    2/18

    Introduction

    We will demonstrate, on a real-lifeexample, how a

    sound HDL methodology can be used in conjunction

    with modern synthesis and simulation tools.

    Note : the source code we provide here if for teaching purpose only.

    This code belongs to ALSE.If you want to use it in your projects please contact us.

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    3/18

    UART Specification

    We want to address the following needs :

    Transmit / Receive with h/w handshake N81Format , but plan for parity Speed : 1200..115200 baud (Clock = 14.7456 MHz)

    No internal Fifo (usually not needed in an FPGA !) Limited frame timing checks

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    4/18

    Methodology

    We adopt the following constraints :

    Standard & 100% portable VHDL Description :-Synthesis-Simulation-Target FPGA (or CPLD)

    Complete functional Simulation with file I/O.

    Should work invivoon an existing ALSE demo board. Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    5/18

    RS 232 OutputUARTS

    TXSDout[7:0]

    LD_SDout

    Din[7:0]

    LD

    Tx * TXoutRS232 Inputs I14

    TxBusyTxBusy (0=active)

    RawRx

    CLK

    RX

    Baud[2:0]

    TxBusy

    SDin[7:0]

    RxRDYRxErr

    RTS

    RXFLEX * D Q Rx

    Baud[2:0]

    CLKRST

    SDout[7:0] SDout[7:0]

    LD_SDout LD_SDout

    * CTSFLEXSDin[7:0]

    RxRDYRxErr

    I15 I202Dout[7:0]

    RxRDYRxErr

    Noted on PCB = RTSFlexC

    CLKRST

    I306RST

    I320

    UART moduleNoted on PCB = CTSFlex

    ApplicationRawRTS RTSRTSFLEX * D QI54 I218 CLKInversion needed C

    I307RST

    CLKRST

    CLKRSTExternal Baud Rate Selection

    Baud[2]

    Baud[1]

    Baud[0]

    DIPSW[2]

    DIPSW[1]

    DIPSW[0]

    I319

    I318

    I317

    Bertrand CUZEAU -info@alse-

    *

    *

    *

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    6/18

    Baud Rate Generator

    Embedded in UARTS.

    Divides by 8, 16, 28, 48, 96, 192, 384 or 768and builds Top16.

    Generates two ticks by further dividing Top16 :

    -Transmit : TopTx, fixed rate

    -Receive : TopRx, mid-bit, resynchronized

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    7/18

    -- ---------------------------- Baud rate selection-- --------------------------process (RST, CLK)beginif RST='1' then

    Divisor Divisor Divisor Divisor Divisor Divisor Divisor Divisor Divisor Divisor

  • 5/27/2018 Design UART Using VHDL

    8/18

    Transmitter

    We use a very simple State Machine to control the

    transmit shift register. The FSM inputs are :LD : Loads the character to transmit (Din)

    TopTx : Bit shifting command

    For simplicity we code the FSM as a

    re-synchronizedMealy.

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    9/18

    -- ---------------------------- Transmit State Machine-- --------------------------

    TX

  • 5/27/2018 Design UART Using VHDL

    10/18

    Receiver

    We also use a State Machine :

    Wait RX (Start bit) falling edge,

    Synchronize the Half-bit counter

    Sample RX at mid-bit and verify the Start bit

    Loop on the data bits (+ parity) :

    *Skip transition

    *Sample at mid-bit

    Sample and Test Stop bit Return to Idle state (waiting for a new Start condition)

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    11/18

    Bertrand CUZEAU - [email protected]

    -- -------------------------- RECEIVE State Machine-- ------------------------Rx_FSM: process (RST, CLK)begin

    if RST='1' thenRx_Reg '0');Dout '0');RxBitCnt

  • 5/27/2018 Design UART Using VHDL

    12/18

    Bertrand CUZEAU - [email protected]

    Receiver State Machine

  • 5/27/2018 Design UART Using VHDL

    13/18

    Test Application

    To test our UART, we use a trivial application which

    increments the characters received and resends them !

    (Example : AB, fg,HALIBM)

    This way, it is easy to verify the reveive and transmit

    operations, both by simulation and on the demo board.

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    14/18

    -- APPLIC.vhd-- ------------------------------------------------------ Demo for UART module-- ------------------------------------------------------ Bertrand Cuzeau /[email protected] Receives a char, and re-emits the same char + 1

    LIBRARY ieee;USE ieee.std_logic_1164.ALL;USE ieee.numeric_std.ALL;

    -- ----------------------------------------------------Entity APPLIC is

    -- ----------------------------------------------------Port ( CLK : In std_logic;

    RST : Instd_logic;RTS : In std_logic;

    RxErr : In std_logic;RxRDY : In std_logic;SDin : In std_logic_vector (7 downto 0);

    TxBusy : In std_logic;LD_SDout : Out std_logic;

    SDout : Out std_logic_vector (7 downto 0));

    end APPLIC;

    -- ----------------------------------------------------Architecture RTL of APPLIC is

    -- ----------------------------------------------------type State_Type is (Idle, Get, Send);signal State : State_Type;

    signal RData : std_logic_vector (7 downto 0);

    signal SData : std_logic_vector (7 downto 0);

    begin

    SDout

  • 5/27/2018 Design UART Using VHDL

    15/18

    Test Bench

    The VHDL Test Bench simply sends the ASCII character A

    and displays the character(s) sent back by the system.

    It is based on two behavioral UART routines (described in

    another of our conferences).

    A much more sophisticated Test Bench (with file I/O and

    console emulation with inter-character spacing) is provided byALSE in the commercial version.

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    16/18

    -- ----------------------------------------------- Simple VHDL test bench for UART Top_Level-- ----------------------------------------------- (c) ALSE - Bertrand [email protected]

    USE std.textio.all;LIBRARY ieee;

    USE ieee.std_logic_1164.ALL;USE ieee.numeric_std.ALL;USE ieee.std_logic_textio.ALL;

    entity testbench isend testbench;-- ---------------------------------------------Architecture TEST of testbench is

    component ALSE_UARTPort ( RST : In std_logic;

    CLK : In std_logic;RXFLEX : In std_logic;RTSFLEX : In std_logic;DIPSW : In std_logic_vector (2 downto 0);

    CTSFLEX : Out std_logic;TXout : Out std_logic );

    end component;

    constant period : time := 68 ns;constant BITperiod : time := 8680 ns; -- 115.200signal RSData : std_logic_vector (7 downto 0);signal CLK : std_logic := '0';signal RST : std_logic;signal RXFLEX : std_logic;signal RTSFLEX : std_logic;signal DIPSW : std_logic_vector (2 downto 0);

    signal CTSFLEX : std_logic;signal TXout : std_logic;begin-- UUT Instanciation :UUT : ALSE_UARTPort Map (CLK=>CLK, CTSFLEX=>CTSFLEX, DIPSW=>DIPSW,

    RST=>RST, RTSFLEX=>RTSFLEX, RXFLEX=>RXFLEX,TXout=>TXout );

    -- Clock, Reset & DIP-SwitchesRST transcript

    end loop;end process;end TEST;

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    17/18

    Lets make it work !

    After the theory, we are now going to follow the entire design

    flow, down to the Demo Board (~10 minutes) :

    1.Build the Project2.Syntactic Verification

    3.Unitary Functional Simulation

    4.Unitary Logic Synthesis

    5.System-Level Simulation

    6.Global Synthesis7.Place and Route

    8.Download & tests on the demo board (using HyperTerminal !)

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]
  • 5/27/2018 Design UART Using VHDL

    18/18

    Conclusion

    It takes less than a working day to design and test a simple UART

    like this one. Powerful HDL languages, as well as capable

    Simulation and Synthesis Tools are now widely available.

    With the right methodology and some design practice, projects that

    used to be considered as complex become almost trivial.

    Note : an enhanced version of this UART, still simple and efficient, isavailable at ALSE, at a very affordable cost.

    Bertrand CUZEAU [email protected]

    mailto:[email protected]:[email protected]:[email protected]