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

📄 main_8c-source.html

📁 离散 PID 控制 设计方法 ATMEL参考设计
💻 HTML
字号:
<!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: main.c Source File</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>main.c</h1><a href="main_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <span class="comment">/*This file has been prepared for Doxygen automatic documentation generation.*/</span><a name="l00022"></a>00022 <span class="preprocessor">#include &lt;inavr.h&gt;</span><a name="l00023"></a>00023 <span class="preprocessor">#include &lt;ioavr.h&gt;</span><a name="l00024"></a>00024 <span class="preprocessor">#include "<a class="code" href="stdint_8h.html">stdint.h</a>"</span><a name="l00025"></a>00025 <span class="preprocessor">#include "<a class="code" href="pid_8h.html" title="Header file for pid.c.">pid.h</a>"</span><a name="l00026"></a>00026 <a name="l00032"></a>00032 <a name="l00033"></a><a class="code" href="main_8c.html#cfc98b8c69707c30ac9a96bb12f2a0ab">00033</a> <span class="preprocessor">#define K_P     1.00</span><a name="l00035"></a><a class="code" href="main_8c.html#5e606c8dc6de900bea3cd7740ac1bd4d">00035</a> <span class="preprocessor">#define K_I     0.00</span><a name="l00037"></a><a class="code" href="main_8c.html#0b9e481775b5a7ecdd0dbb43cacc1a09">00037</a> <span class="preprocessor">#define K_D     0.00</span><a name="l00038"></a>00038 <span class="preprocessor"></span><a name="l00041"></a><a class="code" href="structGLOBAL__FLAGS.html">00041</a> <span class="keyword">struct </span><a class="code" href="structGLOBAL__FLAGS.html" title="Flags for status information.">GLOBAL_FLAGS</a> {<a name="l00043"></a><a class="code" href="structGLOBAL__FLAGS.html#6a87af13be5ba5f4835749cc92528a09">00043</a>   <a class="code" href="stdint_8h.html#ba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> <a class="code" href="structGLOBAL__FLAGS.html#6a87af13be5ba5f4835749cc92528a09" title="True when PID control loop should run one time.">pidTimer</a>:1;<a name="l00044"></a><a class="code" href="structGLOBAL__FLAGS.html#4ad67e9034f614d772064cbf9088ff55">00044</a>   <a class="code" href="stdint_8h.html#ba7bc1797add20fe3efdf37ced1182c5">uint8_t</a> <a class="code" href="structGLOBAL__FLAGS.html#4ad67e9034f614d772064cbf9088ff55">dummy</a>:7;<a name="l00045"></a>00045 } <a class="code" href="main_8c.html#37da6ea23a280bce8cc2ba16f6a31532" title="Flags for status information.">gFlags</a> = {0, 0};<a name="l00046"></a>00046 <a name="l00048"></a><a class="code" href="main_8c.html#e95a1d87e515fada8578052871321ff9">00048</a> <span class="keyword">struct </span><a class="code" href="structPID__DATA.html" title="PID Status.">PID_DATA</a> <a class="code" href="main_8c.html#e95a1d87e515fada8578052871321ff9" title="Parameters for regulator.">pidData</a>;<a name="l00049"></a>00049 <a name="l00056"></a>00056 <a name="l00057"></a><a class="code" href="main_8c.html#847b99b287f7c6555ab0f1cb4ed52119">00057</a> <span class="preprocessor">#define TIME_INTERVAL   157</span><a name="l00058"></a>00058 <span class="preprocessor"></span><a name="l00061"></a>00061 <span class="preprocessor">#pragma vector = TIMER0_OVF_vect</span><a name="l00062"></a><a class="code" href="main_8c.html#8b6ed5249679f9ab632635809380a5e5">00062</a> <span class="preprocessor"></span>__interrupt <span class="keywordtype">void</span> <a class="code" href="main_8c.html#8b6ed5249679f9ab632635809380a5e5" title="Timer interrupt to control the sampling interval.">TIMER0_OVF_ISR</a>( <span class="keywordtype">void</span> )<a name="l00063"></a>00063 {<a name="l00064"></a>00064   <span class="keyword">static</span> <a class="code" href="stdint_8h.html#273cf69d639a59973b6019625df33e30">uint16_t</a> i = 0;<a name="l00065"></a>00065   <span class="keywordflow">if</span>(i &lt; <a class="code" href="main_8c.html#847b99b287f7c6555ab0f1cb4ed52119">TIME_INTERVAL</a>)<a name="l00066"></a>00066     i++;<a name="l00067"></a>00067   <span class="keywordflow">else</span>{<a name="l00068"></a>00068     <a class="code" href="main_8c.html#37da6ea23a280bce8cc2ba16f6a31532" title="Flags for status information.">gFlags</a>.<a class="code" href="structGLOBAL__FLAGS.html#6a87af13be5ba5f4835749cc92528a09" title="True when PID control loop should run one time.">pidTimer</a> = <a class="code" href="pid_8h.html#a8cecfc5c5c054d2875c03e77b7be15d">TRUE</a>;<a name="l00069"></a>00069     i = 0;<a name="l00070"></a>00070   }<a name="l00071"></a>00071 }<a name="l00072"></a>00072 <a name="l00075"></a><a class="code" href="main_8c.html#7ce0a14b6e7779fbb2d9a05333792c41">00075</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#7ce0a14b6e7779fbb2d9a05333792c41" title="Init of PID controller demo.">Init</a>(<span class="keywordtype">void</span>)<a name="l00076"></a>00076 {<a name="l00077"></a>00077   <a class="code" href="pid_8c.html#29fe06205528f56bcfdd242e3d1f9c19" title="Initialisation of PID controller parameters.">pid_Init</a>(<a class="code" href="main_8c.html#cfc98b8c69707c30ac9a96bb12f2a0ab">K_P</a> * <a class="code" href="pid_8h.html#1dfc2df4edf95f828461ec28a276d36c">SCALING_FACTOR</a>, <a class="code" href="main_8c.html#5e606c8dc6de900bea3cd7740ac1bd4d">K_I</a> * SCALING_FACTOR , <a class="code" href="main_8c.html#0b9e481775b5a7ecdd0dbb43cacc1a09">K_D</a> * SCALING_FACTOR , &amp;<a class="code" href="main_8c.html#e95a1d87e515fada8578052871321ff9" title="Parameters for regulator.">pidData</a>);<a name="l00078"></a>00078 <a name="l00079"></a>00079   <span class="comment">// Set up timer, enable timer/counte 0 overflow interrupt</span><a name="l00080"></a>00080   TCCR0A = (1&lt;&lt;CS00);<a name="l00081"></a>00081   TIMSK0 = (1&lt;&lt;TOIE0);<a name="l00082"></a>00082   TCNT0 = 0;<a name="l00083"></a>00083 }<a name="l00084"></a>00084 <a name="l00090"></a><a class="code" href="main_8c.html#5d425d60c4c5cc27b85f5d91f3089b24">00090</a> <a class="code" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> <a class="code" href="main_8c.html#5d425d60c4c5cc27b85f5d91f3089b24" title="Read reference value.">Get_Reference</a>(<span class="keywordtype">void</span>)<a name="l00091"></a>00091 {<a name="l00092"></a>00092   <span class="keywordflow">return</span> 8;<a name="l00093"></a>00093 }<a name="l00094"></a>00094 <a name="l00099"></a><a class="code" href="main_8c.html#6c21c2fcef2ac5b7bd483e1ca38f14e0">00099</a> <a class="code" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> <a class="code" href="main_8c.html#6c21c2fcef2ac5b7bd483e1ca38f14e0" title="Read system process value.">Get_Measurement</a>(<span class="keywordtype">void</span>)<a name="l00100"></a>00100 {<a name="l00101"></a>00101   <span class="keywordflow">return</span> 4;<a name="l00102"></a>00102 }<a name="l00103"></a>00103 <a name="l00109"></a><a class="code" href="main_8c.html#9890f9c197e2e87a8b187f2c4c821e7a">00109</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#9890f9c197e2e87a8b187f2c4c821e7a" title="Set control input to system.">Set_Input</a>(<a class="code" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> inputValue)<a name="l00110"></a>00110 {<a name="l00111"></a>00111   ;<a name="l00112"></a>00112 }<a name="l00113"></a>00113 <a name="l00114"></a>00114 <a name="l00117"></a><a class="code" href="main_8c.html#6288eba0f8e8ad3ab1544ad731eb7667">00117</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#6288eba0f8e8ad3ab1544ad731eb7667" title="Demo of PID controller.">main</a>(<span class="keywordtype">void</span>)<a name="l00118"></a>00118 {<a name="l00119"></a>00119   <a class="code" href="stdint_8h.html#269259c924dce846340ddbb810db2e3c">int16_t</a> referenceValue, measurementValue, inputValue;<a name="l00120"></a>00120   <a class="code" href="main_8c.html#7ce0a14b6e7779fbb2d9a05333792c41" title="Init of PID controller demo.">Init</a>();<a name="l00121"></a>00121   __enable_interrupt();<a name="l00122"></a>00122 <a name="l00123"></a>00123   <span class="keywordflow">while</span>(1){<a name="l00124"></a>00124 <a name="l00125"></a>00125     <span class="comment">// Run PID calculations once every PID timer timeout</span><a name="l00126"></a>00126     <span class="keywordflow">if</span>(<a class="code" href="main_8c.html#37da6ea23a280bce8cc2ba16f6a31532" title="Flags for status information.">gFlags</a>.<a class="code" href="structGLOBAL__FLAGS.html#6a87af13be5ba5f4835749cc92528a09" title="True when PID control loop should run one time.">pidTimer</a>)<a name="l00127"></a>00127     {<a name="l00128"></a>00128       referenceValue = <a class="code" href="main_8c.html#5d425d60c4c5cc27b85f5d91f3089b24" title="Read reference value.">Get_Reference</a>();<a name="l00129"></a>00129       measurementValue = <a class="code" href="main_8c.html#6c21c2fcef2ac5b7bd483e1ca38f14e0" title="Read system process value.">Get_Measurement</a>();<a name="l00130"></a>00130 <a name="l00131"></a>00131       inputValue = <a class="code" href="pid_8c.html#c0129c983e062dd6ee925ea932bae93f" title="PID control algorithm.">pid_Controller</a>(referenceValue, measurementValue, &amp;<a class="code" href="main_8c.html#e95a1d87e515fada8578052871321ff9" title="Parameters for regulator.">pidData</a>);<a name="l00132"></a>00132 <a name="l00133"></a>00133       <a class="code" href="main_8c.html#9890f9c197e2e87a8b187f2c4c821e7a" title="Set control input to system.">Set_Input</a>(inputValue);<a name="l00134"></a>00134 <a name="l00135"></a>00135       <a class="code" href="main_8c.html#37da6ea23a280bce8cc2ba16f6a31532" title="Flags for status information.">gFlags</a>.<a class="code" href="structGLOBAL__FLAGS.html#6a87af13be5ba5f4835749cc92528a09" title="True when PID control loop should run one time.">pidTimer</a> = <a class="code" href="pid_8h.html#a93f0eb578d23995850d61f7d61c55c1">FALSE</a>;<a name="l00136"></a>00136     }<a name="l00137"></a>00137   }<a name="l00138"></a>00138 }<a name="l00139"></a>00139 </pre></div><hr size="1"><address style="text-align: right;"><small>Generated on Mon Sep 17 09:08:11 2007 for AVR221 - PID controller by&nbsp;<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.5.2 </small></address></body></html>

⌨️ 快捷键说明

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