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

📄 main_8c.html

📁 ATtiny261 461 861 这份资料介绍了执行Attiny261 461 861微控制器系列正弦波驱动三相无刷直流电动机霍尔传感器。
💻 HTML
📖 第 1 页 / 共 5 页
字号:
</table><a class="anchor" name="a33"></a><!-- doxytag: member="main.c::HallChangeISR" ref="a33" args="()" --><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 HallChangeISR           </td>          <td class="md" valign="top">(&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>Updates the PWM outputs according to the current position and amplitude.Hall sensor change interrupt service routine. <p>This ISR is run every time one of the hall sensor inputs changes value. The responsibilities of this ISR are:<ul><li>Synchronize sine wave generation to hall sensors.</li><li>Block commutation.</li><li>Direction control.</li><li>Synchronization control.</li><li>Sine table increment calculation.</li><li>Stop detection.</li></ul><p>Definition at line <a class="el" href="main_8c-source.html#l00888">888</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="main_8c-source.html#l00522">ActualDirectionUpdate()</a>, <a class="el" href="main_8c-source.html#l00092">advanceCommutationSteps</a>, <a class="el" href="main_8c-source.html#l00455">BlockCommutate()</a>, <a class="el" href="main_8c-source.html#l00074">commutationTicks</a>, <a class="el" href="PMSM__tables_8h-source.html#l00322">CSOffsetsForward</a>, <a class="el" href="PMSM__tables_8h-source.html#l00343">CSOffsetsReverse</a>, <a class="el" href="PMSM_8h-source.html#l00141">DIRECTION_FORWARD</a>, <a class="el" href="pid_8h-source.html#l00058">FALSE</a>, <a class="el" href="main_8c-source.html#l00437">GetDesiredDirection()</a>, <a class="el" href="main_8c-source.html#l00484">GetHall()</a>, <a class="el" href="main_8c-source.html#l00709">IsMotorSynchronized()</a>, <a class="el" href="main_8c-source.html#l00675">MotorSynchronizedUpdate()</a>, <a class="el" href="main_8c-source.html#l00055">sineTableIncrement</a>, <a class="el" href="main_8c-source.html#l00559">SineTableIncrementCalculate()</a>, <a class="el" href="main_8c-source.html#l00064">sineTableIndex</a>, <a class="el" href="main_8c-source.html#l00103">sineTableNextSectorStart</a>, <a class="el" href="PMSM_8h-source.html#l00173">TABLE_ELEMENTS_PER_COMMUTATION_SECTOR</a>, <a class="el" href="main_8c-source.html#l00317">TimerSetModeSinusoidal()</a>, <a class="el" href="PMSM_8h-source.html#l00197">WAVEFORM_BLOCK_COMMUTATION</a>, and <a class="el" href="PMSM_8h-source.html#l00200">WAVEFORM_SINUSOIDAL</a>.<div class="fragment"><pre class="fragment"><a name="l00889"></a>00889 {<a name="l00890"></a>00890   <span class="keyword">static</span> <a class="code" href="stdint_8h.html#a56">uint8_t</a> lastHall = 0xff;<a name="l00891"></a>00891   <a class="code" href="stdint_8h.html#a56">uint8_t</a> hall;<a name="l00892"></a>00892 <a name="l00893"></a>00893   hall = <a class="code" href="main_8c.html#a21">GetHall</a>();<a name="l00894"></a>00894 <a name="l00895"></a>00895   <span class="comment">//Make sure that the hall sensors really changed.</span><a name="l00896"></a>00896   <span class="keywordflow">if</span> (hall == lastHall)<a name="l00897"></a>00897   {<a name="l00898"></a>00898     <span class="keywordflow">return</span>;<a name="l00899"></a>00899   }<a name="l00900"></a>00900 <a name="l00901"></a>00901   <a class="code" href="main_8c.html#a30">MotorSynchronizedUpdate</a>();<a name="l00902"></a>00902   <a class="code" href="stdint_8h.html#a56">uint8_t</a> synch = <a class="code" href="main_8c.html#a31">IsMotorSynchronized</a>();<a name="l00903"></a>00903   <span class="keywordflow">if</span> ((fastFlags.driveWaveform != <a class="code" href="PMSM_8h.html#a39">WAVEFORM_SINUSOIDAL</a>) &amp;&amp; (synch))<a name="l00904"></a>00904   {<a name="l00905"></a>00905     <a class="code" href="main_8c.html#a15">TimerSetModeSinusoidal</a>();<a name="l00906"></a>00906   }<a name="l00907"></a>00907 <a name="l00908"></a>00908   <span class="comment">//If sinusoidal driving is used, synchronize sine wave generation to the</span><a name="l00909"></a>00909   <span class="comment">//current hall sensor value. Advance commutation (lead angle) is also</span><a name="l00910"></a>00910   <span class="comment">//added in the process.</span><a name="l00911"></a>00911   <span class="keywordflow">if</span> (fastFlags.driveWaveform == <a class="code" href="PMSM_8h.html#a39">WAVEFORM_SINUSOIDAL</a>)<a name="l00912"></a>00912   {<a name="l00913"></a>00913     <a class="code" href="stdint_8h.html#a58">uint16_t</a> tempIndex;<a name="l00914"></a>00914     <span class="keywordflow">if</span> (<a class="code" href="main_8c.html#a19">GetDesiredDirection</a>() == <a class="code" href="PMSM_8h.html#a27">DIRECTION_FORWARD</a>)<a name="l00915"></a>00915     {<a name="l00916"></a>00916       tempIndex = (<a class="code" href="PMSM__tables_8h.html#a5">CSOffsetsForward</a>[hall] + <a class="code" href="main_8c.html#a5">advanceCommutationSteps</a>) &lt;&lt; 8;<a name="l00917"></a>00917     }<a name="l00918"></a>00918     <span class="keywordflow">else</span><a name="l00919"></a>00919     {<a name="l00920"></a>00920       tempIndex = (<a class="code" href="PMSM__tables_8h.html#a6">CSOffsetsReverse</a>[hall] + <a class="code" href="main_8c.html#a5">advanceCommutationSteps</a>) &lt;&lt; 8;<a name="l00921"></a>00921     }<a name="l00922"></a>00922     <a class="code" href="main_8c.html#a2">sineTableIndex</a> = tempIndex;<a name="l00923"></a>00923 <a name="l00924"></a>00924     <span class="comment">//Adjust next sector start index. It might be set to a value larger than</span><a name="l00925"></a>00925     <span class="comment">//SINE_TABLE_LENGTH at this point. This is adjusted in AdjustSineTableIndex</span><a name="l00926"></a>00926     <span class="comment">//and should not be done here, as it will cause problems when advance</span><a name="l00927"></a>00927     <span class="comment">//commutation is used.</span><a name="l00928"></a>00928     <a class="code" href="main_8c.html#a6">sineTableNextSectorStart</a> = (tempIndex &gt;&gt; 8) + <a class="code" href="PMSM_8h.html#a34">TABLE_ELEMENTS_PER_COMMUTATION_SECTOR</a>;<a name="l00929"></a>00929 <a name="l00930"></a>00930   }<a name="l00931"></a>00931   <span class="comment">//If block commutation is used. Commutate according to hall signal.</span><a name="l00932"></a>00932   <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fastFlags.driveWaveform == <a class="code" href="PMSM_8h.html#a38">WAVEFORM_BLOCK_COMMUTATION</a>)<a name="l00933"></a>00933   {<a name="l00934"></a>00934     <a class="code" href="main_8c.html#a20">BlockCommutate</a>(<a class="code" href="main_8c.html#a19">GetDesiredDirection</a>(), hall);<a name="l00935"></a>00935   }<a name="l00936"></a>00936 <a name="l00937"></a>00937   <span class="comment">//Update the actual direction flag.</span><a name="l00938"></a>00938   <a class="code" href="main_8c.html#a23">ActualDirectionUpdate</a>(lastHall, hall);<a name="l00939"></a>00939 <a name="l00940"></a>00940   lastHall = hall;<a name="l00941"></a>00941 <a name="l00942"></a>00942 <a name="l00943"></a>00943   <span class="comment">//Calculate new step size for sine wave generation and reset commutation</span><a name="l00944"></a>00944   <span class="comment">//timer.</span><a name="l00945"></a>00945   <a class="code" href="main_8c.html#a1">sineTableIncrement</a> = <a class="code" href="main_8c.html#a24">SineTableIncrementCalculate</a>(<a class="code" href="main_8c.html#a3">commutationTicks</a>);<a name="l00946"></a>00946   <a class="code" href="main_8c.html#a3">commutationTicks</a> = 0;<a name="l00947"></a>00947 <a name="l00948"></a>00948   <span class="comment">//Since the hall sensors are changing, the motor can not be stopped.</span><a name="l00949"></a>00949   fastFlags.motorStopped = <a class="code" href="pid_8h.html#a4">FALSE</a>;<a name="l00950"></a>00950 }</pre></div><p><p>Here is the call graph for this function:<p><center><img src="main_8c_a33_cgraph.png" border="0" usemap="#main_8c_a33_cgraph_map" alt=""></center><map name="main_8c_a33_cgraph_map"><area href="main_8c.html#a23" shape="rect" coords="188,5,345,32" alt=""><area href="main_8c.html#a20" shape="rect" coords="204,56,329,83" alt=""><area href="main_8c.html#a19" shape="rect" coords="196,107,337,133" alt=""><area href="main_8c.html#a21" shape="rect" coords="233,157,300,184" alt=""><area href="main_8c.html#a31" shape="rect" coords="193,208,340,235" alt=""><area href="main_8c.html#a30" shape="rect" coords="177,259,356,285" alt=""><area href="main_8c.html#a24" shape="rect" coords="168,309,365,336" alt=""><area href="main_8c.html#a15" shape="rect" coords="181,360,352,387" alt=""><area href="main_8c.html#a28" shape="rect" coords="413,335,560,361" alt=""><area href="main_8c.html#a27" shape="rect" coords="415,385,559,412" alt=""></map>    </td>  </tr></table><a class="anchor" name="a31"></a><!-- doxytag: member="main.c::IsMotorSynchronized" ref="a31" 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 <a class="el" href="stdint_8h.html#a56">uint8_t</a> IsMotorSynchronized           </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>Returns the motor synchronized flag. <p>This function returns the motor synchronized flag.<p><dl compact><dt><b>Returns:</b></dt><dd>The motor synchronized flag.</dd></dl><dl compact><dt><b>Return values:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td valign="top"></td><td valign="top"><em>TRUE</em>&nbsp;</td><td>Motor control is synchronized with motor. </td></tr>    <tr><td valign="top"></td><td valign="top"><em>FALSE</em>&nbsp;</td><td>Motor control is not yet synchronized with motor.</td></tr>  </table></dl><p>Definition at line <a class="el" href="main_8c-source.html#l00709">709</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#l00888">HallChangeISR()</a>.<div class="fragment"><pre class="fragment"><a name="l00710"></a>00710 {<a name="l00711"></a>00711   <span class="keywordflow">return</span> (<a class="code" href="stdint_8h.html#a56">uint8_t</a>)(fastFlags.motorSynchronized);<a name="l00712"></a>00712 }</pre></div><p>    </td>  </tr></table><a class="anchor" name="a8"></a><!-- doxytag: member="main.c::main" ref="a8" 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">void main           </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><p>Definition at line <a class="el" href="main_8c-source.html#l00120">120</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="main_8c-source.html#l00239">ADCInit()</a>, <a class="el" href="PMSM_8h-source.html#l00043">PMSMflags::desiredDirection</a>, <a class="el" href="main_8c-source.html#l00500">DesiredDirectionUpdate()</a>, <a class="el" href="PMSM_8h-source.html#l00147">DIRECTION_UNKNOWN</a>, <a class="el" href="PMSM_8h-source.html#l00044">PMSMflags::driveWaveform</a>, <a class="el" href="pid_8h-source.html#l00058">FALSE</a>, <a class="el" href="PMSM_8h-source.html#l00040">PMSMflags::motorStopped</a>, <a class="el" href="PMSM_8h-source.html#l00041">PMSMflags::motorSynchronized</a>, <a class="el" href="pid_8c-source.html#l00040">pid_Init()</a>, <a class="el" href="PMSM_8h-source.html#l00258">PID_K_D</a>, <a class="el" href="PMSM_8h-source.html#l00253">PID_K_I</a>, <a class="el" href="PMSM_8h-source.html#l00248">PID_K_P</a>, <a class="el" href="main_8c-source.html#l00255">PinChangeInit()</a>, <a class="el" href="main_8c-source.html#l00203">PLLInit()</a>, <a class="el" href="main_8c-source.html#l00187">PortsInit()</a>, <a class="el" href="main_8c-source.html#l00218">PWMInit()</a>, <a class="el" href="main_8c-source.html#l00606">SetAdvanceCommutation()</a>, <a class="el" href="PMSM_8h-source.html#l00243">SPEED_CONTROLLER_TIME_BASE</a>, <a class="el" href="main_8c-source.html#l00278">SpeedController()</a>, <a class="el" href="main_8c-source.html#l00111">speedControllerTimer</a>, and <a class="el" href="PMSM_8h-source.html#l00206">WAVEFORM_UNDEFINED</a>.<div class="fragment"><pre class="fragment"><a name="l00121"></a>00121 {<a name="l00122"></a>00122   <a class="code" href="main_8c.html#a9">PortsInit</a>();<a name="l00123"></a>00123   <a class="code" href="main_8c.html#a10">PLLInit</a>();<a name="l00124"></a>00124   <a class="code" href="main_8c.html#a11">PWMInit</a>();<a name="l00125"></a>00125   <a class="code" href="main_8c.html#a13">PinChangeInit</a>();<a name="l00126"></a>00126   <a class="code" href="main_8c.html#a12">ADCInit</a>();<a name="l00127"></a>00127 <a name="l00128"></a>00128 <span class="preprocessor">#if (SPEED_CONTROL_METHOD == SPEED_CONTROL_CLOSED_LOOP)</span><a name="l00129"></a>00129 <span class="preprocessor"></span>  <a class="code" href="pid_8c.html#a0">pid_Init</a>(<a class="code" href="PMSM_8h.

⌨️ 快捷键说明

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