📄 uever悠威电子网-c语言实现pid算法.htm
字号:
<DIV align=center><A
href="http://www.uever.com/technic/electronic/elecdiy.asp"></A><A
href="http://www.uever.com/software/softdown.asp"><FONT
color=#000000>软件下载</FONT></A></DIV></TD>
<TD width="1%">
<DIV align=center>|</DIV></TD>
<TD width="10%">
<DIV align=center><FONT color=#0000ff>技术资料</FONT></DIV></TD>
<TD width="1%">
<DIV align=center>|</DIV></TD>
<TD width="10%">
<DIV align=center><A
href="http://www.uever.com/mark/mark.asp"><FONT
color=#000000>刻录服务</FONT></A></DIV></TD>
<TD width="1%">
<DIV align=center>|</DIV></TD>
<TD width="10%">
<DIV align=center><A
href="http://www.uever.com/design/design.asp"><FONT
color=#000000>技术方案</FONT></A></DIV></TD>
<TD width="1%">
<DIV align=center>|</DIV></TD>
<TD width="10%">
<DIV align=center><A
href="http://www.uever.com/shop/OrderShow.asp"><FONT
color=#000000>订单查询</FONT></A></DIV></TD>
<TD width="1%">
<DIV align=center>|</DIV></TD>
<TD width="10%">
<DIV align=center><A
href="http://www.uever.com/forum/forum.asp"><FONT
color=#000000>技术论坛</FONT></A></DIV></TD>
<TD width="1%">
<DIV align=center></DIV></TD></TR></TBODY></TABLE></TD></TR>
<TR>
<TD height=3> </TD>
<TD width=389 height=3> </TD>
<TD colSpan=2 height=3> </TD></TR>
<TR>
<TD height=15>
<DIV align=left>今天是: 2007年8月4日 星期六 </DIV></TD>
<TD colSpan=3 height=15> 您现在的位置:UEVER>><A
href="http://www.uever.com/technic/technic.asp"><FONT
color=#000066>技术资料</FONT></A>>>单片机>> C语言实现PID算法
<DIV align=center></DIV></TD></TR>
<TR>
<TD height=20>
<DIV align=center>当前在线44人 </DIV></TD>
<TD> </TD>
<TD width=12> </TD>
<TD width=205> </TD></TR>
<TR>
<TD background=Uever悠威电子网-C语言实现PID算法.files/bg_dian.gif colSpan=4
height=1></TD></TR>
<TR vAlign=top align=middle>
<TD colSpan=4 height=999>
<TABLE height=1007 cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD colSpan=2> </TD>
<TD width="65%"> </TD>
<TD colSpan=3> </TD></TR>
<TR>
<TD colSpan=6 height=27>
<DIV align=center><FONT color=#ff0000
size=2><STRONG>C语言实现PID算法</STRONG></FONT></DIV></TD></TR>
<TR vAlign=center align=middle>
<TD colSpan=6> </TD></TR>
<TR vAlign=center align=middle>
<TD
colSpan=6>作者:unknow 更新时间:2006-5-7 点击数:3499</TD></TR>
<TR>
<TD height=16> </TD>
<TD colSpan=4 height=16>
<HR>
</TD>
<TD height=16> </TD></TR>
<TR>
<TD width="2%" height=25> </TD>
<TD vAlign=top align=middle colSpan=4 height=25> </TD>
<TD width="2%"> </TD></TR>
<TR>
<TD width="2%" height=26> </TD>
<TD vAlign=top align=middle colSpan=4 height=26>
<TABLE cellSpacing=0 cellPadding=0 width="93%" border=0>
<TBODY>
<TR>
<TD>关键词 PID pid算法 pid控制算法 pid程序 pid调节<BR><BR> <BR><BR>BC31 TC30 编译过,可运行。<BR> <BR> <BR> #include <STDIO.H><BR> #include<MATH.H><BR> <BR> struct _pid {<BR> int pv; /*integer that contains the process value*/<BR> int sp; /*integer that contains the set point*/<BR> float integral;<BR> float pgain;<BR> float igain;<BR> float dgain;<BR> int deadband;<BR> int last_error;<BR> };<BR> <BR> struct _pid warm,*pid;<BR> int process_point, set_point,dead_band; <BR> float p_gain, i_gain, d_gain, integral_val,new_integ;; <BR> <BR> <BR> <BR> /*------------------------------------------------------------------------ <BR> pid_init <BR> <BR> DESCRIPTION This function initializes the pointers in the _pid structure <BR> to the process variable and the setpoint. *pv and *sp are <BR> integer pointers. <BR> ------------------------------------------------------------------------*/ <BR> void pid_init(struct _pid *warm, int process_point, int set_point)<BR> { <BR> struct _pid *pid; <BR> <BR> pid = warm; <BR> pid->pv = process_point; <BR> pid->sp = set_point; <BR> } <BR> <BR> <BR> /*------------------------------------------------------------------------ <BR> pid_tune <BR> <BR> DESCRIPTION Sets the proportional gain (p_gain), integral gain (i_gain), <BR> derivitive gain (d_gain), and the dead band (dead_band) of <BR> a pid control structure _pid. <BR> ------------------------------------------------------------------------*/ <BR> <BR> void pid_tune(struct _pid *pid, float p_gain, float i_gain, float d_gain, int dead_band) <BR> { <BR> pid->pgain = p_gain; <BR> pid->igain = i_gain; <BR> pid->dgain = d_gain; <BR> pid->deadband = dead_band; <BR> pid->integral= integral_val; <BR> pid->last_error=0; <BR> } <BR> <BR> /*------------------------------------------------------------------------ <BR> pid_setinteg <BR> <BR> DESCRIPTION Set a new value for the integral term of the pid equation. <BR> This is useful for setting the initial output of the <BR> pid controller at start up. <BR> ------------------------------------------------------------------------*/ <BR> void pid_setinteg(struct _pid *pid,float new_integ)<BR> { <BR> pid->integral = new_integ; <BR> pid->last_error = 0; <BR> } <BR> <BR> /*------------------------------------------------------------------------ <BR> pid_bumpless <BR> <BR> DESCRIPTION Bumpless transfer algorithim. When suddenly changing <BR> setpoints, or when restarting the PID equation after an <BR> extended pause, the derivative of the equation can cause <BR> a bump in the controller output. This function will help <BR> smooth out that bump. The process value in *pv should <BR> be the updated just before this function is used. <BR> ------------------------------------------------------------------------*/ <BR> void pid_bumpless(struct _pid *pid) <BR> { <BR> <BR> pid->last_error = (pid->sp)-(pid->pv); <BR> <BR> } <BR> <BR> /*------------------------------------------------------------------------ <BR> pid_calc <BR> <BR> DESCRIPTION Performs PID calculations for the _pid <BR>structure *a. This function uses the positional form of the pid equation, and incorporates an integral windup <BR>prevention algorithim. Rectangular integration is used, so<BR> this function must be repeated on a consistent time basis <BR>for accurate control. <BR> <BR> RETURN VALUE The new output value for the pid loop. <BR> <BR> USAGE #include "control.h"*/ <BR> <BR> <BR> float pid_calc(struct _pid *pid)<BR> { <BR> int err;<BR> float pterm, dterm, result, ferror; <BR> <BR> err = (pid->sp) - (pid->pv); <BR> if (abs(err) > pid->deadband) <BR> { <BR> ferror = (float) err; /*do integer to float conversion only once*/ <BR> pterm = pid->pgain * ferror; <BR> if (pterm > 100 || pterm < -100)<BR> {<BR> pid->integral = 0.0; <BR> }<BR> else <BR> { <BR> pid->integral += pid->igain * ferror; <BR> if (pid->integral > 100.0) <BR> {<BR> pid->integral = 100.0; <BR> }<BR> else if (pid->integral < 0.0) pid->integral = 0.0; <BR> } <BR> dterm = ((float)(err - pid->last_error)) * pid->dgain; <BR> result = pterm + pid->integral + dterm; <BR> } <BR> else result = pid->integral; <BR> pid->last_error = err; <BR> return (result); <BR> }<BR> <BR> <BR> void main(void)<BR> {<BR> float display_value;<BR> int count=0;<BR> <BR> pid = &warm;<BR> <BR> // printf("Enter the values of Process point, Set point, P gain, I gain, D gain \n");<BR> // scanf("%d%d%f%f%f", &process_point, &set_point, &p_gain, &i_gain, &d_gain);<BR> <BR> <BR> <BR> process_point = 30;<BR> set_point = 40;<BR> p_gain = (float)(5.2);<BR> i_gain = (float)(0.77);<BR> d_gain = (float)(0.18);<BR> <BR> <BR> <BR> dead_band = 2;<BR> integral_val =(float)(0.01);<BR> <BR> <BR> printf("The values of Process point, Set point, P gain, I gain, D gain \n");<BR> printf(" %6d %6d %4f %4f %4f\n", process_point, set_point, p_gain, i_gain, d_gain);<BR> <BR> printf("Enter the values of Process point\n");<BR> <BR> while(count<=20)<BR> {<BR> <BR> <BR> <BR> scanf("%d",&process_point);<BR> <BR> pid_init(&warm, process_point, set_point);<BR> pid_tune(&warm, p_gain,i_gain,d_gain,dead_band);<BR> pid_setinteg(&warm,0.0); //pid_setinteg(&warm,30.0);<BR> <BR> //Get input value for process point<BR> pid_bumpless(&warm);<BR> <BR> // how to display output<BR> display_value = pid_calc(&warm); <BR> printf("%f\n", display_value); <BR> //printf("\n%f%f%f%f",warm.pv,warm.sp,warm.igain,warm.dgain); <BR> count++; <BR> <BR> } <BR> <BR> }<BR><BR></TD></TR></TBODY></TABLE></TD>
<TD width="2%"> </TD></TR>
<TR>
<TD colSpan=2> </TD>
<TD> </TD>
<TD colSpan=3> </TD></TR>
<TR>
<TD height=16> </TD>
<TD colSpan=4 height=16> </TD>
<TD> </TD></TR>
<TR>
<TD colSpan=2 height=18> <FONT color=#ff0000>上一篇:</FONT></TD>
<TD><A
href="http://www.uever.com/technic/technicshow.asp?artID=115"><FONT
color=#000066>单片机温度控制应用</FONT></A></TD>
<TD width="12%">
<DIV align=center></DIV></TD>
<TD width="13%">
<DIV align=center>[<A href="javascript:window.close()"><FONT
color=#000000>关闭窗口</FONT></A>]</DIV></TD>
<TD></TD></TR>
<TR>
<TD colSpan=2 height=18> <FONT color=#ff0000>下一篇:</FONT></TD>
<TD><A
href="http://www.uever.com/technic/technicshow.asp?artID=117"><FONT
color=#000066>ISD1400 系列单片永久性语音录放电路应用</FONT></A></TD>
<TD>
<DIV align=center></DIV></TD>
<TD>
<DIV align=center></DIV></TD>
<TD> </TD></TR>
<TR vAlign=top>
<TD colSpan=6 height=80>
<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
<TBODY>
<TR>
<TD vAlign=top align=middle width="33%" height=234>
<TABLE height=250 cellSpacing=1 cellPadding=0
width="98%" border=1>
<TBODY>
<TR>
<TD width="100%" bgColor=#efefef height=15>
<DIV align=center><FONT
color=#ff0000>最近浏览</FONT></DIV></TD></TR>
<TR>
<TD vAlign=top>
<DIV align=center>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD height=5></TD>
<TD height=5></TD></TR>
<TR>
<TD width="8%">
<DIV align=center><IMG height=6
src="Uever悠威电子网-C语言实现PID算法.files/dimg_10.gif"
width=6></DIV></TD>
<TD width="92%">
<DIV
style="OVERFLOW: hidden; WIDTH: 220px; TEXT-OVERFLOW: ellipsis"><NOBR><A
href="http://www.uever.com/technic/technicshow.asp?artID=180"><FONT
color=#000066>基于烟雾检测火灾自动报警系统</FONT></A></NOBR></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD height=5></TD>
<TD height=5></TD></TR>
<TR>
<TD width="8%">
<DIV align=center><IMG height=6
src="Uever悠威电子网-C语言实现PID算法.files/dimg_10.gif"
width=6></DIV></TD>
<TD width="92%">
<DIV
style="OVERFLOW: hidden; WIDTH: 220px; TEXT-OVERFLOW: ellipsis"><NOBR><A
href="http://www.uever.com/technic/technicshow.asp?artID=189"><FONT
color=#000066>奉献:AT45DB041读写程序</FONT></A></NOBR></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD height=5></TD>
<TD height=5></TD></TR>
<TR>
<TD width="8%">
<DIV align=center><IMG height=6
src="Uever悠威电子网-C语言实现PID算法.files/dimg_10.gif"
width=6></DIV></TD>
<TD width="92%">
<DIV
style="OVERFLOW: hidden; WIDTH: 220px; TEXT-OVERFLOW: ellipsis"><NOBR><A
href="http://www.uever.com/technic/technicshow.asp?artID=142"><FONT
color=#000066>单片机系统软件抗干扰方法</FONT></A></NOBR></DIV></TD></TR></TBODY></TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="100%"
border=0>
<TBODY>
<TR>
<TD height=5></TD>
<TD height=5></TD></TR>
<TR>
<TD width="8%">
<DIV align=center><IMG height=6
src="Uever悠威电子网-C语言实现PID算法.files/dimg_10.gif"
width=6></DIV></TD>
<TD width="92%">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -