版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、第三章UART設(shè)計 3.1 UART的幀格式 在UART中,數(shù)據(jù)位是以字符為傳送單位,數(shù)據(jù)的前、后要有起始位、停止 位,另外可以在停止位的前面加上一個比特(bit)的校驗位。其幀格式如圖所示 數(shù)據(jù)位 起始位 D0 D1 D2 D3 D7 校驗位 停止位 以9600波特率接收或發(fā)送,每一位時間為 1/9600秒,或48MHZ晶振5000次計數(shù) 圖3_1數(shù)據(jù)幀格式 文章通 過分析UART的功能,利用有限狀態(tài)機來描述UART核心控制邏輯 的方法,將其核心功能集成,從而使整個設(shè)計更加穩(wěn)定、可靠?;镜腢ART 通信只需要兩條信號線就可以完成數(shù)據(jù)的相互通信。 UART的功能模塊如圖3_2 所示。 圖3
2、2UART的功能模塊圖 3.2 UART 模塊 在大規(guī)模電路的設(shè)計中,廣泛采用層次化,結(jié)構(gòu)化的設(shè)計方法。它將一個完 整的硬件設(shè)計任務(wù)從系統(tǒng)級開始,劃分為若干個可操作的模塊,編制出相應(yīng)的模 型并進行仿真驗證,最后在系統(tǒng)級上進行組合。這樣在提高設(shè)計效率的同時又提 高了設(shè)計質(zhì)量,是目前復(fù)雜數(shù)字系統(tǒng)實現(xiàn)的主要手段,也是本文設(shè)計思想的基礎(chǔ) 其系統(tǒng)模塊可劃分為4個部分,如波特發(fā)生器,控制器,接收器,發(fā)送器,如圖 3-3所示: 圖3-3uart結(jié)構(gòu)圖 3.2.1主要引腳功能介紹 Read串行輸入 Datan并行輸入 Cs通知cpu接收數(shù)據(jù)位 Reset重啟輸入 Clk:48M時鐘輸入 sen d:串行輸出
3、data_out并行輸出 ks:通知cpu發(fā)送準備位 state:uart狀態(tài)輸入 3.2.2UART主體程序 timescale 1ns/1ns module gs_opt( in put wire read, in put wire clk, in put wire reset, in put wire state, in put wire 7:0 dat_in, output wire send, output wire cs, output wire ks, output wire 7:0 dat_out ); wire send_en able; wire read_e nable;
4、 wire clk_e nable3; wire clk_e nable4; wire clear3 ; wire clear4 ; wire clk_e nable; wire 7:0 coun ters; wire clear ; wiret1; /* read,se nd,cs,ks,reset,state,clk,dat_i n,dat_out); /module uart(read,se nd,cs,ks,reset,state,clk,dat_i n,dat_out); in put read,clk,reset,state; /read為串行輸入,clk為時鐘輸入50MHZ ,
5、reset為重啟鍵 in put7:0 dat_i n;并行數(shù)據(jù)輸入 output sen d,cs,ks; /send為串行輸出,cs為通知cpu接收數(shù)據(jù)位,ks為發(fā)送準備位 output7:0 dat_out;/ 并行數(shù)據(jù)輸出 wire clear,clk_e nable,read_e nable,clear3,se nd_en able,clear4,t1; wire7:0 coun ters,dat_i n;*/ rxd u1 ( .dat_out (dat_out) , .cs (cs), .read (read), .reset (reset) , .clk_e nable3 (c
6、lk_e nable3), .clk (clk) , .read_enable (read_enable), .clear3 (clear3), .co un ters(co un ters) );/接收數(shù)據(jù)module txd u2 ( .dat_in (dat_i n), .ks (ks), .se nd (se nd), .reset (reset), .clk_e nable4 (clk_e nable4), .clk (clk), .se nd_en able (se nd_en able), .clear4 (clear4), .co un ters( coun ters) );發(fā)
7、送數(shù)據(jù)module clk_bau u3 ( .clk(clk), t1 (t1), .clk_e nable (clk_e nable) );時鐘計數(shù)器模塊 ctrl u4( .read_e nable (read_e nable), .se nd_en able (se nd_en able), .clk (clk), .state (state), .t1 (t1), .read (read ), .co un ters (cou nters), .reset (reset ), .clear (clear) ); check_cle u5 ( .state (state), .clea
8、r3 (clear3), .clear4 (clear4), .clear (clear), .clk_e nable3 (clk_e nable3), .clk_e nable4 (clk_e nable4), .clk_e nable (clk_e nable) ); en dmodule/ / 3.3UART發(fā)送模塊 3.3.1UART的數(shù)據(jù)發(fā)送服務(wù) 發(fā)送器實現(xiàn)的功能是將輸入的8位并行數(shù)據(jù)變?yōu)榇袛?shù)據(jù),同時在數(shù)據(jù)頭部加 起始位,在數(shù)據(jù)位尾部加奇偶校驗位和停止位。數(shù)據(jù)發(fā)送服務(wù)如表3.1 計數(shù)器 0 18 9 10 操作 發(fā)送低電平 發(fā)送數(shù)據(jù)和奇 偶校驗 發(fā)送奇偶校驗 結(jié)果 發(fā)送高電平 表3
9、.1數(shù)據(jù)發(fā)送 其基本特點是: 在信號線上共有兩種狀態(tài),可分別用邏輯 1和邏輯。來區(qū)分。在發(fā)送器空 閑時,數(shù)據(jù)線應(yīng)該保持在邏輯高電平狀態(tài)。 發(fā)送 起 始 位:該位是一個邏輯0,總是加在每一幀的頭部,提示接受器數(shù)據(jù) 傳輸即將開始,在接收數(shù)據(jù)位過程中又被分離出去,占據(jù)一個數(shù)據(jù)位的時間。 發(fā)送數(shù)據(jù)位:在起始位之后就是數(shù)據(jù)位,一般為8位一個字節(jié)的數(shù)據(jù),低位 在前,高位在后。如字母 C在ASCII表中是十進制67,二進制01000011,那么 傳輸?shù)膶⑹?10000100=并在數(shù)據(jù)發(fā)送過程當(dāng)中,進行數(shù)據(jù)位奇偶校驗。 發(fā)送校 驗 位:該位一般用來判斷接收的數(shù)據(jù)位有無錯誤, 常用的校驗方法是 奇偶校驗法。將3
10、過程當(dāng)中奇偶校驗的結(jié)果輸入到數(shù)據(jù)線,并占一個數(shù)據(jù)位時鐘。 停止位:停止位總在每一幀的末尾,為邏輯1,用于標(biāo)志一個字符傳送的結(jié)束, 占據(jù)一個數(shù)據(jù)位的時間。 幀:從起始位到停止位之間的一組數(shù)據(jù)稱為一幀。 3.3.2UART的數(shù)據(jù)發(fā)送操作 如圖3-4 圖3-4數(shù)據(jù)發(fā)送操作 解釋:采用9600波特率發(fā)送 從cpu傳入數(shù)據(jù):是指將data_in端口的數(shù)據(jù)存入寄存器中 Cpu發(fā)送為檢測:是指將ks寄存器置位,即數(shù)據(jù)發(fā)送完畢 3.3.3UART的數(shù)據(jù)發(fā)送模塊程序 module rxd(dat_out,cs,read,reset, clk_e nable3,clk,read_e nable,clear3,co
11、 un ters); 接收數(shù)據(jù)module in put read_e nable; in put read,reset,clk;/read 為串行輸入,read_co ntrol 為時鐘控制,reset 為 重啟鍵 in put7:0 coun ters; output cs,clear3,clk_enable3;/cs為通知 cpu 讀取數(shù)據(jù)位 output7:0 dat_out;/wire clear3; reg cs,cs1,clk_e nable3; reg7:0 data_out;移位寄存器 reg parity_check_result,parity_result,clear3,
12、clear1;/ / always(posedge clk) beg in if(read_enable)/當(dāng)read_enable為高電平時為發(fā)送操作狀態(tài) beg in clk_e nable3=1; clear3=clear1; end else beg in clear3=1; end end / always(negedge countersO) /接收操作 if(read_e nable parity_check_result=parity_check_result + read; end else if (cou nters=8b00101000) 2 beg in data_ou
13、t6v=read; parity_check_result=parity_check_result + read; end else if (cou nters=8b00111000) 3 beg in data_out5v=read; parity_check_result=parity_check_result + read; end else if (cou nters=8b01001000) 4 beg in data_out4=read; parity_check_result=parity_check_result + read; end else if (cou nters=8b
14、01011000) 5 beg in data_out3=read; parity_check_result=parity_check_result + read; end else if (cou nters=8b01101000) 6 beg in data_out2v=read; parity_check_result=parity_check_result + read; end else if (cou nters=8b01111000) 7 beg in data_out1=read; parity_check_result=parity_check_result + read;
15、end else if (cou nters=8b10001000) 8 beg in data_out0=read; parity_check_result=parity_check_result + read; end else if (cou nters=8b10011000) 9進行奇偶校驗檢測 beg in parity_result=read; parity_result=#2 (parity_check_result = parity_result) 1:0; end else if (cou nters=8b10101000) 0進行幀檢測 beg in cs1=(read)
16、? 1:0; end else if (counters=8b10101010) 01 給 cpu 發(fā)送接收信號 beg in cs=(cs1 /當(dāng)奇偶校驗結(jié)果與幀 檢測結(jié)果都為1時,cs置位一 clear1=1; /clk_e nable=0; clk_e nable3=0; end else if(cou nters=8b00001000)/檢測是否是毛刺 beg in clear1=(!read)?0:1; end else clear1=0; end else clear1=1; en dmodule 3.3.4UART的數(shù)據(jù)發(fā)送模塊程序仿真圖 當(dāng)reset為零時 Interval.
17、j ps30. Q ns 1呦.卩ns 紉.p ns 320.卩 ns 400. p 480. fl n= SM.,0 n= 640. p ns TW.p ns ECO.p ns660.0 ns 960.p ns 0 us 410.0 H *J5T IKS 巧航充KI 4TU5 Q ns +S2S.0 J J d - * Slrt: End. 圖3-5reset為零時仿真圖 如圖為UART的數(shù)據(jù)發(fā)送模塊的功能仿真圖,為方便觀察,其中的時鐘是直 接給出來的,根據(jù)圖中的數(shù)據(jù)判讀,其功能為正確,UART的數(shù)據(jù)發(fā)送模塊編譯 成功。 1. 當(dāng)計時器為140 ns時,為數(shù)據(jù)接收 2. 當(dāng)計時器為357ns
18、時,為數(shù)據(jù)發(fā)送 3. 當(dāng)計時器為705ns時,為奇偶校驗結(jié)果發(fā)送 4. 當(dāng)計時器為825ns時,發(fā)送高電平 當(dāng)reset為1時 如圖3-6 elk if AS4t *1 4電_:館 R1 crant-t ssiid. eltA-ur d匕 L j ps60.0 ns16D.0 ns 4JQ.p tie 320.0 nt W. 3 TiS460.0 EkSfiC. O lE MO.卩 nr TSO-? 3 玷aoo p 頼P加 j ps J 顧TT麗 飛1麗】過廠 LtKJtittU T 0000Q000 KOOTQCOOJ X 00( LOOM XOOJOQOOO )DO1QCOOX oaoo
19、cmtj xioioooXJiioffloOJ LiwDXaraooMooiooaoMiKjojoocnocoo * J COMDGOO J D Q pi 0 pi 圖3-6reset為1時仿真圖 3.4UART接收模塊 3.4.1UART數(shù)據(jù)接收服務(wù) 串行數(shù)據(jù)幀和接收時鐘是異步的,由邏輯1跳變?yōu)檫壿?可視為一個數(shù)據(jù) 幀的開始,所以接收器首先要判斷起始位。如表3.2 計數(shù)器 0 9 10 操作 數(shù)據(jù)起始位檢 測 數(shù)據(jù)接收和奇 偶校驗 奇偶校驗 數(shù)據(jù)判斷 表3.2uart的數(shù)據(jù)接收服務(wù) 其基本特點是: UART接收狀態(tài)一共有4個:state0檢測起始位),stat e1(對數(shù)據(jù)位進行采樣, 并串
20、/并轉(zhuǎn)換),state2奇偶校驗 分析),state3接收數(shù)據(jù)正確與否檢測)。 起始位判讀:當(dāng)UART接收器復(fù)位以后,接收器將處 于這一狀態(tài)。在該狀態(tài), 控制器一直等待read電平的跳變,即從邏輯1變?yōu)檫壿?,也就是等待起始位 的到來。一旦檢測到起始位,就對采樣時鐘elk rev上跳沿計 數(shù),當(dāng)計數(shù)為 8時,也就是確保在起始位的中間點 ,然后轉(zhuǎn)到state1狀態(tài)。 數(shù)據(jù)接收:該狀態(tài)下,每間隔16位倍頻采樣一位 串行數(shù)據(jù),接收8位異步 數(shù)據(jù)并進行串/并轉(zhuǎn)換。即對clk 一 rev上跳沿計數(shù),當(dāng)為16時,就對數(shù)據(jù)采樣, 這樣 保證了數(shù)據(jù)位是在中點處被采樣的,同時串/并轉(zhuǎn)換,當(dāng)檢測到已收到8個 數(shù)據(jù)
21、后以后,便進入了 state2狀態(tài)。 奇偶校驗:該狀態(tài)實現(xiàn)的功能是奇偶校驗。本文采用的是偶校驗。校驗結(jié)束 以后,轉(zhuǎn)到state3狀態(tài)。 數(shù)據(jù)幀判讀:該狀態(tài)是用來幀校驗的,即在校驗位以后,檢測停止位是否為 邏輯高電平 3.4.2UART數(shù)據(jù)接收操作 圖3-7UART數(shù)據(jù)接收操作 圖3-7UART數(shù)據(jù)接收操作 解釋:數(shù)據(jù)接收速度9600波特率,以16倍頻接收 cpu接收位檢測:當(dāng)奇偶結(jié)果比較和數(shù)據(jù)幀檢測都正確時,cpu檢測接收位CS置 位 3.4.3UART的數(shù)據(jù)接收模塊程序 /發(fā)送數(shù)據(jù)模塊 module txd( dat_i n,sen d,reset,clk_e nable4,clk, sen
22、d_enable,clear4,counters,ks);發(fā)送數(shù)據(jù) module in put7:0 dat_ in,coun ters; in put reset,clk,se nd_en able; output sen d,clk_e nable4,clear4; output ks;/jia wire clear; wire7:0 dat_s; reg sen d,parity_result,ks; reg clk_e nable,clear1,clear4,clk_e nable4; reg7:0 date_s; / always(posedge elk) begin if(send
23、_enable clear4=clear1; end else begin clear4=1; end end / always(posedge clk) if(send_en able date_s=dat_ in;/? parity_result=1; end else if(cou nters=8bOOO1OOOO)1 begin sen d=date_s0; parity_result=parity_result + date_s0; end else if(cou nters=8bOO1OOOOO)2 begin sen d=date_s1; parity_result=parity
24、_result + date_s0; end else if(cou nters=8bOO11OOOO)3 begin sen d=date_s2; parity_result=parity_result + date_s0; end else if(cou nters=8b01000000)/4 begin sen d=date_s3; parity_result=parity_result + date_s0; end else if(cou nters=8bO1O1OOOO)5 begin sen d=date_s4; parity_result=parity_result + date
25、_s0; end else if(cou nters=8bO11OOOOO)6 begin sen d=date_s5; parity_result=parity_result + date_s0; end else if(cou nters=8bO111OOOO)7 begin sen d=date_s6; parity_result=parity_result + date_s0; end else if(cou nters=8b10000000)/8 begin sen d=date_s7; parity_result=parity_result + date_s0; end else
26、if(counters=8b10010000)/9 發(fā)送奇偶校驗結(jié)果 begin sen d=parity_result; end else if(counters=8b10100000)/0 發(fā)送高電平 begin send=1; end else if(cou nters=8b10101111)/0 begin clear1=1; ks=(se nd end else if(cou nters=8b00000000) begin send=1; end else clear1=0; end else send=1; en dmodule / 3.4.4UART的數(shù)據(jù)接收模塊程序功能仿真圖
27、圖3-8當(dāng)counters指定時間時功能仿真 二土二S E CAUXlit iHFX E4Vnt UEPI*. cunt El d.t -肛“E -rUl. ft -址心旳】 -d*Lfc(| -d.kE 13 4LQ. KA3D.O DhE歸口 O M Tie 55U.a E:K aiLDiaDD (COX I 1. LOT: XanJt IDDOiaOD 3 fioXLDonDcn it-aX LB:ii.ooa II 1 _1 |_ | -1 L l 1_ _ _J- 1 1 IOLLlldO lCliLLllti LU 圖3-8當(dāng)cou nters指定時間時 解釋:由圖可明顯看出dat
28、aO和data1變化,模塊功能仿真通過 dk u mDKOOD o 弱.弱 nsStw!. 站 ns* fc|rgiagr:関. ns 圖3-9當(dāng)counters未指定時間時功能仿真 _rL_rL_r_r_r_nr_r_r_r_jn_rL_L_LL,_r_ 門 口一 1 口 門 n.n n nn n.n n. n 廠.n.r n.n n n 一 n. r.n r.n r. n .n n.r injunTumuuiunRunjuiujuiRinnRUJUivLnnRinjuiJVLJWLnnnnw-iJWjm WiroomnwwTjmimuimniranmojimiainiimomU-WMinw
29、uiniinrnwinnwii COUAtbfsCD reset clk_frTiiabls LL11.LLL3 圖3-9當(dāng)counters未指定時間時功能仿真 Bunt ers camll Laouccoa 3.5UART控制器 3.5.1UART控制器服務(wù) UART控制器實質(zhì)上是一組計數(shù)器,由 state決定計數(shù)器數(shù)據(jù)發(fā)送對象,在這 里指定當(dāng)state為1時,發(fā)送到UART接收模塊,反之,發(fā)送到UART發(fā)送模塊 當(dāng)計數(shù)到指定數(shù)據(jù)時,觸發(fā)指定模塊的制定操作。 3.5.2UART控制器模塊程序 module coun ters(read_e nable,se nd_en able, clk,s
30、tate,t1,read,co un ters,reset,clear)程序計數(shù)寄存器 in put clk,state,t1,read,reset,clear;/stat為 uart 狀態(tài)輸入, /clear為程序計數(shù)寄存器清零控制位 output7:0 coun ters; -lit ft 2 -g譏門 -dtOl output read_e nable,se nd_en able; reg read_enable,send_enable,control;/read_enab為接收控制位?/ /send_enable為發(fā)送控制位,control為程序計數(shù)寄存器為零狀態(tài)寄存位 reg7:0
31、co un ters;/8位程序計數(shù)寄存器 always(posedge clk) /當(dāng)程序計數(shù)寄存器為零時,程序計數(shù)寄存器為零狀態(tài)寄存位置位 begi n con trol=(!co un ters)? 1 : 0; end / always (n egedge read)/uar發(fā)送或接收狀態(tài)判斷 if(con trol) beg in if(state) begi n if(!read) beg in read_e nable=1; send_en able=0; end else beg in send_en able=0; end end else begi n send_en able=1; read_e nable8b10101111) cou nters=8b00000000; else coun ters=co un ters + 1;
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 二零二五年度基礎(chǔ)設(shè)施建設(shè)合作協(xié)議2篇
- 水池回廊景石施工方案
- 二零二五年度個人股權(quán)投資退出協(xié)議2篇
- 二零二五年度高品質(zhì)住宅小區(qū)物業(yè)經(jīng)營權(quán)轉(zhuǎn)讓合同3篇
- 二零二五年度個人教育培訓(xùn)機構(gòu)合作協(xié)議范本3篇
- 2025版送氣工被辭退經(jīng)濟補償合同3篇
- 二零二五年度個人旅游保險代理銷售合同(出境游保障)
- 蒸壓加氣混凝土砌塊砌筑施工方案
- 二零二五年度汽車租賃個人司機勞動合同8篇
- 二零二五年度房產(chǎn)共有權(quán)售房合同協(xié)議3篇
- 山東省泰安市2022年初中學(xué)業(yè)水平考試生物試題
- 注塑部質(zhì)量控制標(biāo)準全套
- 受賄案例心得體會
- 人教A版高中數(shù)學(xué)選擇性必修第一冊第二章直線和圓的方程-經(jīng)典例題及配套練習(xí)題含答案解析
- 畢業(yè)設(shè)計(論文)-液體藥品灌裝機的設(shè)計與制造
- 銀行網(wǎng)點服務(wù)禮儀標(biāo)準培訓(xùn)課件
- 二年級下冊數(shù)學(xué)教案 -《數(shù)一數(shù)(二)》 北師大版
- 晶體三極管資料
- 銀行內(nèi)部舉報管理規(guī)定
- 石群邱關(guān)源電路(第1至7單元)白底課件
- 平面幾何強化訓(xùn)練題集:初中分冊數(shù)學(xué)練習(xí)題
評論
0/150
提交評論