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

📄 pid_8c.html

📁 ATtiny261 461 861 这份资料介绍了执行Attiny261 461 861微控制器系列正弦波驱动三相无刷直流电动机霍尔传感器。
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"><title>AVR449: pid.c File Reference</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.4.4 --><div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div><h1>pid.c File Reference</h1><hr><a name="_details"></a><h2>Detailed Description</h2>PID controller. <p>This file contains the PID controller, based on the AVR221 application note.<p><dl compact><dt><b>Application note:</b></dt><dd>AVR447: Sinusoidal driving of three-phase permanent motor using ATtiny261/461/861.</dd></dl><dl compact><dt><b>Documentation</b></dt><dd>For comprehensive code documentation, supported compilers, compiler settings and supported devices see readme.html</dd></dl><dl 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><dl compact><dt><b>Name</b></dt><dd>RELEASE_1_0 </dd></dl><dl compact><dt><b>Revision</b></dt><dd>1.2 </dd></dl><dl compact><dt><b>RCSfile</b></dt><dd><a class="el" href="pid_8c.html">pid.c</a>,v </dd></dl><dl compact><dt><b>Date</b></dt><dd>2006/05/11 13:31:43 </dd></dl><br><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 href="pid_8h.html" shape="rect" coords="104,5,155,32" alt=""><area href="stdint_8h.html" shape="rect" coords="204,31,268,57" alt=""></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#a57">int16_t</a>&nbsp;</td><td class="memItemRight" valign="bottom"><a class="el" href="pid_8c.html#a1">pid_Controller</a> (<a class="el" href="stdint_8h.html#a57">int16_t</a> setPoint, <a class="el" href="stdint_8h.html#a57">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="#a1"></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#a0">pid_Init</a> (<a class="el" href="stdint_8h.html#a57">int16_t</a> p_factor, <a class="el" href="stdint_8h.html#a57">int16_t</a> i_factor, <a class="el" href="stdint_8h.html#a57">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="#a0"></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#a2">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="#a2"></a><br></td></tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="a1"></a><!-- doxytag: member="pid.c::pid_Controller" ref="a1" args="(int16_t setPoint, int16_t processValue, struct PID_DATA *pid_st)" --><p><table class="mdTable" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"><a class="el" href="stdint_8h.html#a57">int16_t</a> pid_Controller           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top"><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>setPoint</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td class="md"></td>          <td class="md" nowrap><a class="el" href="stdint_8h.html#a57">int16_t</a>&nbsp;</td>          <td class="mdname" nowrap> <em>processValue</em>, </td>        </tr>        <tr>          <td class="md" nowrap align="right"></td>          <td class="md"></td>          <td class="md" nowrap>struct <a class="el" href="structPID__DATA.html">PID_DATA</a> *&nbsp;</td>          <td class="mdname" nowrap> <em>pid_st</em></td>        </tr>        <tr>          <td class="md"></td>          <td class="md">)&nbsp;</td>          <td class="md" colspan="2"></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><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#l00064">64</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#l00278">SpeedController()</a>.<div class="fragment"><pre class="fragment"><a name="l00065"></a>00065 {<a name="l00066"></a>00066   <a class="code" href="stdint_8h.html#a57">int16_t</a> error, p_term, d_term;<a name="l00067"></a>00067   <a class="code" href="stdint_8h.html#a59">int32_t</a> i_term, ret, temp;<a name="l00068"></a>00068 <a name="l00069"></a>00069   error = setPoint - processValue;<a name="l00070"></a>00070 <a name="l00071"></a>00071   <span class="comment">// Calculate Pterm and limit error overflow</span><a name="l00072"></a>00072   <span class="keywordflow">if</span> (error &gt; pid_st-&gt;<a class="code" href="structPID__DATA.html#o3">maxError</a>){<a name="l00073"></a>00073     p_term = <a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00074"></a>00074   }<a name="l00075"></a>00075   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (error &lt; -pid_st-&gt;maxError){<a name="l00076"></a>00076     p_term = -<a class="code" href="pid_8h.html#a1">MAX_INT</a>;<a name="l00077"></a>00077   }<a name="l00078"></a>00078   <span class="keywordflow">else</span>{<a name="l00079"></a>00079     p_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#o5">P_Factor</a> * error;<a name="l00080"></a>00080   }<a name="l00081"></a>00081 <a name="l00082"></a>00082   <span class="comment">// Calculate Iterm and limit integral runaway</span><a name="l00083"></a>00083   temp = pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> + error;<a name="l00084"></a>00084   <span class="keywordflow">if</span>(temp &gt; pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>){<a name="l00085"></a>00085     i_term = <a class="code" href="pid_8h.html#a3">MAX_I_TERM</a>;<a name="l00086"></a>00086     pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>;<a name="l00087"></a>00087   }<a name="l00088"></a>00088   <span class="keywordflow">else</span> <span class="keywordflow">if</span>(temp &lt; -pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>){<a name="l00089"></a>00089     i_term = -<a class="code" href="pid_8h.html#a3">MAX_I_TERM</a>;<a name="l00090"></a>00090     pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = -pid_st-&gt;<a class="code" href="structPID__DATA.html#o4">maxSumError</a>;<a name="l00091"></a>00091   }<a name="l00092"></a>00092   <span class="keywordflow">else</span>{<a name="l00093"></a>00093     pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a> = temp;<a name="l00094"></a>00094     i_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#o1">I_Factor</a> * pid_st-&gt;<a class="code" href="structPID__DATA.html#o6">sumError</a>;<a name="l00095"></a>00095   }<a name="l00096"></a>00096 <a name="l00097"></a>00097   <span class="comment">// Calculate Dterm</span><a name="l00098"></a>00098   d_term = pid_st-&gt;<a class="code" href="structPID__DATA.html#o0">D_Factor</a> * (pid_st-&gt;<a class="code" href="structPID__DATA.html#o2">lastProcessValue</a> - processValue);<a name="l00099"></a>00099 <a name="l00100"></a>00100   pid_st-&gt;<a class="code" href="structPID__DATA.html#o2">lastProcessValue</a> = processValue;<a name="l00101"></a>00101 

⌨️ 快捷键说明

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