【正文】
基于 16位單片機 MC9S12 的直流電機閉環(huán)控制系統(tǒng) 的研究 摘 要 本論文 以 飛思卡爾 16 位 單片機 MC9S12DG128B 為平臺 ,設(shè)計直流電機速度閉環(huán)伺服系統(tǒng),實現(xiàn)速度閉環(huán)和位置閉環(huán)。為了減小開發(fā)難度和增加軟件的可移植性,程序采用 C 語言編寫。 通過和伺服電機軸同軸轉(zhuǎn)動的編碼器輸出脈沖信號到 16 位單片機的計數(shù)器口,從而可以測出電機的實際轉(zhuǎn)速,然后應(yīng)用增量式數(shù)字 PID調(diào)節(jié)轉(zhuǎn)速,通過調(diào)節(jié) PID參數(shù),可以使電機按照設(shè)定的轉(zhuǎn)速運行,而不受負(fù)載大小的影響。 在一些高精密的設(shè)備中,通常要求電機以設(shè)定的速度轉(zhuǎn)動一個精確的角度,即電機不僅要實現(xiàn)速度上的閉環(huán),而且實現(xiàn)位置上的閉環(huán)。通過對編碼器的脈沖進(jìn)行累加計數(shù)是目前實現(xiàn)位置閉環(huán)控制的一種方法。假設(shè)電機需要正向轉(zhuǎn)動一個特定的角度,那么負(fù)責(zé)電機控制的相應(yīng)控制器把這個角度指令轉(zhuǎn)換成對應(yīng)的編碼器脈沖數(shù),并根據(jù)方向指令確定電 機的旋轉(zhuǎn)方向,電機開始轉(zhuǎn)動時,單片機的內(nèi)部計數(shù)器開始計數(shù),并進(jìn)行相應(yīng)的轉(zhuǎn)速調(diào)節(jié),通過相應(yīng)的位置閉環(huán)算法,可以使電機精確地停在設(shè)定的位置。實驗表明 ,該系統(tǒng)可以實現(xiàn)較好的位置閉環(huán)和速度閉環(huán)性能。 關(guān)鍵詞 : 直流電機 ; 閉環(huán)控制 ; MC9S12 ; 光電編碼器 ; PID ABSTRACT This thesis designs a Servomotor Control System based on Freescale 16bit mircocontroler MC9S12DG128, in order to carry out close loop control both in speed and position. The programmes are written by C Language to make the development easy and enhance the programe transplantablity. The photoelectric encoder which is coaxial with the servomotor generates the pulse signal and counter port of The MCU is in charge of counting these pulse, therefore the MCU can calculate the realtime speed of the motor. By using the increment digital PID arithmetic,the MCU can control the motor runs as the preset speed,regardless the amount of load driven by the motor. In some highprecision equipment, the DC motors are requested to turn a certain angle in the preset speed .In other words, the motor is close loop control not only in speed but also in positon. Accumulating the pulse from photoelectricity coder is a mon way to carry out close loop in position. Suppose an equipment needs a motor turn a certain angle, then the MCU which is in charge of controlling the motor will translate this angle to the corresponding number of photoelectric encoder onchip pulses counter will start to accumulate the photoelectric encoder pulse ,though correspongding position close looparithmetic the motor will stop in the preset related experiments shows the system has good performance both in close loop control in speed and positon. Keywords: Servomotor ; Close loop control ; MC9S12 ; Photoelectric encoder; PID 目 錄 1 緒論 ................................................................ 1 直流閉環(huán)伺服技術(shù)的廣泛應(yīng)用 ................................. 1 國內(nèi)情況 .................................................... 1 國外情況 .................................................... 2 課題的提出與研究現(xiàn)狀 ............................................ 3 本文所作的工作 .................................................. 4 2 系統(tǒng)總體結(jié)構(gòu)及設(shè)計方案 .............................................. 5 直流伺服電機簡介 ................................................ 5 伺服電機的優(yōu)點 .............................................. 5 使用伺服電機事應(yīng)注意的問題 .................................. 5 本論文選用的伺服電機簡介 .................................... 6 直流伺服電機驅(qū)動電路 ............................................ 6 伺服電機系統(tǒng)常用控制芯片( MCU) ................................. 7 51 系列 8位單片機 ............................................ 7 飛思卡爾( Freescale) 16 位單片機 ............................. 8 數(shù)字信號處理器( DSP) ....................................... 9 本論文采用的控制芯片選型 .................................... 9 數(shù)字 PID 簡介 ................................................... 10 PID 控制原理 ................................................ 10 數(shù)字 PID 控制算法選擇 ....................................... 10 3 系統(tǒng)硬件設(shè)計與實現(xiàn) ................................................. 14 直流伺服電機驅(qū)動電路的實現(xiàn) ..................................... 14 IR2110 驅(qū)動電路概述 ......................................... 14 驅(qū)動電路芯 IR2110 簡介 ...................................... 14 驅(qū)動電路輸入波形的產(chǎn)生 ..................................... 16 數(shù)碼管顯示模塊的實現(xiàn) ........................................... 17 利用光電編碼器的兩路輸出信號 A、 B判斷電機旋轉(zhuǎn)方向 .............. 18 4 系統(tǒng)軟件設(shè)計與實現(xiàn) ................................................. 21 飛思卡爾( Freescale) 16 位單片機 MC9S12DG128 的應(yīng)用過程 .......... 21 計數(shù)器功能 ................................................. 21 中斷功能 ................................................... 22 PWM 輸出 功能 ................................................ 24 數(shù)字 PID的軟件實現(xiàn) ............................................... 26 測速子程序 SPEED()的編寫 ...................................... 26 PID 調(diào)節(jié)量計算子程序的實現(xiàn) .................................. 27 5 系統(tǒng)調(diào)試及參數(shù)選擇 ................................................. 29 系統(tǒng)調(diào)試總體介紹 ............................................... 29 飛思卡爾 16 位單片機 MC9S12 程序開發(fā)調(diào)試環(huán)境 ..................... 29 速度閉環(huán)調(diào)試 ................................................... 30 速度閉環(huán)調(diào)試概述 ........................................... 30 采樣周期的選擇 ............................................. 30 PID 參數(shù)整定 ................................................ 31 伺服電機轉(zhuǎn)速特性 ........................................... 32 伺服電機驅(qū)動器兩端的電壓變化曲線 ........................... 34 位置閉環(huán)調(diào)試 ................................................... 35 6 結(jié)論與展望 ......................................................... 37 結(jié)論 ........................................................... 37 展望與感想 ..................................................... 37 致 謝 ................................................................ 40 參考文獻(xiàn) .............................................................. 41 附錄 1 主要程序 ...................................................... 43 附錄 2 驅(qū)動電路原理圖 ................................................ 49 附錄 3 接口顯示板系統(tǒng)原理圖 .......................................... 51 附錄 4 飛思卡爾 MC9S12DG128B 單片機控制系統(tǒng)原理圖 ..................... 52 1 緒論 直流閉環(huán)伺服技術(shù)的廣泛應(yīng)用 電動機的控制可以分為簡單控制和復(fù)雜控制兩種。簡單控制是指電動機進(jìn)行啟動、制動、正反轉(zhuǎn)控制和順序控制。這類控制可通過繼電器、可編程控制器和開關(guān)元件來實現(xiàn)。復(fù) 雜控制是對電動機的轉(zhuǎn)速、轉(zhuǎn)角、轉(zhuǎn)矩、電壓、電流等物理量進(jìn)行控制, 而且有時往往需要非常精確的控制。以前,對電動機的簡單控 制應(yīng)用較多。但隨著現(xiàn)代化步伐的邁進(jìn),人們對自動化的需求越來越高,使電動機的復(fù)雜控制逐漸成為主流, 其在軍事、航天、工業(yè)自動化和日常家電中均有廣泛的應(yīng)用。所以開發(fā)改進(jìn)直流電機的閉環(huán)控制有著廣泛的應(yīng)用和深刻的意義 。 [1] 電動機的數(shù)字控制是電動機控制的發(fā)展趨勢,用單片機對電動機 進(jìn)行控制 是實現(xiàn)電動機數(shù)字控制