📄 main_8c-source.html
字号:
<a name="l00683"></a>00683 <span class="keywordflow">if</span> ((tempFlags.<a class="code" href="structPMSMflags.html#o1">desiredDirection</a> == tempFlags.<a class="code" href="structPMSMflags.html#o0">actualDirection</a>) &&<a name="l00684"></a>00684 (tempFlags.<a class="code" href="structPMSMflags.html#o3">motorStopped</a> == <a class="code" href="pid_8h.html#a4">FALSE</a>) && (tempFlags.<a class="code" href="structPMSMflags.html#o4">motorSynchronized</a> == <a class="code" href="pid_8h.html#a4">FALSE</a>))<a name="l00685"></a>00685 {<a name="l00686"></a>00686 synchCount++;<a name="l00687"></a>00687 <span class="keywordflow">if</span> (synchCount >= <a class="code" href="PMSM_8h.html#a37">SYNCHRONIZATION_COUNT</a>)<a name="l00688"></a>00688 {<a name="l00689"></a>00689 fastFlags.<a class="code" href="structPMSMflags.html#o4">motorSynchronized</a> = <a class="code" href="pid_8h.html#a5">TRUE</a>;<a name="l00690"></a>00690 }<a name="l00691"></a>00691 }<a name="l00692"></a>00692 <span class="keywordflow">else</span><a name="l00693"></a>00693 {<a name="l00694"></a>00694 synchCount = 0;<a name="l00695"></a>00695 }<a name="l00696"></a>00696 }<a name="l00697"></a>00697 <a name="l00698"></a>00698 <a name="l00708"></a>00708 <span class="preprocessor">#pragma inline = forced</span><a name="l00709"></a><a class="code" href="main_8c.html#a31">00709</a> <span class="preprocessor"></span><span class="keyword">static</span> <a class="code" href="stdint_8h.html#a56">uint8_t</a> <a class="code" href="main_8c.html#a31">IsMotorSynchronized</a>(<span class="keywordtype">void</span>)<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 }<a name="l00713"></a>00713 <a name="l00714"></a>00714 <a name="l00722"></a>00722 <span class="preprocessor">#if (SINE_TABLE_SIZE == SINE_TABLE_SIZE_SMALL)</span><a name="l00723"></a>00723 <span class="preprocessor"></span><span class="preprocessor">#pragma inline = forced</span><a name="l00724"></a>00724 <span class="preprocessor"></span><a class="code" href="stdint_8h.html#a56">uint8_t</a> <a class="code" href="PMSM_8h.html#a83">SineTableSmallGetValue</a>(<a class="code" href="stdint_8h.html#a56">uint8_t</a> index)<a name="l00725"></a>00725 {<a name="l00726"></a>00726 <span class="comment">//The last 3rd of the table is zero.</span><a name="l00727"></a>00727 <span class="keywordflow">if</span> (index >= (<a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a> * 2 / 3) )<a name="l00728"></a>00728 {<a name="l00729"></a>00729 <span class="keywordflow">return</span> 0;<a name="l00730"></a>00730 }<a name="l00731"></a>00731 <a name="l00732"></a>00732 <span class="comment">//The second third of the table is a mirror of the first third.</span><a name="l00733"></a>00733 <span class="keywordflow">if</span> (index >= (<a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a> / 3) )<a name="l00734"></a>00734 {<a name="l00735"></a>00735 index = ((<a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a> * 2 / 3) - 1) - index;<a name="l00736"></a>00736 }<a name="l00737"></a>00737 <a name="l00738"></a>00738 <span class="keywordflow">return</span> <a class="code" href="PMSM__tables_8h.html#a0">sineTable</a>[index];<a name="l00739"></a>00739 }<a name="l00740"></a>00740 <span class="preprocessor">#endif</span><a name="l00741"></a>00741 <span class="preprocessor"></span><a name="l00742"></a>00742 <a name="l00748"></a>00748 <span class="preprocessor">#if (SINE_TABLE_SIZE == SINE_TABLE_SIZE_LARGE)</span><a name="l00749"></a>00749 <span class="preprocessor"></span><span class="preprocessor">#pragma inline = forced</span><a name="l00750"></a><a class="code" href="main_8c.html#a32">00750</a> <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a32">SineOutputUpdate</a>(<span class="keywordtype">void</span>)<a name="l00751"></a>00751 {<a name="l00752"></a>00752 <a class="code" href="stdint_8h.html#a56">uint8_t</a> <span class="keyword">const</span> __flash * sineTablePtr = <a class="code" href="PMSM__tables_8h.html#a0">sineTable</a>;<a name="l00753"></a>00753 <a class="code" href="stdint_8h.html#a58">uint16_t</a> temp;<a name="l00754"></a>00754 <a name="l00755"></a>00755 <span class="comment">//Add sine table offset to pointer. Must be multiplied by 3, since one</span><a name="l00756"></a>00756 <span class="comment">//value for each phase is stored in the table.</span><a name="l00757"></a>00757 <span class="comment">//sineTablePtr += (uint8_t)(sineTableIndex >> 8) * 3;</span><a name="l00758"></a>00758 {<a name="l00759"></a>00759 <a class="code" href="stdint_8h.html#a56">uint8_t</a> tempIndex = (<a class="code" href="stdint_8h.html#a56">uint8_t</a>)(<a class="code" href="main_8c.html#a2">sineTableIndex</a> >> 8);<a name="l00760"></a>00760 sineTablePtr += tempIndex;<a name="l00761"></a>00761 sineTablePtr += tempIndex;<a name="l00762"></a>00762 sineTablePtr += tempIndex;<a name="l00763"></a>00763 }<a name="l00764"></a>00764 <a name="l00765"></a>00765 <span class="comment">//Calculate output duty cycles. Since one phase is always zero, the scaling</span><a name="l00766"></a>00766 <span class="comment">//is only performed on the two non-zero phases, saving one multiply.</span><a name="l00767"></a>00767 <a name="l00768"></a>00768 <span class="comment">//Calculate U phase output duty cycle.</span><a name="l00769"></a>00769 temp = *sineTablePtr++;<a name="l00770"></a>00770 <span class="keywordflow">if</span> (temp != 0)<a name="l00771"></a>00771 {<a name="l00772"></a>00772 temp = <a class="code" href="main_8c.html#a36">MultiplyUS15x8</a>(<a class="code" href="main_8c.html#a4">amplitude</a>, temp);<a name="l00773"></a>00773 }<a name="l00774"></a>00774 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a23">COMPARE_REGISTER_PHASE_U</a>, temp);<a name="l00775"></a>00775 <a name="l00776"></a>00776 <span class="comment">//Calculate U + 240 degree phase output duty cycle.</span><a name="l00777"></a>00777 temp = *sineTablePtr++;<a name="l00778"></a>00778 <span class="keywordflow">if</span> (temp != 0)<a name="l00779"></a>00779 {<a name="l00780"></a>00780 temp = <a class="code" href="main_8c.html#a36">MultiplyUS15x8</a>(<a class="code" href="main_8c.html#a4">amplitude</a>, temp);<a name="l00781"></a>00781 }<a name="l00782"></a>00782 <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="l00783"></a>00783 {<a name="l00784"></a>00784 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a24">COMPARE_REGISTER_PHASE_V</a>, temp);<a name="l00785"></a>00785 }<a name="l00786"></a>00786 <span class="keywordflow">else</span><a name="l00787"></a>00787 {<a name="l00788"></a>00788 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a25">COMPARE_REGISTER_PHASE_W</a>, temp);<a name="l00789"></a>00789 }<a name="l00790"></a>00790 <a name="l00791"></a>00791 <span class="comment">//Calculate U + 120 degree phase output duty cycle.</span><a name="l00792"></a>00792 temp = *sineTablePtr++;<a name="l00793"></a>00793 <span class="keywordflow">if</span> (temp != 0)<a name="l00794"></a>00794 {<a name="l00795"></a>00795 temp = <a class="code" href="main_8c.html#a36">MultiplyUS15x8</a>(<a class="code" href="main_8c.html#a4">amplitude</a>, temp);<a name="l00796"></a>00796 }<a name="l00797"></a>00797 <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="l00798"></a>00798 {<a name="l00799"></a>00799 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a25">COMPARE_REGISTER_PHASE_W</a>, temp);<a name="l00800"></a>00800 }<a name="l00801"></a>00801 <span class="keywordflow">else</span><a name="l00802"></a>00802 {<a name="l00803"></a>00803 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a24">COMPARE_REGISTER_PHASE_V</a>, temp);<a name="l00804"></a>00804 }<a name="l00805"></a>00805 }<a name="l00806"></a>00806 <span class="preprocessor">#endif</span><a name="l00807"></a>00807 <span class="preprocessor"></span><a name="l00808"></a>00808 <a name="l00814"></a>00814 <span class="preprocessor">#if (SINE_TABLE_SIZE == SINE_TABLE_SIZE_SMALL)</span><a name="l00815"></a>00815 <span class="preprocessor"></span><span class="preprocessor">#pragma inline = forced</span><a name="l00816"></a>00816 <span class="preprocessor"></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code" href="main_8c.html#a32">SineOutputUpdate</a>(<span class="keywordtype">void</span>)<a name="l00817"></a>00817 {<a name="l00818"></a>00818 <a class="code" href="stdint_8h.html#a58">uint16_t</a> temp;<a name="l00819"></a>00819 <a class="code" href="stdint_8h.html#a56">uint8_t</a> tempIndex;<a name="l00820"></a>00820 <a name="l00821"></a>00821 <span class="comment">//Calculate U phase output duty cycle.</span><a name="l00822"></a>00822 tempIndex = (<a class="code" href="stdint_8h.html#a56">uint8_t</a>)(<a class="code" href="main_8c.html#a2">sineTableIndex</a> >> 8);<a name="l00823"></a>00823 <a name="l00824"></a>00824 temp = <a class="code" href="PMSM_8h.html#a83">SineTableSmallGetValue</a>(tempIndex);<a name="l00825"></a>00825 <span class="keywordflow">if</span> (temp != 0)<a name="l00826"></a>00826 {<a name="l00827"></a>00827 temp = <a class="code" href="main_8c.html#a36">MultiplyUS15x8</a>(<a class="code" href="main_8c.html#a4">amplitude</a>, temp);<a name="l00828"></a>00828 }<a name="l00829"></a>00829 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a23">COMPARE_REGISTER_PHASE_U</a>, temp);<a name="l00830"></a>00830 <a name="l00831"></a>00831 <span class="comment">//Calculate U phase + 120 degree output duty cycle.</span><a name="l00832"></a>00832 tempIndex += (<a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a> / 3);<a name="l00833"></a>00833 <span class="keywordflow">if</span> (tempIndex >= <a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a>)<a name="l00834"></a>00834 {<a name="l00835"></a>00835 tempIndex -= <a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a>;<a name="l00836"></a>00836 }<a name="l00837"></a>00837 <a name="l00838"></a>00838 temp = <a class="code" href="PMSM_8h.html#a83">SineTableSmallGetValue</a>(tempIndex);<a name="l00839"></a>00839 <span class="keywordflow">if</span> (temp != 0)<a name="l00840"></a>00840 {<a name="l00841"></a>00841 temp = <a class="code" href="main_8c.html#a36">MultiplyUS15x8</a>(<a class="code" href="main_8c.html#a4">amplitude</a>, temp);<a name="l00842"></a>00842 }<a name="l00843"></a>00843 <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="l00844"></a>00844 {<a name="l00845"></a>00845 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a25">COMPARE_REGISTER_PHASE_W</a>, temp);<a name="l00846"></a>00846 }<a name="l00847"></a>00847 <span class="keywordflow">else</span><a name="l00848"></a>00848 {<a name="l00849"></a>00849 <a class="code" href="TinyX61__macros_8h.html#a12">TC1_WRITE_10_BIT_REGISTER</a>(<a class="code" href="PMSM_8h.html#a24">COMPARE_REGISTER_PHASE_V</a>, temp);<a name="l00850"></a>00850 }<a name="l00851"></a>00851 <a name="l00852"></a>00852 <span class="comment">//Calculate U phase + 240 degree output duty cycle.</span><a name="l00853"></a>00853 tempIndex += (<a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a> / 3);<a name="l00854"></a>00854 <span class="keywordflow">if</span> (tempIndex >= <a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a>)<a name="l00855"></a>00855 {<a name="l00856"></a>00856 tempIndex -= <a class="code" href="PMSM_8h.html#a30">SINE_TABLE_LENGTH</a>;<a name="l00857"></a>00857 }<a name="l00858"></a>00858
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -