【AutoChips AC7801x电机demo板测评】+关键外设测试-HALL采集
本帖最后由 我爱下载 于 2020-12-5 12:15 编辑<p class="MsoTitle" style="text-align:center; margin-top:16px; margin-bottom:4px"><span style="font-size:16pt"><span style="font-family:Cambria,serif"><span style="font-weight:bold"><span style="font-family:宋体">关键外设测试</span></span></span></span></p>
<p style="text-align: center;"><span style="font-size:16pt"><span style="line-height:130%"><span style="font-family:Cambria,serif"><span style="font-weight:bold"><span style="font-family:宋体">——</span>HALL<span style="font-family:宋体">接口的测试</span></span></span></span></span></p>
<p> </p>
<p> </p>
<p> </p>
<ol>
<li><span style="font-size:16pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="font-weight:normal">硬件接口</span></span></span></span></li>
</ol>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif"">如前述所描述,系统主板集成了一个</span>HALL<span style="font-family:"微软雅黑","sans-serif"">接口,允许输入电机的位置传感器信号。</span></span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif"">根据数据手册和原理图中的描述,可以知道,线路板采用</span>PWDT1<span style="font-family:"微软雅黑","sans-serif"">作为霍尔元件的输出采集端,连接到</span>PC6<span style="font-family:"微软雅黑","sans-serif"">、</span>PC7<span style="font-family:"微软雅黑","sans-serif"">、</span>PC8<span style="font-family:"微软雅黑","sans-serif"">三个引脚。当然,还有</span>5V<span style="font-family:"微软雅黑","sans-serif"">电源和地。</span></span></span></p>
<p> </p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
<ol start="2">
<li><span style="font-size:16pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="font-weight:normal">软件设置</span></span></span></span> </li>
</ol>
<ul>
<li><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="font-weight:normal">PWDT模块</span></span></span></span></li>
</ul>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">AC7801x<span style="font-family:"微软雅黑","sans-serif"">控制器内部集成了</span>PWDT<span style="font-family:"微软雅黑","sans-serif"">外设,可以用来采集霍尔信号的输入,可以输出霍尔状态,霍尔输入信号高低电平的时间,从而求出霍尔信号的频率,占空比等信号。</span></span></span></p>
<p> </p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> PWDT<span style="font-family:"微软雅黑","sans-serif"">的机构框图</span></span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif""> 霍尔测量模式</span></span></span></p>
<p> </p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif""> 两种常见的</span>Hall<span style="font-family:"微软雅黑","sans-serif"">安装方式</span></span></span></p>
<p> </p>
<p> </p>
<p> </p>
<ul>
<li><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="font-weight:normal">配置PWDT模块</span></span></span></span></li>
</ul>
<p> </p>
<p> </p>
<p></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"></p>
<p> </p>
<p> </p>
<ul>
<li><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> <span style="font-family:"微软雅黑","sans-serif"">生成的初始化代码</span></span></span></li>
</ul>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">/* PWDT1 init function */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">static void ATC_PWDT1_Init(void)</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">{</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN PWDT1_Init 0 */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END PWDT1_Init 0 */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> PWDT_ConfigType pwdtConfig;</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN PWDT1_Init 1 */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END PWDT1_Init 1 */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> MSP_PWDT_Init(PWDT1);</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.clkPsc = PWDT_CLK_PRESCALER_1;</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.edgeType = PWDT_RISING_START_CAPTURE_ALL;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.channel = PWDT_INPUT_CH_0;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.overflowInterruptEn = ENABLE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.readyInterruptEn = ENABLE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.interruptEn = ENABLE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.cmpModeEn = DISABLE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.mode = PWDT_MEASURE_MODE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.hallModeEn = ENABLE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.filterPsc = PWDT_FILTER_PRESCALER_1;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.filterValue = 10;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.filterEn = ENABLE;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> pwdtConfig.callBack = PWDT1_IRQHandler_Callback;</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> PWDT_Init(PWDT1, &pwdtConfig);</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN PWDT1_Init 2 */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END PWDT1_Init 2 */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">}</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif"">生成的中断处理函数</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">/**</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">* <a href="home.php?mod=space&uid=159083" target="_blank">@brief</a> This function handle PWDT1 interrupt.</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">* @param device: PWDT_Type pointer</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">* @param wpara: callback parameter</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">* @param lpara: callback parameter</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">* <a href="home.php?mod=space&uid=784970" target="_blank">@return</a> none</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">*/</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">void PWDT1_IRQHandler_Callback(void *device, uint32_t wpara, uint32_t lpara)</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">{</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> if (wpara & PWDT_INIT0_OVF_Msk)</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> {</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN OVERFLOW INTERRUPT */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END OVERFLOW INTERRUPT */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> }</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> if (wpara & PWM_STR_CHSF_Msk)</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> {</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN PLUSE PLUSE EFFECTIVE */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END PLUSE PLUSE EFFECTIVE */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> }</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN PWDT1_IRQHandler_Callback */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END PWDT1_IRQHandler_Callback */</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif">}</span></span></p>
<p> </p>
<p> </p>
<p> </p>
<ul>
<li><span style="font-size:14pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="font-weight:normal">处理函数</span></span></span></span></li>
</ul>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE BEGIN PLUSE PLUSE EFFECTIVE */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> g_hallStatus = PWDT_GetHallStatus(PWDT) & 0x07;</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> g_positvePulse = PWDT_GetPositivePulseWidth(PWDT); //<span style="font-family:"微软雅黑","sans-serif"">获取正脉宽计数值</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> g_negativePulse = PWDT_GetNegativePulseWidth(PWDT); //<span style="font-family:"微软雅黑","sans-serif"">获取负脉宽计数值</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> if (0 != (g_positvePulse + g_negativePulse))</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> {</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /*</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> <span style="font-family:"微软雅黑","sans-serif"">计算频率和占空比</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> <span style="font-family:"微软雅黑","sans-serif"">频率</span> = PWDT<span style="font-family:"微软雅黑","sans-serif"">时钟源</span> / PWDT<span style="font-family:"微软雅黑","sans-serif"">时钟分频</span> / <span style="font-family:"微软雅黑","sans-serif"">正</span>+<span style="font-family:"微软雅黑","sans-serif"">负脉宽计数值</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> <span style="font-family:"微软雅黑","sans-serif"">占空比</span> = <span style="font-family:"微软雅黑","sans-serif"">正脉宽计数值</span> / <span style="font-family:"微软雅黑","sans-serif"">正</span>+<span style="font-family:"微软雅黑","sans-serif"">负脉宽计数值</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> */</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> g_freq = PWDT_CLK / (g_positvePulse + g_negativePulse);</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> g_duty = ((g_positvePulse * 100)/ (g_positvePulse + g_negativePulse)); </span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> }</span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"> /* USER CODE END PLUSE PLUSE EFFECTIVE */</span></span> </p>
<p> </p>
<p> </p>
<ol start="3"><br />
<li><span style="font-size:16pt"><span style="line-height:150%"><span style="font-family:宋体"><span style="font-weight:normal">效果展示</span></span></span></span></li>
</ol>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif"">电机霍尔线的硬件连接图</span></span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"></p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-left:28px; margin-bottom:13px"><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif"">利用</span>uart<span style="font-family:"微软雅黑","sans-serif"">端口将霍尔信号</span> <span style="font-family:"微软雅黑","sans-serif"">的输入状态打印到串口终端中。通过终端打印可以清晰的看到霍尔信号的变化过程为</span>1-5-4-6-2-3<span style="font-family:"微软雅黑","sans-serif"">。</span></span></span></p>
<p> </p>
<p> </p>
<p><span style="font-size:11pt"><span style="font-family:Tahoma,sans-serif"><span style="font-family:"微软雅黑","sans-serif"">结论,通过对于特定电机及预想的电机转速测量范围,可以进一步调整</span>PWDT<span style="font-family:"微软雅黑","sans-serif"">的预分频系数,来保证转速测量范围。</span></span></span></p>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<p style="margin-bottom:13px"> </p>
<p> </p>
<p> </p>
<p>还不错,知识点讲的挺好,就喜欢这种分享知识和代码的帖子!</p>
w494143467 发表于 2020-12-5 13:34
还不错,知识点讲的挺好,就喜欢这种分享知识和代码的帖子!
<p>谢谢鼓励,继续努力,共同学习</p>
<p>谢谢分享</p>
<p>谢谢分享</p>
页:
[1]