內(nèi)置FIFO的UART設(shè)計(jì)與實(shí)現(xiàn)_第1頁
內(nèi)置FIFO的UART設(shè)計(jì)與實(shí)現(xiàn)_第2頁
內(nèi)置FIFO的UART設(shè)計(jì)與實(shí)現(xiàn)_第3頁
內(nèi)置FIFO的UART設(shè)計(jì)與實(shí)現(xiàn)_第4頁
內(nèi)置FIFO的UART設(shè)計(jì)與實(shí)現(xiàn)_第5頁
已閱讀5頁,還剩10頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

1、內(nèi)置FIFO的UART設(shè)計(jì)與實(shí)現(xiàn)一、程序(加批注)library ieee; -U1:RSRuse ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity RSR is port(reset:in std_logic; rx:in std_logic; clk:in std_logic; rx_data:out std_logic_vector(7 downto 0); rx_int:out std_logic);end entity; architecture ar

2、c of RSR issignal shifter:std_logic_vector(7 downto 0);signal bitstate:integer range 0 to 10:=0;beginprocess(clk,reset,rx) -接收進(jìn)程begin if(reset=1) then -復(fù)位信號 bitstate=0; shifter=ZZZZZZZZ; elsif(rising_edge(clk) then if(bitstate=0) then -狀態(tài)0 判斷有沒有數(shù)據(jù)輸入 if(rx=0) then bitstate=bitstate+1; end if; elsif(b

3、itstate=9) then -狀態(tài)9 數(shù)據(jù)接收完成 bitstate=0; else -其他狀態(tài)接收1-8為數(shù)據(jù),停止位不檢查 shifter(0)=rx; shifter(7 downto 1)=shifter(6 downto 0); bitstate=bitstate+1; end if; end if; end process;process(clk,reset) -輸出進(jìn)程begin if(reset=1) then rx_data=00000000; rx_int=0; elsif(rising_edge(clk) then if(bitstate=9) then rx_dat

4、a=shifter; -數(shù)據(jù)輸出 rx_int=1; else rx_int=0; rx_data=ZZZZZZZZ; end if; end if;end process; end arc; library ieee; -U2:FIFO ( 8 * 8 bit )use ieee.std_logic_1164.all;entity FIFO is port( clock : in std_logic; reset : in std_logic; wr_req : in std_logic; -寫請求 rd_req : in std_logic; -讀請求 data_in : in std_l

5、ogic_vector(7 downto 0); full : buffer std_logic; -滿狀態(tài),1有效 empty : buffer std_logic; -空狀態(tài),1有效 data_out : out std_logic_vector(7 downto 0);end FIFO;architecture arch of FIFO is type type_2d_array is array(0 to 7) of std_logic_vector(7 downto 0); signal fifo_memory : type_2d_array; signal wr_address :

6、 integer range 0 to 7; signal rd_address : integer range 0 to 7; signal offset : integer range 0 to 7; signal data_buffer : std_logic_vector(7 downto 0);beginoffset rd_address)else (8 - (rd_address - wr_address)when (rd_address wr_address)else 0;empty = 1 when (offset = 0) else 0; full = 1 when (off

7、set = 7) else 0; -實(shí)際存儲空間7 * 8 bit,空出1*8bit以區(qū)分空和滿process(clock,rd_req) -讀進(jìn)程begin if (clockevent and clock=1) then -同步清0 if reset = 1 then rd_address = 0; data_buffer 0); elsif (rd_req = 1 and empty = 0) then -讀出數(shù)據(jù) data_buffer rd_address rd_address = rd_address + 1 ; end case; end if; end if;end proce

8、ss;data_out = data_buffer ;process(clock,wr_req) -寫進(jìn)程begin if (clockevent and clock=1) then -同步清0 if reset = 1 then wr_address = 0; elsif (wr_req = 1 and full = 0) then -寫入數(shù)據(jù) fifo_memory(wr_address) wr_address wr_address = wr_address + 1 ; end case; end if; end if;end process;end arch;library ieee;

9、-U3:TSRuse ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity TSR is port(reset:in std_logic; tx_data:in std_logic_vector(7 downto 0); tx_int:in std_logic; - clk:in std_logic; tx:out std_logic; tx_req:out std_logic);end entity; architecture arc of TSR issigna

10、l shifter:std_logic_vector(7 downto 0);type state is(s0,s1,s2);beginprocess(clk,reset) variable cnt:integer range 0 to 8:=0; variable present_state:state;begin if(reset=1) then tx=1; tx_req -判定有沒有并行數(shù)據(jù)輸入 if(tx_int=0) then shifter=tx_data; tx=1; tx_req=1; present_state:=s1; -一旦進(jìn)入并串轉(zhuǎn)換輸出,TSR不再受empty的控制

11、else tx=1; tx_req -狀態(tài)1,低電平起始位輸出 tx=0; tx_req -狀態(tài)2,8位數(shù)據(jù)移位輸出 if(cnt8) then tx=shifter(7-cnt); cnt:=cnt+1; tx_req=0; present_state:=s2; else -狀態(tài)2,高電平停止位輸出 cnt:=0; tx=1; tx_reqRXD,clk=bps_clk,reset=rst,rx_data=data1,rx_int=req1);U2:FIFO port map(data_in=data1,wr_req=req1,clock=bps_clk,reset=rst,data_out

12、=data2,rd_req=req2,empty=req3);U3:TSR port map(tx_data=data2,tx_int=req3,clk=bps_clk,reset=rst,tx_req=req2,tx=TXD);end arc;二、功能仿真如圖中若干藍(lán)線的劃分:輸入RXD:0 0000 0100 1 0 0001 0000 1 0 0011 0000 1 0 0110 1001 1 (即以8421BCD碼形式輸入本人的學(xué)號:04103069) 0 0000 0000 1 1 1111 1111 1(無效輸入)對于第五行(即輸入00)的說明:本程序設(shè)計(jì) 發(fā)送模塊TSR 控制FI

13、FO的rd_req信號:只有當(dāng)FIFO成功將其輸出傳送給TSR之后,才會產(chǎn)生tx_req信號控制rd_req信號并在下一個(gè)時(shí)鐘上升沿下,F(xiàn)IFO進(jìn)行讀進(jìn)程實(shí)現(xiàn)讀取輸出(只有這樣才能實(shí)現(xiàn)FIFO輸出的刷新)以及讀指針的自增操作。而對于輸入的數(shù)據(jù)69,盡管FIFO最終已經(jīng)將其輸出,但是由于讀指針實(shí)現(xiàn)自增,empty變成1,無法將數(shù)據(jù)69傳輸?shù)桨l(fā)送模塊TSR。所以在輸入的學(xué)號數(shù)據(jù)后面還要加上一個(gè)無用的8位數(shù)據(jù)將其寫入FIFO以使寫指針自增,實(shí)現(xiàn)empty=0,再在下一個(gè)時(shí)鐘上升沿下將數(shù)據(jù)69傳送到TSR,最終將輸入的學(xué)號數(shù)據(jù)完整的輸出。如圖中若干藍(lán)線的劃分:輸出TXD:1 0 0000 0000 1

