【正文】
她 的指導(dǎo) 不僅使我拓寬了 知識(shí)面,更使我在發(fā)現(xiàn)問題、分析問題、解決問題等各方面的能力都有一個(gè)明顯的提高。 軟件延時(shí)10ms消抖CPL 有鍵按下(=0)?有鍵按下(=0)?入口出口YYNN 圖 412 鍵盤程序流程圖 XX 大學(xué)本科生畢業(yè)設(shè)計(jì) 基于 FPGA 和 MCU 的相位測(cè)量?jī)x的設(shè)計(jì) 29 5 系統(tǒng)設(shè)計(jì)總結(jié) 本設(shè)計(jì)是利用 FPGA 和 MCU 相結(jié)合的方案來實(shí)現(xiàn)相位測(cè)量?jī)x的設(shè)計(jì),其中 MCU完成的是系統(tǒng)功能,而用 FPGA 來實(shí)現(xiàn)系統(tǒng)的指標(biāo)。讀入哪一種數(shù)據(jù)由兩者之間的握手信號(hào) fen 和 dsel 控制,其程序流程圖如圖 48 所示。 reg out。 else out_data=in_data。 else out=out+1。end else begin q=d。 2. 利用 D觸發(fā)器的特點(diǎn)進(jìn)行信號(hào)的超前 /滯后檢測(cè)。 FPGA 的 Verilog HDL 程序設(shè)計(jì) FPGA 主要完成對(duì)數(shù)據(jù)的采集,它可以準(zhǔn)確的采集到兩個(gè)同頻正弦信號(hào)的相位差所對(duì)應(yīng)的時(shí)間差以及信號(hào)的周期 。 該顯示電路由 8 個(gè)共陰極 7 段 LED 數(shù)碼管和 8 片串入 /并出的 74LS164 芯片組成。 P3 口 : 10~ 17 腳為 ~ 輸入 /輸出引腳。作為通用 I/O 口時(shí),需要外接上拉電阻,輸出數(shù)據(jù)可以得到鎖存,最為輸出口,每個(gè)引腳可以驅(qū)動(dòng) 8個(gè) TTL 負(fù)載。即可上電復(fù)位,又可 按鍵復(fù)位,一般 R1 選 470Ω , R2選 ,C 選 22μ F[1]。 該模塊使用的單片機(jī)型號(hào)為 AT89C51,它是美國 Atmel 公司生產(chǎn)的 8位單 片機(jī)。 FPGA 與單片機(jī)的連接框圖如圖 32所示。這兩種電路都含有鎖相環(huán)( PLL),時(shí)鐘鎖定電路為一個(gè)同步的 PLL, 可以減小器件內(nèi)的時(shí)鐘延遲和偏移。 XX 大學(xué)本科生畢業(yè)設(shè)計(jì) 基于 FPGA 和 MCU 的相位測(cè)量?jī)x的設(shè)計(jì) 14 1 2 3 4 5 6ABCD654321DCBAT i t l eN um be r R e v i s i onS i z eBD a t e : 1 J un 20 1 1 S he e t of F i l e : D : \ P R O T E L _9 9 _S E _C N \ E X A M P L E S \M yD e s i gn .dd bD r a w n B y :U I AL M 33 9L M 33 9R110 K ΩR910 K ΩR310 K ΩR410 0 ΩR510 K Ω123J4C O N 3A I N SGNDB I N SR651 0 ΩR710 0 ΩR251 0 ΩR810 K ΩU I BGNDGNDGNDGND+ 5V+ 5V+ 5V+ 5VB I NA I N 圖 31 由施密特觸發(fā)器構(gòu)成的整形電路 由上圖分析計(jì)算有: VURRR RUU KPN 04 4 ????? ( 31) 則其閥值電壓 VUVU TT 0 4 7 ,0 4 7 ??? ?? 。由于有干擾信號(hào),導(dǎo)致單門限電壓比較器在輸入信號(hào)過零點(diǎn)時(shí)會(huì)產(chǎn)生多次觸發(fā)翻轉(zhuǎn)的現(xiàn)象,這樣就會(huì)導(dǎo)致 FPGA 采集數(shù)據(jù)(計(jì)數(shù))不準(zhǔn)確,從而使單片機(jī)無法計(jì)算出正確的被測(cè)信號(hào)的頻率和相位差的數(shù)值。將數(shù)據(jù)采集交 FPGA 完成,可以準(zhǔn)確的采集到兩個(gè)同頻正弦信號(hào)的相位差所對(duì)應(yīng)的時(shí)間差以及信號(hào)的周期,從而提高了系統(tǒng)的可靠性。這不滿足 相位測(cè)量絕對(duì)誤差≤ 2176。而且在同一個(gè)單片機(jī)應(yīng)用程序中實(shí)現(xiàn)頻率和相位差的測(cè)量,程序設(shè)計(jì)也相當(dāng)復(fù)雜。這樣一來, FPGA 和 MCU 之間要有握手信號(hào),因此設(shè)置兩個(gè)握手信號(hào) DSEL、 FEN。 對(duì)頻率的測(cè)量采用測(cè)周期的方法,即在信號(hào)周期 T 時(shí)間內(nèi),對(duì)時(shí)標(biāo)信號(hào)進(jìn)行計(jì)數(shù)。 因?yàn)榈?1次測(cè)量時(shí)間差和周期的起始時(shí)刻有一定的隨機(jī)性,這是由于軟件啟動(dòng)定時(shí)器 /計(jì)數(shù)器 0T 、 1T 的時(shí)刻是隨機(jī)的,因此定時(shí)器 /計(jì)數(shù)器 0T 、 1T 第 1次測(cè)得的時(shí)間差和周期是不準(zhǔn)確的,所以舍棄不要 。 GATE TC/ 1M 0M GATE TC/ 1M 0M XX 大學(xué)本科生畢業(yè)設(shè)計(jì) 基于 FPGA 和 MCU 的相位測(cè)量?jī)x的設(shè)計(jì) 7 待 測(cè) 信 號(hào) 1整 形 電 路整 形 電 路二 分 頻= 1 M C U 5 1_ _ _ _ I N T 0 ( P 3 . 2 ) P 3 . 6_ _ _ _ I N T 1 ( P 3 . 3 )≥ 1﹠待 測(cè) 信 號(hào) 2圖 23 MCU 測(cè)量 時(shí)間差和周期的電路圖 需要說明的是,本系統(tǒng)要由軟件創(chuàng)建一個(gè)標(biāo)志位 ,當(dāng)輸入引腳 =0時(shí), CPU 置位標(biāo)志位 ,而當(dāng) =1 時(shí), CPU 在讀取時(shí)間差數(shù)據(jù)后清零標(biāo)志位 。 MCS51 系列 單 片機(jī)芯片內(nèi)部集成了兩個(gè) 16 位的硬件定時(shí)器 /計(jì)數(shù)器, 他們XX 大學(xué)本科生畢業(yè)設(shè)計(jì) 基于 FPGA 和 MCU 的相位測(cè)量?jī)x的設(shè)計(jì) 6 是 0T 、 1T ,均是二進(jìn)制加法計(jì)數(shù)器,當(dāng)計(jì)數(shù)器計(jì)滿回零時(shí)能自動(dòng)產(chǎn)生溢出中斷請(qǐng)求,表示定時(shí)時(shí)間已到或計(jì)數(shù)已終止。因此,人們?cè)谶M(jìn)行電子系統(tǒng)設(shè)計(jì)的時(shí)候,用MCU 實(shí)現(xiàn)系統(tǒng)功能, FPGA 完成 系統(tǒng)指標(biāo)。相位測(cè)量?jī)x有兩路輸入信號(hào),也就是被測(cè)信號(hào),它們是兩個(gè)同頻率的正弦信號(hào),頻率范圍 為 20HZ— 20KHZ(正好是音頻范圍),而這兩個(gè)被測(cè)信號(hào)的幅度分別為Upp=1V— 5V(可以擴(kuò)展到 — 5V),但兩者幅度不一定相等。 而且可以很好地完成 該設(shè)計(jì)所要求的各項(xiàng)指標(biāo)。近年來,隨著計(jì)算機(jī)軟硬件及其外圍設(shè)備的日益發(fā)展,以數(shù)字信號(hào)處理為核心的軟件法測(cè)量技術(shù)在相位差的測(cè)量中得到了越來越多的關(guān)注,并取得了較快的發(fā)展。相位測(cè)量?jī)x可應(yīng)用于變壓器件生產(chǎn)廠,收錄機(jī),電視機(jī),整機(jī)生產(chǎn)廠或有關(guān)科研單位,作為產(chǎn)品驗(yàn)收,檢驗(yàn),樣品分析的測(cè)試儀器,是提高產(chǎn)品質(zhì)量和工作效率的最佳輔助工具。 關(guān)鍵詞 : 數(shù)字式 相位測(cè)量?jī)x 單片機(jī) FPGA 設(shè)計(jì)方案 II Abstract Along with the social and historical progress, phase measurement technology is widely used in national defense, scientific research, production and other fields, on the phase measurement requirements are also gradually to high precision, high intelligent direction, in the range of low frequency digital phase measurement instrument, because of its high precision measurement resolution and highly intelligent, intuitive characteristics have been more and more widely applied. This text first discusses the phase measuring technology development in domestic and international, and according to the present situation designs the phase measuring system. The design includes system design theory analysis, system structure design and hardware realization, finally verified the feasibility and validity of the system. The bination of MCU and FPGA is adopted in the design .It has the features of FPGA high operating speed, abundant resources and convenient programming. And the use of MCU’s strong operation and control function, which makes the whole system modularized, the hardware circuit is simple and the operation is convenient. The paper mainly introduces the designs of the demonstration, hardware and software, the hardware circuits and main software program are given in detail. III Keywords: Digital phase measuring instrument MCU FPGA Design strategy IV 目 錄 摘 要 ................................................ I Abstract ............................................. II 1 緒 論 ............................................. 1 課題背景及研究意義 ........................................... 1 國內(nèi)外發(fā)展動(dòng)態(tài) ............................................... 1 課題設(shè)計(jì)任務(wù) ................................................. 3 2 設(shè)計(jì)方案論證 ....................................... 4 以 MCU 為核心的實(shí)現(xiàn)方案 ....................................... 4 以 MCU 和 FPGA 相結(jié)合的實(shí)現(xiàn)方案 ................................ 8 兩個(gè)設(shè)計(jì)方案的比較 .......................................... 11 3 系統(tǒng)硬件設(shè)計(jì) ...................................... 13 輸入模塊設(shè)計(jì) ................................................ 13 基于 FPGA 的數(shù)據(jù)采集模塊設(shè)計(jì) ................................. 14 基于 MCU 的數(shù)據(jù)處理模塊設(shè)計(jì) .................................. 16 顯示模塊設(shè)計(jì) ................................................ 20 4 系統(tǒng)軟件設(shè)計(jì) ...................................... 20 FPGA 的 Verilog HDL 程序設(shè)計(jì) .................................. 20 MCU 的匯編語言程序設(shè)計(jì) ....................................... 24 5 系統(tǒng)設(shè)計(jì)總結(jié) ...................................... 29 致 謝 .............................................. 30 [參考文獻(xiàn) ] ........................................... 31 V 附錄 1 ............................................... 32 附錄 2 ........................................