【正文】
the Proportional, the Integral and Derivative values. The Proportional value determines the reaction to the current error, the Integral determines the reaction based on the sum of recent errors and the Derivative determines the reaction to the rate at which the error has been changing. The weighted sum of these three actions is used to adjust the process via a control element such as the position of a control valve or the power supply of a heating element. By tuning the three constants in the PID controller algorithm the PID can provide control action designed for specific process requirements. The response of the controller can be described in terms of the responsiveness of the controller to an error, the degree to which the controller overshoots the setpoint and the degree of system oscillation. Note that the use of the PID algorithm for control does not guarantee optimal control of the system or system stability. Some applications may require using only one or two modes to provide the controle ppropriate system control. This is achieved by setting the gain of undesired control outputs to zero. A PID controller will be called a PI, PD, P or I controller in the absence of the respective control actions. PI controllers are particularly mon, since derivative action is very sensitive to measurement noise, and the absence of an integral value may prevent the system from reaching its target value due to the control action. 2 A block diagram of a PID controller Note: Due to the diversity of the field of control theory and application, many naming conventions for the relevant variables are in mon use. Control loop basics A familiar example of a control loop is the action taken to keep one39。在此謹向耿老師致以誠摯的謝意! 在畢 業(yè) 設(shè) 計 的進行過程中,劉 同學(xué) 、余 同學(xué) 、高 同學(xué) 給了我大量的幫助和支持,在此同樣 表示深切的謝意! 另外,院領(lǐng)導(dǎo)和老師也給了我們必要的指導(dǎo),為我們畢設(shè)的完成提供了很大的幫助。在整個研究學(xué)習(xí)階段,耿老師不斷向我們傳授分析問題和解 決問題的辦法,并指出了正確的努力方向,使我在畢設(shè)完成過程中少走了很多彎路。 chn_disp(3,0,TD_data)。 chn_disp(1,0,KP_data)。 TD_data[14]=TD%10+0x30。 TD_data[11]=TD/100+0x30。 TI_data[12]=(TI/10)%10+0x30。 33 KP_data[14]=KP%10+0x30。 KP_data[11]=KP/100+0x30。0X04)==0)。 SEI()。 clrram()。 if(key==4) { key=0。 OCR0= 0x00。0X04)==0) { CLI()。 if(key!=0) shuju()。 if(key==2) 32 TI。 shedin[10]=set%10+0x30。 shedin[8]=set/100+0x30。 if((PINCamp。 } } if((PINCamp。 if(key==3) TD++。 } if(key==1) KP++。 shedin[9]=(set/10)%10+0x30。0X02)==0) { if(key==0) { set++。0X02)==0) { delay_ms(60)。 ADCSRA|=(1ADSC)。 //轉(zhuǎn)換數(shù)值 return V。 //讀取值 V=(ADCH8)+V。 unsigned int V=0。 //禁止模擬比較器 ADCSRA= 0xCE。 30 SFIOR |= 0x00。 //輸出給寄存器 ,改變 PWM占空比 } void adc_init(void) //AD初始化 { ADCSRA= 0x00。 //輸出值限幅 if(PWM_out Pmin)PWM_out = Pmin。 //調(diào)整值限幅,防止積分飽和 } PWM_out=PWM_out+pwm_var。 //強制轉(zhuǎn)化調(diào)整量 ,PWM為整數(shù) if(pwm_var = Umax)pwm_var = Umax。 Ei = Ek。 } else { Uo = Kpp*Ek + Ki*Ei + Kd*Ed。 Dennis C Program— ming Language, 1997, P387 28 [20] Sha zhanyou, Guochen, Sui Design of Multiple Channel Dustlike Object Temperature Measure and Control Syetem, MCGM’2022 , ISTP [21] Boait Peter, Co ntroling embedded generators using SMS, IEE Power Engineer, 2022, Volumel7, P3133 29 附錄 1:程序 ////// PID運算 /////// void pid_ctrl(void) { Ek = ref feb。 本設(shè)計的實質(zhì)是 基于工業(yè)過程物理模擬對象, 參考 自動化儀表技術(shù)、 傳感器技術(shù) 、 計算機技術(shù)、通信技術(shù)、自動控制技術(shù) 等 , 涉及 流量、 液位、壓力等熱工參數(shù) 來運用自動控制理論,利用單片機及其接口技術(shù)及 C語言等實習(xí)工業(yè)模擬控制。 本系統(tǒng)采用工程整定的方法,由于現(xiàn)場整定經(jīng)驗不足,調(diào)節(jié)的效果不太理想。這種方法所得到的計算數(shù)據(jù) 不一定可以直接 用,還必須通過工程實際進行調(diào)整和修改。 PID控制器參數(shù)整定的方法很多,概括起來有兩大類:一是理論計算整定法。 26 總 結(jié) 本設(shè)計以 ATmega16L單片機為 控制 核心,利用其強大的處理能力和豐富的外圍接口,合理選用了超聲波 傳感器, 電機驅(qū)動電路 ,以及 12864液晶 LCD顯示,較好的完成了 液位調(diào)節(jié)系統(tǒng)的液位 采集 電路、 液位處理 電路、液位顯示電路、報警電路等功能模塊,進而完成了 PID液位調(diào)節(jié)器 的 設(shè)計。 其次是按鍵部分,通過按下按鍵看顯示屏幕是否顯示相關(guān)內(nèi)容,如果出現(xiàn)問題,需要查看程序是否是設(shè)置的問題。 在 ICCAVR編譯環(huán)境下,將程序通過 ISP下載線下載到到單片機中。 本設(shè)計中鍵盤的按鍵直接與單片機相連,包括按鍵查詢、鍵功能程序轉(zhuǎn)移,作用是 切換 液晶顯示 界面,設(shè)定 或 更改 控制 參數(shù)。 液位顯示子程序結(jié)構(gòu)設(shè)計 本設(shè)計采用 的是 液晶 12864來顯示相關(guān)參數(shù) ,其流程圖如圖 43所示 圖 43 液晶顯示流程圖 液位設(shè)定 子程序結(jié)構(gòu)設(shè)計 鍵盤掃描程序的作用是讀得用戶自行設(shè)定的液位值,即取得預(yù)設(shè)液位值。首先選一個 PD口 的一個通道 ,讀入的電壓值是與液位具有線性關(guān)系的數(shù)據(jù),該值送入 該 口,經(jīng)線性運算后得出液位數(shù)據(jù),延時后, A/D轉(zhuǎn)換子程序結(jié)束 。 主程序 軟件流程圖如圖 42所示 23 圖 42 主程序流程圖 本系統(tǒng)各功能模塊子程序 主要 包括: A/D轉(zhuǎn)換子程序、液位顯示子程序、液位 處理子程序以及液位設(shè)定 子程序。 顯示程序:向 LCD送數(shù) 據(jù) 顯示,控制系統(tǒng)的顯示部分。 各 主要 模塊功能如下: :讀取 ADC送入單片機的 模擬量電壓信號,并換算為相對應(yīng)的液位 信號。 各功能模塊子程序的 設(shè)計 本設(shè)計在軟件方面采用了模塊化的設(shè)計思想, 主程序主要調(diào)用了 4個 子程序,分別是 A/D轉(zhuǎn)換程序、液位處理 程序、液位顯示程序、液位 設(shè)定 程序。啟動電機后就進行液面探測。增量型算 法只需知道連續(xù)三個采樣值的偏差值就能計算增量輸出。 模擬 PID調(diào)節(jié)器,其控制規(guī)律如公式 41所示 )(tu? = KP [e(t)+Ti1 )()(0 tdtet? +TD dttde)( ] ( 41) 式中, KP為比例系數(shù), TI為積分時間常數(shù), TD為微分時間常數(shù)。利用增量型算法其算法簡單,使用的數(shù)據(jù)少,只要采集連續(xù)三次的數(shù)據(jù)偏差,就可以算出輸出計算 e(n) 計算 a0 e(n) 計算 a1e(n1) 計算 a0 e(n)+a1 e(n1) 計算 a2 e(n1) 計算 ? u(n) 更新 e(n1),e(n2) 開始 返回 22 量,再結(jié)合位置型算法使輸出值等于上次的輸出值加上這次采樣的偏差值。但是,這種控制也有不足之處: 積分截斷效應(yīng)大,有靜態(tài)誤差;溢出的影響大。而增量設(shè)計只與本次的偏差 值有關(guān),與閥門原來的位置無關(guān),因而增量算法易于實現(xiàn)手動 /自動無擾動切換; ( 3) 不產(chǎn)生積分失控,所以容易獲得較好的調(diào)節(jié)效果。 本系統(tǒng)的 PID程序采用的是增量型算法 如圖 41所示 。把變送器送來的信號與給定值進行比較,得到偏差信號,并以預(yù)先設(shè)定的參數(shù) (比例系數(shù)、積分時間 )進行運算。由此可見,控制器在控制系統(tǒng)中起著非常重要的作用,是整個控制系統(tǒng)的核心和靈魂。 在一個控制系統(tǒng)中至少由被控對象、測量變送器、控制器及執(zhí)行器等部分組成。軟件的主要任務(wù) 是完成芯片的初始化等工作,如數(shù)據(jù)采集、處理、顯示,延時、中斷 等。其中, ICCAVR因支持標準 C語言對 AVR系列單片機的編程而得到了廣泛 的應(yīng)用。主電源電路圖如 圖 36所示 圖 36 電源設(shè)計電路 20 4 系統(tǒng) 的軟件設(shè)計 本設(shè)計 軟件所 要 實現(xiàn)的功能 :實時控制 小水泵( 電機 ); 實時檢測是否超出上下限 ; 實時顯示檢測的數(shù)據(jù)、時間、上下限數(shù)值 ; 實時監(jiān)控鍵盤輸入 ; 報警控制 。 其 具體電路圖如圖 35所示: 19