14、 1 0 0000 0100 1 1 0 0001 0000 1 1 0 0011 0000 1 1 0 0110 1001 1(學(xué)號04103069的輸出) 1 1 1111 1111 1(無效)對于第一行(即輸出00)說明:由圖可以看出是在第13個(gè)時(shí)鐘周期開始輸出的,因?yàn)殚_始清0后empty=1,直到第10個(gè)時(shí)鐘上升沿下,rx_int=1(即wr_req=1)并且RSR輸出數(shù)據(jù),在第11個(gè)時(shí)鐘上升沿下,向FIFO中寫入數(shù)據(jù)04,empty=0(即tx_int=0),在第12個(gè)時(shí)鐘上升沿下,F(xiàn)IFO的輸出要送入TSR并且TSR輸出1(此時(shí)tx_req=1)。而在此之前,因?yàn)閠x_req=0(

15、即rd_req=0),盡管讀指針為0不變并且所指向的數(shù)據(jù)變成04(即只執(zhí)行了寫進(jìn)程而沒有進(jìn)行讀進(jìn)程),但是FIFO的輸出一直保持著一開始復(fù)位清0時(shí)的輸出00,在第13個(gè)時(shí)鐘上升沿下TSR輸出數(shù)據(jù)的起始位0(此時(shí)FIFO進(jìn)行讀進(jìn)程,F(xiàn)IFO讀取讀指針?biāo)赶虻臄?shù)據(jù)04,輸出變?yōu)?4,但是讀指針實(shí)現(xiàn)自增致使empty=1,不能將數(shù)據(jù)04送入TSR),接著依次輸出00。說明:接收模塊RSR:從輸入數(shù)據(jù)到輸出數(shù)據(jù)整個(gè)周期為 10 個(gè)時(shí)鐘周期(數(shù)據(jù)格式:起始位0+8位有效數(shù)據(jù)+停止位1)。FIFO模塊:對于發(fā)送模塊TSR的設(shè)計(jì):只要FIFO不為空(即empty=0),則在時(shí)鐘上升沿的情況下,F(xiàn)IFO則將其

