📄 main_8c.html
字号:
<table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>lastHall</em> </td><td>The last hall value. </td></tr> <tr><td valign="top"></td><td valign="top"><em>newHall</em> </td><td>The current hall value.</td></tr> </table></dl><p>Definition at line <a class="el" href="main_8c-source.html#l00522">522</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM_8h-source.html#l00042">PMSMflags::actualDirection</a>, <a class="el" href="PMSM_8h-source.html#l00141">DIRECTION_FORWARD</a>, <a class="el" href="PMSM_8h-source.html#l00144">DIRECTION_REVERSE</a>, <a class="el" href="PMSM_8h-source.html#l00147">DIRECTION_UNKNOWN</a>, <a class="el" href="PMSM__tables_8h-source.html#l00295">expectedHallSequenceForward</a>, <a class="el" href="PMSM__tables_8h-source.html#l00308">expectedHallSequenceReverse</a>, <a class="el" href="pid_8h-source.html#l00058">FALSE</a>, and <a class="el" href="PMSM_8h-source.html#l00041">PMSMflags::motorSynchronized</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00888">HallChangeISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00523"></a>00523 {<a name="l00524"></a>00524 <span class="comment">//Make sure that lastHall is within bounds of table. If not, set to an</span><a name="l00525"></a>00525 <span class="comment">//illegal hall value, but legal table index.</span><a name="l00526"></a>00526 <span class="keywordflow">if</span> (lastHall > 7)<a name="l00527"></a>00527 {<a name="l00528"></a>00528 lastHall = 0;<a name="l00529"></a>00529 }<a name="l00530"></a>00530 <span class="keywordflow">if</span> (<a class="code" href="PMSM__tables_8h.html#a3">expectedHallSequenceForward</a>[lastHall] == newHall)<a name="l00531"></a>00531 {<a name="l00532"></a>00532 fastFlags.actualDirection = <a class="code" href="PMSM_8h.html#a27">DIRECTION_FORWARD</a>;<a name="l00533"></a>00533 }<a name="l00534"></a>00534 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (<a class="code" href="PMSM__tables_8h.html#a4">expectedHallSequenceReverse</a>[lastHall] == newHall)<a name="l00535"></a>00535 {<a name="l00536"></a>00536 fastFlags.actualDirection = <a class="code" href="PMSM_8h.html#a28">DIRECTION_REVERSE</a>;<a name="l00537"></a>00537 }<a name="l00538"></a>00538 <span class="keywordflow">else</span><a name="l00539"></a>00539 {<a name="l00540"></a>00540 <a class="code" href="structPMSMflags.html">PMSMflags_t</a> tempFlags = fastFlags;<a name="l00541"></a>00541 tempFlags.<a class="code" href="structPMSMflags.html#o0">actualDirection</a> = <a class="code" href="PMSM_8h.html#a29">DIRECTION_UNKNOWN</a>;<a name="l00542"></a>00542 tempFlags.<a class="code" href="structPMSMflags.html#o4">motorSynchronized</a> = <a class="code" href="pid_8h.html#a4">FALSE</a>;<a name="l00543"></a>00543 fastFlags = tempFlags;<a name="l00544"></a>00544 }<a name="l00545"></a>00545 }</pre></div><p> </td> </tr></table><a class="anchor" name="a12"></a><!-- doxytag: member="main.c::ADCInit" ref="a12" 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">( </td> <td class="md" nowrap valign="top">void </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap><code> [static]</code></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Sets up the ADC for speed reference input on PA7. <p>This function initializes the ADC for speed reference measurements. The ADC will operate in single conversion mode.<p>Definition at line <a class="el" href="main_8c-source.html#l00239">239</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00120">main()</a>.<div class="fragment"><pre class="fragment"><a name="l00240"></a>00240 {<a name="l00241"></a>00241 <span class="comment">//Use PA7 as ADC input, 2.56V internal voltage reference without bypass capacitor.</span><a name="l00242"></a>00242 ADMUX = (1 << REFS1) | (0 << MUX4) | (0 << MUX3) | (1 << MUX2) | (1 << MUX1) | (0 << MUX0);<a name="l00243"></a>00243 <a name="l00244"></a>00244 ADCSRA = (1 << ADEN) | <span class="comment">//Enable the ADC.</span><a name="l00245"></a>00245 (1 << ADSC) | <span class="comment">//Start the first converssion.</span><a name="l00246"></a>00246 (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); <span class="comment">// Prescaler CK/128.</span><a name="l00247"></a>00247 ADCSRB = (1 << REFS2); <span class="comment">//2.56V internal reference.</span><a name="l00248"></a>00248 }</pre></div><p> </td> </tr></table><a class="anchor" name="a25"></a><!-- doxytag: member="main.c::AdjustSineTableIndex" ref="a25" 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">( </td> <td class="md" nowrap valign="top">const <a class="el" href="stdint_8h.html#a58">uint16_t</a> </td> <td class="mdname1" valign="top" nowrap> <em>increment</em> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap><code> [static]</code></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </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> </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#l00573">573</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM_8h-source.html#l00156">SINE_TABLE_LENGTH</a>, <a class="el" href="main_8c-source.html#l00064">sineTableIndex</a>, and <a class="el" href="main_8c-source.html#l00103">sineTableNextSectorStart</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00965">Timer1OverflowISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00574"></a>00574 {<a name="l00575"></a>00575 <a class="code" href="main_8c.html#a2">sineTableIndex</a> += increment;<a name="l00576"></a>00576 <a name="l00577"></a>00577 <span class="comment">// If the table index is out of bounds, wrap the index around the table end</span><a name="l00578"></a>00578 <span class="comment">// to continue from the beginning. Also wrap the next sector start index.</span><a name="l00579"></a>00579 <span class="keywordflow">if</span> ((<a class="code" href="main_8c.html#a2">sineTableIndex</a> >> 8) >= <a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a>)<a name="l00580"></a>00580 {<a name="l00581"></a>00581 <a class="code" href="main_8c.html#a2">sineTableIndex</a> -= (<a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a> << 8);<a name="l00582"></a>00582 <a class="code" href="main_8c.html#a6">sineTableNextSectorStart</a> -= <a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a>;<a name="l00583"></a>00583 }<a name="l00584"></a>00584 <a name="l00585"></a>00585 <span class="comment">//Make copy of sineNextSectorStart to specify order of volatile access.</span><a name="l00586"></a>00586 <a class="code" href="stdint_8h.html#a56">uint8_t</a> nextSectorStart = <a class="code" href="main_8c.html#a6">sineTableNextSectorStart</a>;<a name="l00587"></a>00587 <span class="keywordflow">if</span> ((<a class="code" href="main_8c.html#a2">sineTableIndex</a> >> 8) > nextSectorStart)<a name="l00588"></a>00588 {<a name="l00589"></a>00589 <a class="code" href="main_8c.html#a2">sineTableIndex</a> = (nextSectorStart << 8);<a name="l00590"></a>00590 }<a name="l00591"></a>00591 }</pre></div><p> </td> </tr></table><a class="anchor" name="a20"></a><!-- doxytag: member="main.c::BlockCommutate" ref="a20" args="(const uint8_t direction, const uint8_t hall)" --><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 BlockCommutate </td> <td class="md" valign="top">( </td> <td class="md" nowrap valign="top">const <a class="el" href="stdint_8h.html#a56">uint8_t</a> </td> <td class="mdname" nowrap> <em>direction</em>, </td> </tr> <tr> <td class="md" nowrap align="right"></td> <td class="md"></td> <td class="md" nowrap>const <a class="el" href="stdint_8h.html#a56">uint8_t</a> </td> <td class="mdname" nowrap> <em>hall</em></td> </tr> <tr> <td class="md"></td> <td class="md">) </td> <td class="md" colspan="2"><code> [static]</code></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Performs block commutation according to running direction and hall sensor input. <p>This function performs a block commutation according to the specified running direction and hall sensor input.<p><dl compact><dt><b>Note:</b></dt><dd>Do not use this function while the timers are configured for sine wave driving.</dd></dl><dl compact><dt><b>Parameters:</b></dt><dd> <table border="0" cellspacing="2" cellpadding="0"> <tr><td valign="top"></td><td valign="top"><em>direction</em> </td><td>Direction of rotation. </td></tr> <tr><td valign="top"></td><td valign="top"><em>hall</em> </td><td>Hall sensor value at the same form as returned by <a class="el" href="main_8c.html#a21">GetHall()</a>.</td></tr> </table></dl><p>Definition at line <a class="el" href="main_8c-source.html#l00455">455</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="PMSM__tables_8h-source.html#l00257">blockCommutationTableForward</a>, <a class="el" href="PMSM__tables_8h-source.html#l00275">blockCommutationTableReverse</a>, and <a class="el" href="PMSM_8h-source.html#l00141">DIRECTION_FORWARD</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00643">CommutationTicksUpdate()</a>, and <a class="el" href="main_8c-source.html#l00888">HallChangeISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00456"></a>00456 {<a name="l00457"></a>00457 <span class="keywordflow">if</span> (direction == <a class="code" href="PMSM_8h.html#a27">DIRECTION_FORWARD</a>)<a name="l00458"></a>00458 {<a name="l00459"></a>00459 TCCR1E = <a class="code" href="PMSM__tables_8h.html#a1">blockCommutationTableForward</a>[hall];<a name="l00460"></a>00460 }<a name="l00461"></a>00461 <span class="keywordflow">else</span><a name="l00462"></a>00462 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -