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

📄 main_8c.html

📁 Atmel算法(pid)-步进电机驱动源码 HOWTO,不好用你找我,绝对ok!
💻 HTML
📖 第 1 页 / 共 5 页
字号:
  <tr>    <td>      &nbsp;    </td>    <td><p>Updates global actual direction flag based on the two latest hall values. <p>Calling this function with the last two hall sensor values as parameters triggers an update of the global actualDirection flag.<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>lastHall</em>&nbsp;</td><td>The last hall value. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>newHall</em>&nbsp;</td><td>The current hall value.</td></tr>  </table></dl><p>Definition at line <a class="el" href="main_8c-source.html#l00594">594</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM_8h-source.html#l00257">PMSMflags::actualDirection</a>, <a class="el" href="PMSM_8h-source.html#l00061">DIRECTION_FORWARD</a>, <a class="el" href="PMSM_8h-source.html#l00064">DIRECTION_REVERSE</a>, <a class="el" href="PMSM_8h-source.html#l00067">DIRECTION_UNKNOWN</a>, <a class="el" href="PMSMtables_8h-source.html#l00541">expectedHallSequenceForward</a>, <a class="el" href="PMSMtables_8h-source.html#l00555">expectedHallSequenceReverse</a>, <a class="el" href="pid_8h-source.html#l00079">FALSE</a>, and <a class="el" href="PMSM_8h-source.html#l00256">PMSMflags::motorSynchronized</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00930">HallChangeISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00595"></a>00595 {<a name="l00596"></a>00596   <span class="comment">//Make sure that lastHall is within bounds of table. If not, set to 0, which is</span><a name="l00597"></a>00597   <span class="comment">//also an illegal hall value, but legal table index.</span><a name="l00598"></a>00598   <span class="keywordflow">if</span> (lastHall &gt; 6)<a name="l00599"></a>00599   {<a name="l00600"></a>00600     lastHall = 0;<a name="l00601"></a>00601   }<a name="l00602"></a>00602   <span class="keywordflow">if</span> (<a class="code" href="PMSMtables_8h.html#a4">expectedHallSequenceForward</a>[lastHall] == newHall)<a name="l00603"></a>00603   {<a name="l00604"></a>00604     fastFlags.actualDirection = <a class="code" href="PMSM_8h.html#a7">DIRECTION_FORWARD</a>;<a name="l00605"></a>00605   }<a name="l00606"></a>00606   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="PMSMtables_8h.html#a5">expectedHallSequenceReverse</a>[lastHall] == newHall)<a name="l00607"></a>00607   {<a name="l00608"></a>00608    fastFlags.actualDirection = <a class="code" href="PMSM_8h.html#a8">DIRECTION_REVERSE</a>;<a name="l00609"></a>00609   }<a name="l00610"></a>00610   <span class="keywordflow">else</span><a name="l00611"></a>00611   {<a name="l00612"></a>00612     <a class="code" href="structPMSMflags.html">PMSMflags_t</a> tempFlags = fastFlags;<a name="l00613"></a>00613     tempFlags.<a class="code" href="structPMSMflags.html#o0">actualDirection</a> = <a class="code" href="PMSM_8h.html#a9">DIRECTION_UNKNOWN</a>;<a name="l00614"></a>00614     tempFlags.<a class="code" href="structPMSMflags.html#o4">motorSynchronized</a> = <a class="code" href="pid_8h.html#a4">FALSE</a>;<a name="l00615"></a>00615     fastFlags = tempFlags;<a name="l00616"></a>00616   }<a name="l00617"></a>00617 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a43"></a><!-- doxytag: member="main.c::ADCCompleteISR" ref="a43" args="(void)" --><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">__interrupt void ADCCompleteISR           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">void&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>AD conversion complete interrupt service routine. <p>This interrupt service routine is automatically executed every time an AD conversion is finished and the converted result is available in the ADC data register.<p>The switch/case construct makes sure the converted value is stored in the variable corresponding to the selected channel and changes the channel for the next ADC measurement.<p>More ADC measurements can be added to the cycle by extending the switch/ case construct.<p>Only the 8 most significant bits of the ADC result are used.<p>Definition at line <a class="el" href="main_8c-source.html#l01122">1122</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM_8h-source.html#l00122">ADMUX_CURRENT</a>, <a class="el" href="PMSM_8h-source.html#l00119">ADMUX_SPEED_REF</a>, <a class="el" href="main_8c-source.html#l00109">current</a>, and <a class="el" href="main_8c-source.html#l00113">speedInput</a>.<div class="fragment"><pre class="fragment"><a name="l01123"></a>01123 {<a name="l01124"></a>01124   <span class="keywordflow">switch</span> (ADMUX)<a name="l01125"></a>01125   {<a name="l01126"></a>01126   <span class="keywordflow">case</span> <a class="code" href="PMSM_8h.html#a24">ADMUX_SPEED_REF</a>:<a name="l01127"></a>01127     <a class="code" href="main_8c.html#a8">speedInput</a> = ADCH;<a name="l01128"></a>01128     ADMUX = <a class="code" href="PMSM_8h.html#a25">ADMUX_CURRENT</a>;<a name="l01129"></a>01129     <span class="keywordflow">break</span>;<a name="l01130"></a>01130   <span class="keywordflow">case</span> <a class="code" href="PMSM_8h.html#a25">ADMUX_CURRENT</a>:<a name="l01131"></a>01131     <a class="code" href="main_8c.html#a7">current</a> = ADCH;<a name="l01132"></a>01132     ADMUX = <a class="code" href="PMSM_8h.html#a24">ADMUX_SPEED_REF</a>;<a name="l01133"></a>01133     <span class="keywordflow">break</span>;<a name="l01134"></a>01134   <span class="keywordflow">default</span>:<a name="l01135"></a>01135     <span class="comment">//This is probably an error and should be handled.</span><a name="l01136"></a>01136     <span class="keywordflow">break</span>;<a name="l01137"></a>01137   }<a name="l01138"></a>01138 <a name="l01139"></a>01139   <span class="comment">//Clear Timer/counter0 overflow flag.</span><a name="l01140"></a>01140   TIFR0 = (1 &lt;&lt; TOV0);<a name="l01141"></a>01141 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a14"></a><!-- doxytag: member="main.c::ADCInit" ref="a14" args="(void)" --><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">static void ADCInit           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">void&nbsp;</td>          <td class="mdname1" valign="top" nowrap>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [static]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>Initializes the ADC. <p>This function initializes the ADC for speed reference measurements. The ADC will operate in free-running mode, and reading is done in the ADC complete interrupt service routine.<p>Definition at line <a class="el" href="main_8c-source.html#l00266">266</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM_8h-source.html#l00101">ADC_PRESCALER</a>, and <a class="el" href="PMSM_8h-source.html#l00119">ADMUX_SPEED_REF</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00135">main()</a>.<div class="fragment"><pre class="fragment"><a name="l00267"></a>00267 {<a name="l00268"></a>00268   <span class="comment">//Select initial AD conversion channel.</span><a name="l00269"></a>00269   ADMUX = <a class="code" href="PMSM_8h.html#a24">ADMUX_SPEED_REF</a>;<a name="l00270"></a>00270 <a name="l00271"></a>00271   <span class="comment">//Initialize ADC.</span><a name="l00272"></a>00272   ADCSRA = (1 &lt;&lt; ADEN) | (1 &lt;&lt; ADSC) | (1 &lt;&lt; ADATE) | (1 &lt;&lt; ADIF) | (1 &lt;&lt; ADIE) | <a class="code" href="PMSM_8h.html#a19">ADC_PRESCALER</a>;<a name="l00273"></a>00273 <a name="l00274"></a>00274   <span class="comment">//Set trigger source to Timer/Counter0 overflow.</span><a name="l00275"></a>00275   ADCSRB = (1 &lt;&lt; ADTS2) | (0 &lt;&lt; ADTS1) | (0 &lt;&lt; ADTS0);<a name="l00276"></a>00276 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a31"></a><!-- doxytag: member="main.c::AdjustSineTableIndex" ref="a31" args="(const uint16_t increment)" --><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">static void AdjustSineTableIndex           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">const <a class="el" href="stdint_8h.html#a58">uint16_t</a>&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>increment</em>          </td>          <td class="md" valign="top">&nbsp;)&nbsp;</td>          <td class="md" nowrap><code> [static]</code></td>        </tr>      </table>    </td>  </tr></table><table cellspacing="5" cellpadding="0" border="0">  <tr>    <td>      &nbsp;    </td>    <td><p>Adjusts the sine table index according to the current increment. <p>This function increases the sine table index with the given increment The index is then adjusted to be within the table length.<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>increment</em>&nbsp;</td><td>The increment (in 8.8 format) added to the sine table index.</td></tr>  </table></dl><p>Definition at line <a class="el" href="main_8c-source.html#l00713">713</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM_8h-source.html#l00045">SINE_TABLE_LENGTH</a>, <a class="el" href="main_8c-source.html#l00061">sineTableIndex</a>, and <a class="el" href="main_8c-source.html#l00100">sineTableNextSectorStart</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l01030">Timer1CaptureISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00714"></a>00714 {<a name="l00715"></a>00715   <a class="code" href="main_8c.html#a2">sineTableIndex</a> += increment;<a name="l00716"></a>00716 <a name="l00717"></a>00717   <span class="comment">// If the table index is out of bounds, wrap the index around the table end</span><a name="l00718"></a>00718   <span class="comment">// to continue from the beginning. Also wrap the next sector start index.</span><a name="l00719"></a>00719   <span class="keywordflow">if</span> ((<a class="code" href="main_8c.html#a2">sineTableIndex</a> &gt;&gt; 8) &gt;= <a class="code" href="PMSM_8h.html#a3">SINE_TABLE_LENGTH</a>)<a name="l00720"></a>00720   {<a name="l00721"></a>00721     <a class="code" href="main_8c.html#a2">sineTableIndex</a> -= (<a class="code" href="PMSM_8h.html#a3">SINE_TABLE_LENGTH</a> &lt;&lt; 8);<a name="l00722"></a>00722     <a class="code" href="main_8c.html#a6">sineTableNextSectorStart</a> -= <a class="code" href="PMSM_8h.html#a3">SINE_TABLE_LENGTH</a>;<a name="l00723"></a>00723   }<a name="l00724"></a>00724 <a name="l00725"></a>00725   <span class="comment">//Make copy of sineNextSectorStart to specify order of volatile access.</span><a name="l00726"></a>00726   <a class="code" href="stdint_8h.html#a56">uint8_t</a> nextSectorStart = <a class="code" href="main_8c.html#a6">sineTableNextSectorStart</a>;<a name="l00727"></a>00727   <span class="keywordflow">if</span> ((<a class="code" href="main_8c.html#a2">sineTableIndex</a> &gt;&gt; 8) &gt; nextSectorStart)<a name="l00728"></a>00728   {<a name="l00729"></a>00729     <a class="code" href="main_8c.html#a2">sineTableIndex</a> = (nextSectorStart &lt;&lt; 8);

⌨️ 快捷键说明

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