16、輸出(復(fù)位清0后輸出為00)傳送給 TSR。TSR在每次輸出10位數(shù)據(jù)(輸出數(shù)據(jù)格式:8位數(shù)據(jù)開頭加上起始位0,結(jié)尾加上停止位1)前,則在判斷狀態(tài)下輸出1的同時(shí)產(chǎn)生tx_req信號請求FIFO輸出下一個(gè)數(shù)據(jù),在下一個(gè)時(shí)鐘上升沿下,若empty=0則讀指針自增指向下一個(gè)數(shù)據(jù),并且FIFO將其輸出實(shí)現(xiàn)輸出的刷新;否則,讀指針不變,并且FIFO輸出不變。對于接收模塊RSR的設(shè)計(jì):只要RSR檢驗(yàn)數(shù)據(jù)并接收完畢數(shù)據(jù)就會產(chǎn)生rx_int信號請求向FIFO中寫入數(shù)據(jù),如果full=0則在下一個(gè)時(shí)鐘上升沿下數(shù)據(jù)寫入;否則該數(shù)據(jù)相當(dāng)于被丟棄不會再寫入FIFO中,RSR再次進(jìn)入檢驗(yàn)狀態(tài),等待下一個(gè)有效數(shù)據(jù)。發(fā)送模

17、塊TSR:因?yàn)槎嗔艘粋€(gè)判斷狀態(tài)(此時(shí)TXD輸出1),再加上10位的數(shù)據(jù),所以從數(shù)據(jù)輸入到輸出整個(gè)周期為 11 個(gè)時(shí)鐘周期三、時(shí)序仿真四、耗用報(bào)告五、生成邏輯圖附:對三個(gè)模塊的設(shè)計(jì)與實(shí)現(xiàn)一、 接受模塊U1:RSR1、 程序library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;entity RSR is port(reset:in std_logic; rx:in std_logic; -串行數(shù)據(jù)接收端RXD clk:in std_logic; -時(shí)

18、鐘clk rx_data:out std_logic_vector(7 downto 0); -FIFO中的data_in rx_int:out std_logic); -FIFO中的wr_reqend entity; architecture arc of RSR issignal shifter:std_logic_vector(7 downto 0);signal bitstate:integer range 0 to 10:=0;beginprocess(clk,reset,rx) -接收進(jìn)程 begin if(reset=1) then -復(fù)位信號 -異步清0 bitstate=0;

19、 shifter=ZZZZZZZZ; elsif(rising_edge(clk) then if(bitstate=0) then -狀態(tài)0 判斷有沒有數(shù)據(jù)輸入 if(rx=0) then bitstate=bitstate+1; end if; elsif(bitstate=9) then -狀態(tài)9 數(shù)據(jù)接收完成 bitstate=0; else -其他狀態(tài)接收1-8為數(shù)據(jù),停止位不檢查 shifter(0)=rx; shifter(7 downto 1)=shifter(6 downto 0); bitstate=bitstate+1; end if; end if; end proce

20、ss;process(clk,reset) -輸出進(jìn)程begin if(reset=1) then rx_data=00000000; -異步清0 rx_int=0; elsif(rising_edge(clk) then if(bitstate=9) then rx_data=shifter; -數(shù)據(jù)輸出 rx_int=1; else rx_int=0; rx_data=ZZZZZZZZ; -不輸出時(shí)呈高阻狀態(tài) end if; end if;end process; end arc;2、 功能仿真3、 時(shí)序仿真二、 U2:FIFO1、程序library ieee;use ieee.std_l

21、ogic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all; entity FIFO is port( clock : in std_logic; reset : in std_logic; wr_req : in std_logic; rd_req : in std_logic; data_in : in std_logic_vector(7 downto 0); full : buffer std_logic; empty : buffer std_logic; data_out : out std_

22、logic_vector(7 downto 0);end FIFO;architecture arch of FIFO is type type_2d_array is array(0 to 7) of std_logic_vector(7 downto 0); signal fifo_memory : type_2d_array; signal wr_address : integer range 0 to 7; signal rd_address : integer range 0 to 7; signal offset : integer range 0 to 7; signal dat

23、a_buffer : std_logic_vector(7 downto 0);beginoffset rd_address)else (8 - (rd_address - wr_address)when (rd_address wr_address)else 0;empty = 1 when (offset = 0) else 0;full = 1 when (offset = 7) else 0; -實(shí)際7*8bit容量(full=1)process(clock,rd_req)begin if (clockevent and clock=1) then if reset = 1 then

24、rd_address = 0; data_buffer 0); elsif (rd_req = 1 and empty = 0) then -empty=1則輸出保持 data_buffer rd_address rd_address = rd_address + 1 ; end case; end if; end if;end process;data_out = data_buffer ;process(clock,wr_req)begin if (clockevent and clock=1) then -同步清0 clock時(shí)鐘 if reset = 1 then wr_address = 0; elsif (wr_req = 1 and full = 0) then -full=1而wr_req=1則丟棄數(shù)據(jù) fifo_memory(wr_address) wr_address wr_address = wr_address + 1 ; end case; end if; end if;end process;end arch;2、功能仿真3、時(shí)序仿真三、 發(fā)送模塊U3:TSR1、 程序library ieee;use ieee.std_logic_11

溫馨提示

  • 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)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論