|
|||||||||||
| 技術交流 | 電路欣賞 | 工控天地 | 數(shù)字廣電 | 通信技術 | 電源技術 | 測控之家 | EMC技術 | ARM技術 | EDA技術 | PCB技術 | 嵌入式系統(tǒng) 驅動編程 | 集成電路 | 器件替換 | 模擬技術 | 新手園地 | 單 片 機 | DSP技術 | MCU技術 | IC 設計 | IC 產業(yè) | CAN-bus/DeviceNe |
請教各位大蝦,在設計UART中遇到的問題。 |
| 作者:lilysll 欄目:EDA技術 |
小弟畢業(yè)設計中涉及利用CPLD設計異步串行通信控制器實現(xiàn)兩信號采集板之間的數(shù)據(jù)互傳,即兩片單片機采集8位開關量,通過并行方式與CPLD相連,利用CPLD實現(xiàn)并串轉換,串行發(fā)送出去,另一片CPLD接收后,經(jīng)過串并轉換,傳給單片機控制相應的發(fā)光二極管。 在計算機上仿真并串、串并轉換程序波形正確。在板子上試驗,單向傳輸正確。雙向互傳時就出現(xiàn)錯誤,已經(jīng)搞了很久不能解決,故求助各位。 下面把具體程序附上: 發(fā)送主程序: entity txmit is PORT ( reset : in std_logic; clk : in std_logic; wr : in std_logic; rege1:in std_logic_vector(7 downto 0); txd : out std_logic; int1 : out std_logic); end txmit; architecture Behavioral of txmit is signal count:std_logic_vector(3 downto 0); signal send:std_logic; signal par: std_logic_vector( 7 downto 0); begin PROCESS(reset,wr,count) --內部輸入控制信號 begin if reset='1'or count="1011"then send<='1'; elsif wr'event and wr='0'then send<='0'; end if; end PROCESS; PROCESS(clk,reset,send) --發(fā)送計數(shù)器 begin if send='1'or reset='1'then count<="0000"; elsif clk'event and clk='1'then count<=count+"0001"; end if; end PROCESS; PROCESS(reset,clk,count,rege1) --發(fā)送移位寄存器發(fā)送過程 begin if reset='1'then txd<='1'; int1<='0'; elsif clk'event and clk='1'then if count="0001" then par<=rege1; txd<='0'; int1<='1'; elsif count>="0010" and count<="1001" then par<=par(6 downto 0)&'0'; txd<=par(7); int1<='1'; elsif count="1010" then int1<='1'; txd<='1'; else int1<='0'; txd<='1'; end if; end if; end PROCESS; end Behavioral; 發(fā)送地址譯碼程序: entity add_in is PORT (cs:in std_logic; a:in std_logic; wr:in std_logic; data:in std_Logic_vector(7 downto 0); rege1:out std_logic_vector(7 downto 0)); end add_in; architecture Behavioral of add_in is begin PROCESS(cs,a,data,wr) begin if cs='0'and a='0'then if wr'event and wr='1'then rege1<=data; end if; end if; end PROCESS; end Behavioral; 接收主程序: entity rece_search8 is PORT (reset:in std_logic; clk8:in std_Logic; rxd:in std_logic; rd:in std_logic; int2:out std_logic; rege2:out std_logic_vector(7 downto 0)); end rece_search8; architecture Behavioral of rece_search8 is signal start:std_logic; signal int:std_logic; signal hold:std_logic; signal data1:std_logic; signal sink:std_logic; signal par:std_logic_vector(8 downto 0); signal mm:std_logic_vector(2 downto 0); begin PROCESS(reset,rxd,sink,start) --尋找起始位 begin if reset='1'or sink='0'or start='0'then hold<='0'; elsif rxd'event and rxd='0'then hold<='1'; end if; end PROCESS; PROCESS(reset,clk8,hold,sink) --驗證起始位 variable i:integer range 0 to 4:=0; variable star:std_logic_vector(3 downto 0); begin if reset='1'or hold='0'then if sink='0'then data1<='1'; else data1<='0'; end if; elsif clk8'event and clk8='1'then if i=4 then i:=0; if star(3 downto 0)="0000"then data1<='1'; else data1<='0'; end if; else star(i):=rxd; i:=i+1; end if; end if; end PROCESS; PROCESS(sink,start) begin if start='1'then int2<='1'; elsif sink='1'then int2<='0'; else int2<='1'; end if; end PROCESS; PROCESS(reset,clk8,data1) --寫入移位寄存器 variable a:integer range 0 to 76:=0; begin if reset='1'or data1='0'then par(8 downto 0)<="000000000"; a:=0; int<='0'; elsif clk8'event and clk8='1'then if a=76 then a:=0; int<='0'; elsif a=75 then sink<='1'; a:=a+1; int<='1'; else a:=a+1; int<='1';   |
| 2樓: | >>參與討論 |
| 作者: sunhuaiyi 于 2005/1/15 20:17:00 發(fā)布:
異步通信可以參考一下現(xiàn)成的程序 你的程序太長了,沒仔細看,不過如果是異步通信,首先應該考慮怎樣同步接收過來的數(shù)據(jù),其次,如果用一個時鐘周期去采樣,數(shù)據(jù)出現(xiàn)錯誤是很正常的,因為兩塊cpld板子上的時鐘不是同步的。 根據(jù)奈奎斯特采樣定理,在一個周期內至少采樣兩次才能夠得到正確的數(shù)據(jù)。 一般的,在單片機里面做異步通信,都有一個波特率系數(shù)設置,有16和32的,也就是數(shù)據(jù)的位寬是采樣時鐘周期的16倍或32倍,才能夠保證異步通信數(shù)據(jù)的可靠性! |
|
|
|
| 免費注冊為維庫電子開發(fā)網(wǎng)會員,參與電子工程師社區(qū)討論,點此進入 |
Copyright © 1998-2006 m.58mhw.cn 浙ICP證030469號 |