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

📄 sm__driver_8h.html

📁 使用AVR单片机控制步进电机的软件代码
💻 HTML
📖 第 1 页 / 共 2 页
字号:
</table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p><p>Definition at line <a class="el" href="sm__driver_8h-source.html#l00042">42</a> of file <a class="el" href="sm__driver_8h-source.html">sm_driver.h</a>.<p>Referenced by <a class="el" href="sm__driver_8c-source.html#l00049">sm_driver_Init_IO()</a>.    </td>  </tr></table><a class="anchor" name="a3" doxytag="sm_driver.h::SM_PORT" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> #define SM_PORT&nbsp;&nbsp;&nbsp;PORTD          </td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Define IO port and pins<p>Set the desired drive port and pins to support your device <p>Definition at line <a class="el" href="sm__driver_8h-source.html#l00041">41</a> of file <a class="el" href="sm__driver_8h-source.html">sm_driver.h</a>.<p>Referenced by <a class="el" href="sm__driver_8c-source.html#l00049">sm_driver_Init_IO()</a>, and <a class="el" href="sm__driver_8c-source.html#l00108">sm_driver_StepOutput()</a>.    </td>  </tr></table><hr><h2>Function Documentation</h2><a class="anchor" name="a10" doxytag="sm_driver.h::sm_driver_Init_IO" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> void sm_driver_Init_IO           </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>Init of io-pins for stepper motor. <p><p>Definition at line <a class="el" href="sm__driver_8c-source.html#l00049">49</a> of file <a class="el" href="sm__driver_8c-source.html">sm_driver.c</a>.<p>References <a class="el" href="sm__driver_8h-source.html#l00043">A1</a>, <a class="el" href="sm__driver_8h-source.html#l00044">A2</a>, <a class="el" href="sm__driver_8h-source.html#l00045">B1</a>, <a class="el" href="sm__driver_8h-source.html#l00046">B2</a>, <a class="el" href="sm__driver_8h-source.html#l00042">SM_DRIVE</a>, and <a class="el" href="sm__driver_8h-source.html#l00041">SM_PORT</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00042">Init()</a>.<p><pre class="fragment"><div>00050 {00051   <span class="comment">// Init of IO pins</span>00052   <a class="code" href="sm__driver_8h.html#a3">SM_PORT</a> &amp;= ~((1&lt;&lt;<a class="code" href="sm__driver_8h.html#a5">A1</a>) | (1&lt;&lt;<a class="code" href="sm__driver_8h.html#a6">A2</a>) | (1&lt;&lt;<a class="code" href="sm__driver_8h.html#a7">B1</a>) | (1&lt;&lt;<a class="code" href="sm__driver_8h.html#a8">B2</a>)); <span class="comment">// Set output pin registers to zero</span>00053   <a class="code" href="sm__driver_8h.html#a4">SM_DRIVE</a> |= ((1&lt;&lt;<a class="code" href="sm__driver_8h.html#a5">A1</a>) | (1&lt;&lt;<a class="code" href="sm__driver_8h.html#a6">A2</a>) | (1&lt;&lt;<a class="code" href="sm__driver_8h.html#a7">B1</a>) | (1&lt;&lt;<a class="code" href="sm__driver_8h.html#a8">B2</a>)); <span class="comment">// Set output pin direction registers to output</span>00054 }</div></pre>    </td>  </tr></table><a class="anchor" name="a11" doxytag="sm_driver.h::sm_driver_StepCounter" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> unsigned char sm_driver_StepCounter           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">signed char&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>inc</em>          </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>Move the stepper motor one step. <p>Makes the stepcounter inc/dec one value and outputs this to the steppermotor. This function works like a stepper motor controller, a call to the function is the stepping pulse, and parameter 'inc' is the direction signal.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td></td><td valign=top><em>inc</em>&nbsp;</td><td>Direction to move. </td></tr>  </table></dl><dl compact><dt><b>Returns:</b></dt><dd>Stepcounter value. </dd></dl><p>Definition at line <a class="el" href="sm__driver_8c-source.html#l00066">66</a> of file <a class="el" href="sm__driver_8c-source.html">sm_driver.c</a>.<p>References <a class="el" href="sm__driver_8h-source.html#l00026">CCW</a>, <a class="el" href="sm__driver_8c-source.html#l00108">sm_driver_StepOutput()</a>, and <a class="el" href="sm__driver_8c-source.html#l00045">stepPosition</a>.<p>Referenced by <a class="el" href="speed__cntr_8c-source.html#l00164">speed_cntr_TIMER1_COMPA_interrupt()</a>.<p><pre class="fragment"><div>00067 {00068   <span class="comment">// Counts 0-1-...-6-7 in halfstep, 0-2-4-6 in fullstep</span>00069   <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> counter = 0;00070   <span class="comment">// Update</span>00071   <span class="keywordflow">if</span>(inc == <a class="code" href="sm__driver_8h.html#a1">CCW</a>){00072     <a class="code" href="sm__driver_8c.html#a5">stepPosition</a>--;00073   }00074   <span class="keywordflow">else</span>{00075     <a class="code" href="sm__driver_8c.html#a5">stepPosition</a>++;00076   }00077 00078 <span class="preprocessor">#ifdef HALFSTEPS</span>00079 <span class="preprocessor"></span>  <span class="keywordflow">if</span>(inc){00080     counter++;00081   }00082   <span class="keywordflow">else</span>{00083     counter--;00084   }00085 <span class="preprocessor">#else</span>00086 <span class="preprocessor"></span>  <span class="keywordflow">if</span>(inc){00087     counter += 2;00088   }00089   <span class="keywordflow">else</span>{00090     counter -= 2;00091   }00092 <span class="preprocessor">#endif</span>00093 <span class="preprocessor"></span>00094   <span class="comment">// Stay within the steptab</span>00095   counter &amp;= 0x07;00096   <a class="code" href="sm__driver_8h.html#a12">sm_driver_StepOutput</a>(counter);00097   <span class="keywordflow">return</span>(counter);00098 }</div></pre><p>Here is the call graph for this function:<p><center><img src="sm__driver_8h_a11_cgraph.png" border="0" usemap="#sm__driver_8h_a11_cgraph_map" alt=""></center><map name="sm__driver_8h_a11_cgraph_map"><area href="sm__driver_8h.html#a12" shape="rect" coords="220,7,377,33" alt=""></map>    </td>  </tr></table><a class="anchor" name="a12" doxytag="sm_driver.h::sm_driver_StepOutput" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> void sm_driver_StepOutput           </td>          <td class="md" valign="top">(&nbsp;</td>          <td class="md" nowrap valign="top">unsigned char&nbsp;</td>          <td class="mdname1" valign="top" nowrap> <em>pos</em>          </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>Convert the stepcounter value to signals for the stepper motor. <p>Uses the stepcounter value as index in steptab to get correct steppermotor control signals. Converts these signals to work with the stepper driver hardware.<p><dl compact><dt><b>Parameters:</b></dt><dd>  <table border="0" cellspacing="2" cellpadding="0">    <tr><td></td><td valign=top><em>pos</em>&nbsp;</td><td>Stepcounter value. </td></tr>  </table></dl><p>Definition at line <a class="el" href="sm__driver_8c-source.html#l00108">108</a> of file <a class="el" href="sm__driver_8c-source.html">sm_driver.c</a>.<p>References <a class="el" href="sm__driver_8h-source.html#l00041">SM_PORT</a>, and <a class="el" href="sm__driver_8c-source.html#l00035">steptab</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00042">Init()</a>, and <a class="el" href="sm__driver_8c-source.html#l00066">sm_driver_StepCounter()</a>.<p><pre class="fragment"><div>00109 {00110   <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> temp = <a class="code" href="sm__driver_8c.html#a4">steptab</a>[pos];00111 00112   <span class="comment">/*</span>00113 <span class="comment">  // Output bit by bit</span>00114 <span class="comment">  if(temp&amp;(1&lt;&lt;BIT_A1))</span>00115 <span class="comment">    SM_PORT |= (1&lt;&lt;A1);</span>00116 <span class="comment">  else</span>00117 <span class="comment">    SM_PORT &amp;= ~(1&lt;&lt;A1);</span>00118 <span class="comment"></span>00119 <span class="comment">  if(temp&amp;(1&lt;&lt;BIT_A2))</span>00120 <span class="comment">    SM_PORT |= (1&lt;&lt;A2);</span>00121 <span class="comment">  else</span>00122 <span class="comment">    SM_PORT &amp;= ~(1&lt;&lt;A2);</span>00123 <span class="comment"></span>00124 <span class="comment">  if(temp&amp;(1&lt;&lt;BIT_B1))</span>00125 <span class="comment">    SM_PORT |= (1&lt;&lt;B1);</span>00126 <span class="comment">  else</span>00127 <span class="comment">    SM_PORT &amp;= ~(1&lt;&lt;B1);</span>00128 <span class="comment"></span>00129 <span class="comment">  if(temp&amp;(1&lt;&lt;BIT_B2))</span>00130 <span class="comment">    SM_PORT |= (1&lt;&lt;B2);</span>00131 <span class="comment">  else</span>00132 <span class="comment">    SM_PORT &amp;= ~(1&lt;&lt;B2);</span>00133 <span class="comment">  */</span>00134 00135   <span class="comment">// Output the fast way</span>00136   <a class="code" href="sm__driver_8h.html#a3">SM_PORT</a> |= ((temp&lt;&lt;4)&amp;0xF0);00137   <a class="code" href="sm__driver_8h.html#a3">SM_PORT</a> &amp;= ((temp&lt;&lt;4)|0x0F);00138 }</div></pre>    </td>  </tr></table><hr><h2>Variable Documentation</h2><a class="anchor" name="a9" doxytag="sm_driver.h::stepPosition" ></a><p><table class="mdTable" width="100%" cellpadding="2" cellspacing="0">  <tr>    <td class="mdRow">      <table cellpadding="0" cellspacing="0" border="0">        <tr>          <td class="md" nowrap valign="top"> int <a class="el" href="sm__driver_8h.html#a9">stepPosition</a>          </td>        </tr>      </table>    </td>  </tr></table><table cellspacing=5 cellpadding=0 border=0>  <tr>    <td>      &nbsp;    </td>    <td><p>Position of stepper motor. <p><p>Definition at line <a class="el" href="sm__driver_8h-source.html#l00053">53</a> of file <a class="el" href="sm__driver_8h-source.html">sm_driver.h</a>.<p>Referenced by <a class="el" href="main_8c-source.html#l00062">main()</a>, and <a class="el" href="sm__driver_8c-source.html#l00066">sm_driver_StepCounter()</a>.    </td>  </tr></table><hr size="1"><address style="align: right;"><small>Generated on Mon May 8 15:05:04 2006 for AVR446 - Linear speed control of stepper motor by<a href="http://www.doxygen.org/index.html"><img src="doxygen.png" alt="doxygen" align="middle" border=0 ></a> 1.3.7 </small></address></body></html>

⌨️ 快捷键说明

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