国产FPGA高云GW1N-4系列开发板测评之——步进电机控制(改)
本帖最后由 打破传统 于 2022-1-24 16:13 编辑<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">上一篇实现了步进电机的简单正转反转,后来想一下之前调试通过了UART,做个用上位机控制步进电机实现精确控制步进电机的转动角度。</span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span lang="EN-US" style="font-size:14.0pt"><span style="font-family:宋体">28BYJ48 </span></span><span style="font-size:14.0pt"><span style="font-family:宋体">步进电机的减速比是1:64,步进角为5.625/64度,所以对应于4拍驱动,每拍转动角度为5.625/32度,4拍转动5.625/8度。</span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">那么我们以4拍转动的角度为最小转动单元,则转一圈需要512个4拍。</span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span lang="EN-US" style="font-size:14.0pt"><span style="font-family:宋体">UART</span></span><span style="font-size:14.0pt"><span style="font-family:宋体">传输8bit数据,我们先定一个简单的协议,最高Bit位1表示正转,0表示反转。低bit位表示步数。</span></span></span></span></span></p>
<p><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">接下来修改代码:</span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">由于传输的数据bit位反转,这里要处理一下如上图,代码在附件中。</span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">编译没问题后修改testbench,仿真一下看看结果:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:14.0pt"><span style="font-family:宋体">接下来分配管脚,添加时钟约束:</span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">编译后搭好电路上板测试:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span lang="EN-US" style="font-size:14.0pt"><span style="font-family:宋体">UART</span></span><span style="font-size:14.0pt"><span style="font-family:宋体">收发数据01正常但是步进电机没有转动不正常,查了一下testbench中没有仿真到01的情况,于是试试加入嵌入式逻辑(当然也可以修改testbench),分析看看:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">编译好工程下载:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"> </p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">看到上图中为1步时状态快速变化到0,查找代码需要添加一个逻辑如下:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">修改后重新编译再看:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">正常,测试了一下正反转都正常,最大一次步进127步。</span></span></span></span></span></p>
<p style="text-align:justify"><span style="font-size:10.5pt"><span style="font-family:等线"><span style="text-justify:inter-ideograph"><span style="font-size:14.0pt"><span style="font-family:宋体">至此通过串口控制步进电机小工程完成,展示如下动图:</span></span></span></span></span></p>
<p style="text-align:justify"></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="text-align:justify"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="text-align:justify"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="text-align:justify"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="text-align:justify"> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="text-align:justify"> </p>
<p> </p>
<p> </p>
<p>不错。</p>
<p>看来先做一个内部协议很重要</p>
<p>减速比 :1/64,也就是内部的轴转一圈,外部的轴只转5.625度,5.625=360/64。</p>
页:
[1]