html5-img
1 / 27

陳慶瀚 MIAT 嵌入式系統實驗室 國立中央大學資工系 2009 年 11 月 12 日

ESD-07 UART 控制器設計. 陳慶瀚 MIAT 嵌入式系統實驗室 國立中央大學資工系 2009 年 11 月 12 日. Synchronous Serial Standard. Asynchronous Serial Standard. Universal Synchronous/Asynchronous Receiver Transmitter (USART or UART). Asynchronous Serial Standard. Universal Asynchronous Receive Transmit. RS-232.

barbra
Download Presentation

陳慶瀚 MIAT 嵌入式系統實驗室 國立中央大學資工系 2009 年 11 月 12 日

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ESD-07 UART控制器設計 陳慶瀚 MIAT嵌入式系統實驗室 國立中央大學資工系 2009年11月12日

  2. Synchronous Serial Standard

  3. Asynchronous Serial Standard Universal Synchronous/Asynchronous Receiver Transmitter (USART or UART)

  4. Asynchronous Serial Standard Universal Asynchronous Receive Transmit

  5. RS-232 • The UART input/output uses 0V for logic 0and 5V for logic 1. • The RS-232 standard (and the COM port)use +12V for logic 0 and –12V for logic 1. • To convert between these voltages levelswe need an additional integrated circuit(such as Maxim’s MAX232).

  6. EIA Terminology 􀂄 DTE – Data terminal equipment(computer) 􀂄 DCE – Data communication equipment(modem) 􀂄 RxD – Receiver data 􀂄 TxD – Transmitter data 􀂄 DCD – Data carrier detect (valid modemconnection) 􀂄 DTR – Data terminal ready (Computer on andsoftware is ready) 􀂄 DSR -- Data set ready (Modem on andsoftware ready) 􀂄 RTS – Request to send (DTE wants to sendcharacter) 􀂄 CTS – Clear to send (DCE acknowledge toRTS from DTE) 􀂄 RI – Ring indicator from telephone

  7. UART Communication Protocol 在UART的傳輸協定中,起始位元固定為LOW,停止位元固定為HI,所以接收端的動作是一直不斷的檢查傳輸線的狀態。當傳輸線上的信號一直為HI就表示沒有資料傳送;當傳輸線上的信號由HI變為LOW,即表示有資料將傳送,接收端就會開始準備接收8個位元資料,直到傳送完8個位元資料,傳送端最後會送出停止位元,並使傳輸線的信號保持為HI,以等待下一次的資料傳輸。

  8. UART控制器架構

  9. UART控制器I/O 訊號定義

  10. Baud Rate for UART Baud rate的產生是由系統時脈(System Clock)除頻得到,系統時脈越高,可產生較為精確的baud rate,若以150Mhz為系統主要頻率,要產生115200的baud rate ,必須將150Mhz除以1302約為115207,其誤差率為0.006%,是相當的小的誤差。

  11. Baud Rate for UART 在接收端的部分,為了防止雜訊干擾取到錯誤的訊號,通常會將單一資料連續取樣16次,在由所得的樣本中間第8次來判斷此筆資料是HI或LOW,因此接收端的取樣速度必須16倍於傳送端,若傳送端是115200 baud rate ,則接收取樣率為1843200(150M/82)。

  12. Baud Rate Generator

  13. UART控制器功能模組

  14. Transmit 模組GRAFCET 建模

  15. Receive模組GRAFCET 建模

  16. UARTEntity ENTITY UART IS PORT ( CLK : IN STD_LOGIC; RST : IN STD_LOGIC; RXD : IN STD_LOGIC; SET_RATE : IN STD_LOGIC; HIGH_RATE : IN STD_LOGIC_VECTOR(7 DOWNTO 0); LOW_RATE : IN STD_LOGIC_VECTOR(7 DOWNTO 0); TX_E : IN STD_LOGIC; TX_DATA : IN STD_LOGIC_VECTOR(7 DOWNTO 0); TXD : OUT STD_LOGIC; RX_DATA : OUT STD_LOGIC_VECTOR(7 DOWNTO 0); ERR : OUT STD_LOGIC; RX_FINISH : OUT STD_LOGIC; TX_FINISH : OUT STD_LOGIC );

  17. ARCHITECTURE RTL OF UART IS SIGNAL ENABLE_R_IO : STD_LOGIC; SIGNAL ENABLE_T_IO : STD_LOGIC; COMPONENT BaudRate_Generator PORT ( ..… ); END COMPONENT BaudRate_Generator; COMPONENT Transmit_Module PORT ( …… ); END COMPONENT Transmit_Module; COMPONENT Received_Module PORT ( …… ); END COMPONENT Received_Module; BEGIN M0 : BaudRate_Generator PORT MAP(….); M1 : Transmit_Module PORT MAP (….); M2 : Received_Module PORT MAP (….); END RTL; Component-based Architecture

  18. Baudrate Generator電路設計

  19. BaudRate_GeneratorVHDL Model entity clk_divider is port(Sysclk, rst_b: in std_logic; Sel: in unsigned(2 downto 0); BclkX8: buffer std_logic; Bclk: out std_logic); end clk_divider; architecture baudgen of clk_divider is signal ctr1: unsigned(3 downto 0) := "0000"; -- divide by 13 counter signal ctr2: unsigned(7 downto 0) := "00000000"; -- div by 256 ctr signal ctr3: unsigned(2 downto 0) := "000"; -- divide by 8 counter signal Clkdiv13: std_logic;

  20. BaudRate_GeneratorVHDL Model(2) begin process(Sysclk) -- first divide system clock by 13 begin if (Sysclk'event and Sysclk = '1') then if (ctr1 = "1100") then ctr1 <= "0000"; else ctr1 <= ctr1 + 1; end if; end if; end process; Clkdiv13 <= ctr1(3);

  21. BaudRate_Generator VHDL Model(3) process(Clkdiv13) -- ctr2 is an 8-bit counter begin if (Clkdiv13'event and Clkdiv13 = '1') then ctr2 <= ctr2 + 1; end if; end process; BclkX8 <= ctr2(to_integer(sel)); -- MUX process(BclkX8) begin if (BclkX8'event and BclkX8 = '1') then ctr3 <= ctr3 + 1; end if; end process; Bclk <= ctr3(2); end baudgen;

  22. UART Transmitter模組

  23. 狀態0:暫存器Ready_REG = 0,傳輸結束訊號FINISH = 0,TX腳位為1。若觸發訊號S0 = 1,則狀態轉移到狀態1,否則不轉態。 • 狀態1:將傳送的資料DATA_I存放於暫存器TX_BUFF,Ready_REG = 1,並將BitCnt_REG計數器清空,等待傳輸baudrate TBAUDRATE_I=1,轉移到狀態2。 • 狀態2:TX傳出TX_BUFF(0),又將TX_BUFF右移1Bit,並累加BitCnt_REG後直接轉態到狀態3。 • 狀態3:等待傳輸baudrate TBAUDRATE_I=0,轉態到狀態4。 • 狀態4:當TBAUDRATE_I=1,且BitCnt_REG<10則回到轉到狀態2,否則轉到狀態5 • 狀態5:傳輸結束訊號FINISH = 1,若觸發訊號S0 = 0,則回到初始狀態0,否則不轉態。 UART Transmitter離散事件建模

  24. UART Transmitter電路合成 請上機完成此一電路模擬驗證

  25. UART Receiver模組

  26. 狀態0:計數器BitCnt_REG = 0,傳輸結束訊號FINISH = 0。若UART資料接收端RX = 0,則狀態轉移到狀態1,否則不轉態,並開始啟動接收。 狀態1:取樣計數器SampleCnt_REG = 0,並直接轉態到狀態2。 狀態2:等待RBAUDRATE_I=1,此時若SampleCnt_REG=8,則轉移到狀態4,SampleCnt_REG=15,則轉移到狀態6,否則轉移到狀態3。 狀態3:累加SampleCnt_REG,並轉移到狀態5 狀態4:將UART資料接收端RX 存入暫存器RX_BUFF並右移1,累加SampleCnt_REG後轉態到狀態5。 狀態5:等待RBAUDRATE_I=0,轉態到狀態2。 狀態6:將BitCnt_REG加1,轉態到狀態7。 狀態7:等待RBAUDRATE_I=0,此時若BitCnt_REG<10,則轉移到狀態1繼續接收下一個資料,否則則轉移到狀態8。 狀態8:將接收的資料RX_BUFF傳出,並設定資料錯誤訊號ERR,並直接轉態到狀態9。 狀態9:接收結束訊號FINISH = 1,並直接轉態到初始狀態。 UART Receiver離散事件建模

  27. 練習:UART Receiver電路合成 請上機完成此一電路模擬驗證

More Related