📄 main_8c-source.html
字号:
<!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>AVR221 - PID controller: main.c Source File</title><link href="doxygen.css" rel="stylesheet" type="text/css"></head><body><!-- Generated by Doxygen 1.3.7 --><div class="qindex"><a class="qindex" href="main.html">Main Page</a> | <a class="qindex" href="annotated.html">Data Structures</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="functions.html">Data Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related Pages</a></div><h1>main.c</h1><a href="main_8c.html">Go to the documentation of this file.</a><pre class="fragment"><div>00001 <span class="comment">/*This file has been prepared for Doxygen automatic documentation generation.*/</span>00022 <span class="preprocessor">#include <inavr.h></span>00023 <span class="preprocessor">#include <ioavr.h></span>00024 <span class="preprocessor">#include "<a class="code" href="stdint_8h.html">stdint.h</a>"</span>00025 <span class="preprocessor">#include "<a class="code" href="pid_8h.html">pid.h</a>"</span>00026 00032 <a name="l00033"></a><a class="code" href="main_8c.html#a0">00033</a> <span class="preprocessor">#define K_P 1.00</span>00034 <span class="preprocessor"></span><a name="l00035"></a><a class="code" href="main_8c.html#a1">00035</a> <span class="preprocessor">#define K_I 0.00</span>00036 <span class="preprocessor"></span><a name="l00037"></a><a class="code" href="main_8c.html#a2">00037</a> <span class="preprocessor">#define K_D 0.00</span>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">GLOBAL_FLAGS</a> {<a name="l00043"></a><a class="code" href="structGLOBAL__FLAGS.html#o1">00043</a> <a class="code" href="stdint_8h.html#a56">uint8_t</a> <a class="code" href="structGLOBAL__FLAGS.html#o1">pidTimer</a>:1;<a name="l00044"></a><a class="code" href="structGLOBAL__FLAGS.html#o0">00044</a> <a class="code" href="stdint_8h.html#a56">uint8_t</a> <a class="code" href="structGLOBAL__FLAGS.html#o0">dummy</a>:7;00045 } <a class="code" href="main_8c.html#a4">gFlags</a> = {0, 0};00046 <a name="l00048"></a><a class="code" href="main_8c.html#a5">00048</a> <span class="keyword">struct </span><a class="code" href="structPID__DATA.html">PID_DATA</a> <a class="code" href="main_8c.html#a5">pidData</a>;00049 00056 <a name="l00057"></a><a class="code" href="main_8c.html#a3">00057</a> <span class="preprocessor">#define TIME_INTERVAL 157</span>00058 <span class="preprocessor"></span>00061 <span class="preprocessor">#pragma vector = TIMER0_OVF_vect</span><a name="l00062"></a><a class="code" href="main_8c.html#a6">00062</a> <span class="preprocessor"></span>__interrupt <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a6">TIMER0_OVF_ISR</a>( <span class="keywordtype">void</span> )00063 {00064 <span class="keyword">static</span> <a class="code" href="stdint_8h.html#a58">uint16_t</a> i = 0;00065 <span class="keywordflow">if</span>(i < <a class="code" href="main_8c.html#a3">TIME_INTERVAL</a>)00066 i++;00067 <span class="keywordflow">else</span>{00068 <a class="code" href="main_8c.html#a4">gFlags</a>.<a class="code" href="structGLOBAL__FLAGS.html#o1">pidTimer</a> = <a class="code" href="pid_8h.html#a5">TRUE</a>;00069 i = 0;00070 }00071 }00072 <a name="l00075"></a><a class="code" href="main_8c.html#a7">00075</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a7">Init</a>(<span class="keywordtype">void</span>)00076 {00077 <a class="code" href="pid_8h.html#a7">pid_Init</a>(<a class="code" href="main_8c.html#a0">K_P</a> * <a class="code" href="pid_8h.html#a0">SCALING_FACTOR</a>, <a class="code" href="main_8c.html#a1">K_I</a> * <a class="code" href="pid_8h.html#a0">SCALING_FACTOR</a> , <a class="code" href="main_8c.html#a2">K_D</a> * <a class="code" href="pid_8h.html#a0">SCALING_FACTOR</a> , &<a class="code" href="main_8c.html#a5">pidData</a>);00078 00079 <span class="comment">// Set up timer, enable timer/counte 0 overflow interrupt</span>00080 TCCR0A = (1<<CS00);00081 TIMSK0 = (1<<TOIE0);00082 TCNT0 = 0;00083 }00084 <a name="l00090"></a><a class="code" href="main_8c.html#a8">00090</a> <a class="code" href="stdint_8h.html#a57">int16_t</a> <a class="code" href="main_8c.html#a8">Get_Reference</a>(<span class="keywordtype">void</span>)00091 {00092 <span class="keywordflow">return</span> 8;00093 }00094 <a name="l00099"></a><a class="code" href="main_8c.html#a9">00099</a> <a class="code" href="stdint_8h.html#a57">int16_t</a> <a class="code" href="main_8c.html#a9">Get_Measurement</a>(<span class="keywordtype">void</span>)00100 {00101 <span class="keywordflow">return</span> 4;00102 }00103 <a name="l00109"></a><a class="code" href="main_8c.html#a10">00109</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a10">Set_Input</a>(int16_t inputValue)00110 {00111 ;00112 }00113 00114 <a name="l00117"></a><a class="code" href="main_8c.html#a11">00117</a> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a11">main</a>(<span class="keywordtype">void</span>)00118 {00119 <a class="code" href="stdint_8h.html#a57">int16_t</a> referenceValue, measurementValue, inputValue;00120 <a class="code" href="main_8c.html#a7">Init</a>();00121 __enable_interrupt();00122 00123 <span class="keywordflow">while</span>(1){00124 00125 <span class="comment">// Run PID calculations once every PID timer timeout</span>00126 <span class="keywordflow">if</span>(<a class="code" href="main_8c.html#a4">gFlags</a>.<a class="code" href="structGLOBAL__FLAGS.html#o1">pidTimer</a>)00127 {00128 referenceValue = <a class="code" href="main_8c.html#a8">Get_Reference</a>();00129 measurementValue = <a class="code" href="main_8c.html#a9">Get_Measurement</a>();00130 00131 inputValue = <a class="code" href="pid_8h.html#a8">pid_Controller</a>(referenceValue, measurementValue, &<a class="code" href="main_8c.html#a5">pidData</a>);00132 00133 <a class="code" href="main_8c.html#a10">Set_Input</a>(inputValue);00134 00135 <a class="code" href="main_8c.html#a4">gFlags</a>.<a class="code" href="structGLOBAL__FLAGS.html#o1">pidTimer</a> = <a class="code" href="pid_8h.html#a4">FALSE</a>;00136 }00137 }00138 }00139 </div></pre><hr size="1"><address style="align: right;"><small>Generated on Thu Feb 16 16:22:40 2006 for AVR221 - PID controller by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -