📄 main_8c.html
字号:
<p> </td> </tr></table><a class="anchor" name="a29"></a><!-- doxytag: member="main.c::CalculateSpeed" ref="a29" 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">static unsigned long CalculateSpeed </td> <td class="md" valign="top">( </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>Calculates the current speed in electrical RPM. <p>This function calculates the current speed in electrical rotations per minute from the global variable <a class="el" href="main_8c.html#a3">filteredTimeSinceCommutation</a>.<p>Definition at line <a class="el" href="main_8c-source.html#l00672">672</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="main_8c-source.html#l00042">filteredTimeSinceCommutation</a>, and <a class="el" href="BLDC_8h-source.html#l00243">TICKS_PER_MINUTE</a>.<div class="fragment"><pre class="fragment"><a name="l00673"></a>00673 {<a name="l00674"></a>00674 <span class="comment">// Copy used to minimize period where interrupts are disabled.</span><a name="l00675"></a>00675 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> filteredTimeSinceCommutationCopy;<a name="l00676"></a>00676 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> rotationPeriod;<a name="l00677"></a>00677 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> speed;<a name="l00678"></a>00678 <a name="l00679"></a>00679 <span class="comment">/*</span><a name="l00680"></a>00680 <span class="comment"> Disable interrupts to ensure that \ref filteredTimeSinceCommutation is accessed in</span><a name="l00681"></a>00681 <span class="comment"> an atomic operation.</span><a name="l00682"></a>00682 <span class="comment"> */</span><a name="l00683"></a>00683 __disable_interrupt();<a name="l00684"></a>00684 filteredTimeSinceCommutationCopy = <a class="code" href="main_8c.html#a3">filteredTimeSinceCommutation</a>;<a name="l00685"></a>00685 __enable_interrupt();<a name="l00686"></a>00686 <a name="l00687"></a>00687 <span class="comment">/*</span><a name="l00688"></a>00688 <span class="comment"> filteredTimeSinceCommutation is one half commutation time. Must be multiplied by 12 to get</span><a name="l00689"></a>00689 <span class="comment"> one full rotation.</span><a name="l00690"></a>00690 <span class="comment"> */</span><a name="l00691"></a>00691 rotationPeriod = (<span class="keywordtype">unsigned</span> long)filteredTimeSinceCommutationCopy * 12;<a name="l00692"></a>00692 speed = (<a class="code" href="BLDC_8h.html#a68">TICKS_PER_MINUTE</a> / rotationPeriod);<a name="l00693"></a>00693 <a name="l00694"></a>00694 <span class="keywordflow">return</span> speed;<a name="l00695"></a>00695 }</pre></div><p> </td> </tr></table><a class="anchor" name="a30"></a><!-- doxytag: member="main.c::CalculateSpeedSetpoint" ref="a30" 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">static unsigned long CalculateSpeedSetpoint </td> <td class="md" valign="top">( </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>Calculates the speed set-point in electrical RPM. <p>This function calculates the speed set-point from the global variable speedReferenceADC.<p>In this implementation, the speed reference values from 0x00 to 0xff are linearly mapped into the allowable speed range, set by <a class="el" href="BLDC_8h.html#a82">MIN_SPEED</a> and <a class="el" href="BLDC_8h.html#a83">MAX_SPEED</a>.<p>Definition at line <a class="el" href="main_8c-source.html#l00707">707</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="BLDC_8h-source.html#l00234">ADC_RESOLUTION</a>, <a class="el" href="BLDC_8h-source.html#l00308">MAX_SPEED</a>, <a class="el" href="BLDC_8h-source.html#l00305">MIN_SPEED</a>, and <a class="el" href="main_8c-source.html#l00068">speedReferenceADC</a>.<div class="fragment"><pre class="fragment"><a name="l00708"></a>00708 {<a name="l00709"></a>00709 <span class="keywordflow">return</span> (<a class="code" href="BLDC_8h.html#a82">MIN_SPEED</a> + ((<a class="code" href="BLDC_8h.html#a83">MAX_SPEED</a> - <a class="code" href="BLDC_8h.html#a82">MIN_SPEED</a>) * (<span class="keywordtype">unsigned</span> <span class="keywordtype">int</span>)<a class="code" href="main_8c.html#a7">speedReferenceADC</a>) / <a class="code" href="BLDC_8h.html#a66">ADC_RESOLUTION</a>);<a name="l00710"></a>00710 }</pre></div><p> </td> </tr></table><a class="anchor" name="a22"></a><!-- doxytag: member="main.c::Commutate" ref="a22" 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 Commutate </td> <td class="md" valign="top">( </td> <td class="mdname1" valign="top" nowrap> </td> <td class="md" valign="top"> ) </td> <td class="md" nowrap></td> </tr> </table> </td> </tr></table><table cellspacing="5" cellpadding="0" border="0"> <tr> <td> </td> <td><p>Commutates and prepares for new zero-cross detection. <p>This interrupt service routine is triggered exactly when a commutation is scheduled. The commutation is performed instantly and Timer/counter0 is reset to measure the delay between commutation and zero-cross detection.<p>Commutation causes large transients on all phases for a short while that could cause false zero-cross detections. A zero cross detection hold-off period is therefore used to avoid any false readings. This is performed by using Timer/counter1 compare B. The compare is set to happen after the specified hold-off period. Timer/counter1 compare B interrupt handler then enables the zero-cross detection.<p>Definition at line <a class="el" href="main_8c-source.html#l00482">482</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="BLDC_8h-source.html#l00216">CLEAR_ALL_TIMER1_INT_FLAGS</a>, <a class="el" href="BLDC_8h-source.html#l00114">DRIVE_PORT</a>, <a class="el" href="main_8c-source.html#l00065">nextCommutationStep</a>, <a class="el" href="main_8c-source.html#l00050">nextDrivePattern</a>, <a class="el" href="BLDC_8h-source.html#l00225">SET_TIMER1_INT_HOLDOFF</a>, <a class="el" href="BLDC_8h-source.html#l00201">ZC_DETECTION_HOLDOFF_TIME_US</a>, and <a class="el" href="main_8c-source.html#l00057">zcPolarity</a>.<div class="fragment"><pre class="fragment"><a name="l00483"></a>00483 {<a name="l00484"></a>00484 <span class="comment">// Commutate and clear commutation timer.</span><a name="l00485"></a>00485 <a class="code" href="BLDC_8h.html#a28">DRIVE_PORT</a> = <a class="code" href="main_8c.html#a4">nextDrivePattern</a>;<a name="l00486"></a>00486 TCNT1 = 0;<a name="l00487"></a>00487 <a name="l00488"></a>00488 <a class="code" href="main_8c.html#a5">zcPolarity</a> = <a class="code" href="main_8c.html#a6">nextCommutationStep</a> & 0x01;<a name="l00489"></a>00489 <a name="l00490"></a>00490 <span class="comment">// Set zero-cross detection holdoff time.</span><a name="l00491"></a>00491 <a class="code" href="BLDC_8h.html#a60">CLEAR_ALL_TIMER1_INT_FLAGS</a>;<a name="l00492"></a>00492 OCR1B = <a class="code" href="BLDC_8h.html#a55">ZC_DETECTION_HOLDOFF_TIME_US</a>;<a name="l00493"></a>00493 <a class="code" href="BLDC_8h.html#a63">SET_TIMER1_INT_HOLDOFF</a>;<a name="l00494"></a>00494 <a name="l00495"></a>00495 __watchdog_reset();<a name="l00496"></a>00496 }</pre></div><p> </td> </tr></table><a class="anchor" name="a33"></a><!-- doxytag: member="main.c::CurrentControl" ref="a33" 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 unsigned char CurrentControl </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>Current control loop. <p>This function is called after the speed control loop. The desired duty cycle calculated by the speed control loop is available, and this function is responsible for adjusting the duty cycle to ensure that the current stays within limits.<p>Definition at line <a class="el" href="main_8c-source.html#l00767">767</a> of file <a class="el" href="main_8c-source.html">main.c</a>.<p>References <a class="el" href="BLDC_8h.html#a98">CalculateCurrent()</a>, <a class="el" href="BLDC_8h-source.html#l00269">CURRENT_LIMITER_CRITICAL</a>, <a class="el" href="BLDC_8h-source.html#l00281">CURRENT_LIMITER_FACTOR</a>, <a class="el" href="BLDC_8h-source.html#l00266">CURRENT_LIMITER_START</a>, and <a class="el" href="BLDC_8h-source.html#l00114">DRIVE_PORT</a>.<div class="fragment"><pre class="fragment"><a name="l00768"></a>00768 {<a name="l00769"></a>00769 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> current;<a name="l00770"></a>00770 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> overCurrentCorrection = 0;<a name="l00771"></a>00771 <a name="l00772"></a>00772 current = <a class="code" href="BLDC_8h.html#a98">CalculateCurrent</a>();<a name="l00773"></a>00773 <a name="l00774"></a>00774 <span class="comment">// Cut power to motor if current is critically high.</span><a name="l00775"></a>00775 <span class="keywordflow">if</span> (current > <a class="code" href="BLDC_8h.html#a73">CURRENT_LIMITER_CRITICAL</a>)<a name="l00776"></a>00776 {<a name="l00777"></a>00777 <a class="code" href="BLDC_8h.html#a28">DRIVE_PORT</a> = 0x00;<a name="l00778"></a>00778 <span class="keywordflow">for</span> (;;)<a name="l00779"></a>00779 {<a name="l00780"></a>00780 <span class="comment">// Stop and let watchdog timer reset part.</span>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -