⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pid_8c.html

📁 离散 PID 控制 设计方法 ATMEL参考设计
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"><title>AVR221 - PID controller: pid.c File Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"><link href="tabs.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.5.2 --><div class="tabs">  <ul>    <li><a href="main.html"><span>Main&nbsp;Page</span></a></li>    <li><a href="annotated.html"><span>Data&nbsp;Structures</span></a></li>    <li class="current"><a href="files.html"><span>Files</span></a></li>    <li><a href="pages.html"><span>Related&nbsp;Pages</span></a></li>  </ul></div><div class="tabs">  <ul>    <li><a href="files.html"><span>File&nbsp;List</span></a></li>    <li><a href="globals.html"><span>Globals</span></a></li>  </ul></div><h1>pid.c File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>General PID implementation for AVR. <p>Discrete PID controller implementation. Set up by giving P/I/D terms to Init_PID(), and uses a struct <a class="el" href="structPID__DATA.html" title="PID Status.">PID_DATA</a> to store internal values.<p><ul><li>File: <a class="el" href="pid_8c.html" title="General PID implementation for AVR.">pid.c</a></li><li>Compiler: IAR EWAAVR 4.11A</li><li>Supported devices: All AVR devices can be used.</li><li>AppNote: AVR221 - Discrete PID controller</li></ul><p><dl class="author" compact><dt><b>Author:</b></dt><dd>Atmel Corporation: <a href="http://www.atmel.com">http://www.atmel.com</a> <br> Support email: <a href="mailto:avr@atmel.com">avr@atmel.com</a></dd></dl>$Name$ <dl class="rcs" compact><dt><b>Revision</b></dt><dd>456 </dd></dl>$RCSfile$ <dl class="rcs" compact><dt><b>Date</b></dt><dd>2006-02-16 12:46:13 +0100 (to, 16 feb 2006) </dd></dl><p>Definition in file <a class="el" href="pid_8c-source.html">pid.c</a>.<p><code>#include &quot;<a class="el" href="pid_8h-source.html">pid.h</a>&quot;</code><br><code>#include &quot;<a class="el" href="stdint_8h-source.html">stdint.h</a>&quot;</code><br><p>Include dependency graph for pid.c:<p><center><img src="pid_8c__incl.png" border="0" usemap="#pid.c_map" alt=""></center><map name="pid.c_map"><area shape="rect" href="pid_8h.html" title="General PID implementation for AVR." alt="" coords="104,5,155,32"><area shape="rect" href="stdint_8h.html" title="Header file for pid.c." alt="" coords="204,31,268,57"></map><p><a href="pid_8c-source.html">Go to the source code of this file.</a><table border="0" cellpadding="0" cellspacing="0"><tr><td></td></tr><tr><td colspan="2"><br><h2>Functions</h2></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top"><a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#c0129c983e062dd6ee925ea932bae93f">pid_Controller</a> (<a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> setPoint, <a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> processValue, struct <a class="el" href="structPID__DATA.html">PID_DATA</a> *pid_st)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">PID control algorithm.  <a href="#c0129c983e062dd6ee925ea932bae93f"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#29fe06205528f56bcfdd242e3d1f9c19">pid_Init</a> (<a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> p_factor, <a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> i_factor, <a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> d_factor, struct <a class="el" href="structPID__DATA.html">PID_DATA</a> *pid)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Initialisation of PID controller parameters.  <a href="#29fe06205528f56bcfdd242e3d1f9c19"></a><br></td></tr><tr><td class="memItemLeft" nowrap align="right" valign="top">void&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#7b7ef4e688a58b21b6d36f620d8a645e">pid_Reset_Integrator</a> (<a class="el" href="structPID__DATA.html">pidData_t</a> *pid_st)</td></tr><tr><td class="mdescLeft">&nbsp;</td><td class="mdescRight">Resets the integrator.  <a href="#7b7ef4e688a58b21b6d36f620d8a645e"></a><br></td></tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="c0129c983e062dd6ee925ea932bae93f"></a><!-- doxytag: member="pid.c::pid_Controller" ref="c0129c983e062dd6ee925ea932bae93f" args="(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st)" --><div class="memitem"><div class="memproto">      <table class="memname">        <tr>          <td class="memname"><a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> pid_Controller           </td>          <td>(</td>          <td class="paramtype"><a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a>&nbsp;</td>          <td class="paramname"> <em>setPoint</em>, </td>        </tr>        <tr>          <td class="paramkey"></td>          <td></td>          <td class="paramtype"><a class="el" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a>&nbsp;</td>          <td class="paramname"> <em>processValue</em>, </td>        </tr>        <tr>          <td class="paramkey"></td>          <td></td>          <td class="paramtype">struct <a class="el" href="structPID__DATA.html">PID_DATA</a> *&nbsp;</td>          <td class="paramname"> <em>pid_st</em></td><td>&nbsp;</td>        </tr>        <tr>          <td></td>          <td>)</td>          <td></td><td></td><td width="100%"></td>        </tr>      </table></div><div class="memdoc"><p>PID control algorithm. <p>Calculates output from setpoint, process value and PID status.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>setPoint</em>&nbsp;</td><td>Desired value. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>processValue</em>&nbsp;</td><td>Measured value. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>pid_st</em>&nbsp;</td><td>PID status struct. </td></tr>  </table></dl><p>Definition at line <a class="el" href="pid_8c-source.html#l00059">59</a> of file <a class="el" href="pid_8c-source.html">pid.c</a>.<p>References <a class="el" href="pid_8h-source.html#l00041">PID_DATA::D_Factor</a>, <a class="el" href="pid_8h-source.html#l00039">PID_DATA::I_Factor</a>, <a class="el" href="pid_8h-source.html#l00033">PID_DATA::lastProcessValue</a>, <a class="el" href="pid_8h-source.html#l00055">MAX_I_TERM</a>, <a class="el" href="pid_8h-source.html#l00053">MAX_INT</a>, <a class="el" href="pid_8h-source.html#l00043">PID_DATA::maxError</a>, <a class="el" href="pid_8h-source.html#l00045">PID_DATA::maxSumError</a>, <a class="el" href="pid_8h-source.html#l00037">PID_DATA::P_Factor</a>, <a class="el" href="pid_8h-source.html#l00025">SCALING_FACTOR</a>, and <a class="el" href="pid_8h-source.html#l00035">PID_DATA::sumError</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00117">main()</a>.<div class="fragment"><pre class="fragment"><a name="l00060"></a>00060 {<a name="l00061"></a>00061   <a class="code" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> error, p_term, d_term;<a name="l00062"></a>00062   <a class="code" href="stdint_8h.html#2ba621978a511250f7250fb10e05ffbe">int32_t</a> i_term, ret, temp;<a name="l00063"></a>00063 <a name="l00064"></a>00064   error = setPoint - processValue;<a name="l00065"></a>00065 <a name="l00066"></a>00066   <span class="comment">// Calculate Pterm and limit error overflow</span><a name="l00067"></a>00067   <span class="keywordflow">if</span> (error &gt; pid_st-&gt;<a class="code" href="structPID__DATA.html#80263266448b31cb1b80b30a9a990fe3" title="Maximum allowed error, avoid overflow.">maxError</a>){<a name="l00068"></a>00068     p_term = <a class="code" href="pid_8h.html#aa1ac5caef84256eaeb39594e58e096f" title="Maximum values.">MAX_INT</a>;<a name="l00069"></a>00069   }<a name="l00070"></a>00070   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error &lt; -pid_st-&gt;maxError){<a name="l00071"></a>00071     p_term = -<a class="code" href="pid_8h.html#aa1ac5caef84256eaeb39594e58e096f" title="Maximum values.">MAX_INT</a>;<a name="l00072"></a>00072   }<a name="l00073"></a>00073   <span class="keywordflow">else</span>{<a name="l00074"></a>00074     p_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#30e77a609c5cd17e9d74e1e8315bf883" title="The Proportional tuning constant, multiplied with SCALING_FACTOR.">P_Factor</a> * error;<a name="l00075"></a>00075   }<a name="l00076"></a>00076 <a name="l00077"></a>00077   <span class="comment">// Calculate Iterm and limit integral runaway</span><a name="l00078"></a>00078   temp = pid_st-&gt;<a class="code" href="structPID__DATA.html#bb4705ed19c8668cc3b2a290bcad221d" title="Summation of errors, used for integrate calculations.">sumError</a> + error;<a name="l00079"></a>00079   <span class="keywordflow">if</span>(temp &gt; pid_st-&gt;<a class="code" href="structPID__DATA.html#e580ff6ff0cb31d86d094f1de1270bd7" title="Maximum allowed sumerror, avoid overflow.">maxSumError</a>){<a name="l00080"></a>00080     i_term = <a class="code" href="pid_8h.html#c375d861606f40c7616251bb33f7c9ab">MAX_I_TERM</a>;<a name="l00081"></a>00081     pid_st-&gt;<a class="code" href="structPID__DATA.html#bb4705ed19c8668cc3b2a290bcad221d" title="Summation of errors, used for integrate calculations.">sumError</a> = pid_st-&gt;<a class="code" href="structPID__DATA.html#e580ff6ff0cb31d86d094f1de1270bd7" title="Maximum allowed sumerror, avoid overflow.">maxSumError</a>;<a name="l00082"></a>00082   }<a name="l00083"></a>00083   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(temp &lt; -pid_st-&gt;maxSumError){<a name="l00084"></a>00084     i_term = -<a class="code" href="pid_8h.html#c375d861606f40c7616251bb33f7c9ab">MAX_I_TERM</a>;<a name="l00085"></a>00085     pid_st-&gt;<a class="code" href="structPID__DATA.html#bb4705ed19c8668cc3b2a290bcad221d" title="Summation of errors, used for integrate calculations.">sumError</a> = -pid_st-&gt;<a class="code" href="structPID__DATA.html#e580ff6ff0cb31d86d094f1de1270bd7" title="Maximum allowed sumerror, avoid overflow.">maxSumError</a>;<a name="l00086"></a>00086   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -