【正文】
pid_bumpless DESCRIPTION Bumpless transfer algorithim. When suddenly changing setpoints, or when restarting the PID equation after an extended pause, the derivative of the equation can cause a bump in the controller output. This function will help smooth out that bump. The process value in *pv should be the updated just before this function is used. */ void pid_bumpless(struct _pid *pid) { pidlast_error = (pidsp)(pidpv)。 } /* pid_calc DESCRIPTION Performs PID calculations for the _pid structure *a. This function uses the positional form of the pid equation, and incorporates an integral windup prevention algorithim. Rectangular integration is used, so this function must be repeated on a consistent time basis for accurate control. RETURN VALUE The new output value for the pid loop. USAGE include */ float pid_calc(struct _pid *pid) { int err?! ?float pterm, dterm, result, ferror。 err = (pidsp) (pidpv)。 if (abs(err) piddeadband) { ferror = (float) err。 /*do integer to float conversion only once*/ pterm = pidpgain * ferror。 if (pterm 100 || pterm 100) { pidintegral = 。 } else { pidintegral += pidigain * ferror。 if (pidintegral ) { pidintegral = 。 } else if (pidintegral ) pidintegral = 。 } dterm = ((float)(err pidlast_error)) * piddgain。 result = pterm + pidintegral + dterm。 } else result = pidintegral。 pidlast_error = err。 return (result)。 } void main(void) { float display_value。 int count=0。 pid = amp。warm?! ?/ printf(Enter the values of Process point, Set point, P gain, I gain, D gain \n)。 // scanf(%d%d%f%f%f, amp。process_point, amp。set_point, amp。p_gain, amp。i_gain, amp。d_gain)?! ?process_point = 30?! ?set_point = 40?! ?p_gain = (float)()?! ?i_gain = (float)()。d_gain = (float)()?! ?dead_band = 2?! ?integral_val =(float)()。 printf(The values of Process point, Set point, P gain, I gain, D gain \n)?! ?printf( %6d %6d %4f %4f %4f\n, process_point, set_point, p_gain, i_gain, d_gain)。 printf(Enter the values of Process point\n)?! ?while(count=20) { Scanf(%d,amp。process_point)。 pid_init(amp。warm, process_point, set_point)?! ?pid_tune(amp。warm, p_gain,i_gain,d_gain,dead_band)。 pid_setinteg(amp。warm,)。 //pid_setinteg(amp。warm,)?! ?//Get input value for process point pid_bumpless(amp。warm)。 // how to display output display_value = pid_calc(amp。warm)。 printf(%f\n, display_value)。 //printf(\n%f%f%f%f,)。 count++。 } }參考文獻(xiàn):[1] 何立民:MCS51系列單片機(jī)應(yīng)用系統(tǒng)設(shè)計(jì),北京航空航天大學(xué)出版社,1990,P122 P130[2] 秦進(jìn)平、官英雙:基于單片機(jī)的恒壓供水系統(tǒng),黑龍江工程學(xué)院學(xué)報(bào),2005,P103P112[3] 解宏基、任 光:一種多功能變頻恒壓供水單片機(jī)供水控制系統(tǒng),大連海事大學(xué)輪機(jī)工程研究所,P258P262[4] 周黎輝、馮正進(jìn):變頻器在多泵并聯(lián)調(diào)速系統(tǒng)中的應(yīng)用,機(jī)電一體化,1999,P35P40[5] 王幸之、鐘愛琴:AT89系列單片機(jī)原理及接口技術(shù),北京航空航天大學(xué)出版社,2004,P76P94[6] 蘇 夯:控制恒壓供水系統(tǒng)的設(shè)計(jì),大連交通大學(xué),2009,P76P80[7] 童 占:新概念51單片機(jī)C語言教程,電子工業(yè)出版社,2003,P275P284[8] 馬忠梅、籍順心、張 凱:?jiǎn)纹瑱C(jī)的C語言應(yīng)用程序設(shè)計(jì),北京航空航天大學(xué)出版社,2003,P241P249[9] 南建輝、熊 鳴、王軍茹:MCS51單片機(jī)原理及應(yīng)用實(shí)例,清華大學(xué)出版社,2003,P286P2