【DigiKey 评测之ST应用于车窗升降的L99H92直流电机驱动】硬件搭建与软件初步
<div class='showpostmsg'><p>上期研究了L99H92 的开发板AEK-MOT-WINH92 与STM32NUCLEO-G474RE 的板载资源,今天分享了STM32 NUCLEO-G474RE Arduino 驱动L99H92 以全桥模式驱动DC 直流电机做相关测试;</p><p> </p>
<p>一、硬件连接:</p>
<p> 应用原理图上可以知道,全桥的DC 驱动电路图如下:</p>
<p> </p>
<p>其中EN, DIAGN,DIR,PWM.FSINB 为输入输出控制与反馈脚, SPI(CS,CLK,SDI,SDO)为输入输出控制通讯,5V和GND 供电;</p>
<p>采用12V DC 输入,驱动12V DC 直流电机;</p>
<p>本程序主要采用Arduino 来驱动L99H92, STM32NUCLEO-G474RE 已经支持Arduino ,具体引脚如下:</p>
<p> </p>
<p> </p>
<p> </p>
<p>选中管脚与硬件连接如下所示:</p>
<table style="border-collapse:collapse" width="920">
<colgroup>
<col span="4" width="230" />
</colgroup>
<tbody>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:4px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CS</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:4px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN5-3</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:4px solid white; border-right:1px solid white; border-left:1px solid white">
<p >PWM/CS/D10</p>
</td>
<td rowspan="4" style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:4px solid white; border-right:1px solid white; border-left:1px solid white">
<p >需要配置为CPOL = 0 and CPHA = 0,且MSB 高优先</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CLK</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN5-6</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >SCK/D13</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >SDI/MISO</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN5-5</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >MISO/D12</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >SDO/MOSI</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN5-4</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >PWM/MOSI/D11</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >EN</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN9-3</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >输出/D2</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >L99H92 使能,高有效</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >DIAGN</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN9-4</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >主控芯片输入/D3</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >诊断输出引脚</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >DIR/IN2</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN9-5</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >输出/D4</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >全桥模式下方向控制</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >PWM/IN1</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN9-6</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >PWM/D5</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >占空比控制</p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >FSINB</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN9-7</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >D6</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p > </p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >VDD</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN6-5</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >5V</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#f3f9fa; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p > </p>
</td>
</tr>
<tr>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >GND</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >CN6-6</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p >GND</p>
</td>
<td style="border-bottom:1px solid white; vertical-align:top; background-color:#e7f3f4; border-top:1px solid white; border-right:1px solid white; border-left:1px solid white">
<p > </p>
</td>
</tr>
</tbody>
</table>
<p> </p>
<p>以上就是硬件的全部连接,具体采用杜邦线与开发板相连;</p>
<p>12V 直流电源输入, 逻辑分析仪检测输入波形,万用表测试DC 电机两端电压;</p>
<p> </p>
<p> </p>
<p>二、软件初步:</p>
<p> 采用基于STM32NUCLEO-G474RE Arduino 的软件架构, Arduino 中选择STM32 NUCLEO-64 的板子;</p>
<p> 选择对应开发板;</p>
<p> 选择对应COM 口;</p>
<p>编写初步的程序:</p>
<pre>
<code>#include <SPI.h>
//L99H92 控制口
const int EN_PIN = D2;//D2
const int DIAGN_PIN = D3;
const int DIR_PIN = D4;
const int MTPWM_PIN = D5;
const int FSINB_PIN = D6;
//CS 片选
const int CS_PIN = D10;
void setup() {
SPI.begin();
//串口配置
Serial.begin(115200);
Serial.println("UART Start");
// 设置输入和输出方式
pinMode(CS_PIN,OUTPUT);
pinMode(EN_PIN,OUTPUT);
pinMode(DIAGN_PIN,INPUT);
pinMode(DIR_PIN,OUTPUT);
pinMode(MTPWM_PIN,OUTPUT);
pinMode(FSINB_PIN,OUTPUT);
//设置初始化状态
digitalWrite(CS_PIN,HIGH);
digitalWrite(EN_PIN,LOW);
digitalWrite(FSINB_PIN, LOW);
int Vst = digitalRead(DIAGN_PIN);
//analogWrite(MTPWM_PIN,100);
//启用L99H992
enableL99H92();
digitalWrite(FSINB_PIN, HIGH);
}
void loop() {
digitalWrite(CS_PIN,LOW);
SPI.transfer(0x03);
SPI.transfer(0x55);
SPI.transfer(0x88);
digitalWrite(CS_PIN,HIGH);
delay(500);
}
void enableL99H92()
{
digitalWrite(EN_PIN,HIGH);
}
void disableL99H92()
{
digitalWrite(EN_PIN,LOW);
}</code></pre>
<p> 以上初步完成了软件和硬件环境的搭建,下一步正式驱动L99H92;</p>
</div><script> var loginstr = '<div class="locked">查看本帖全部内容,请<a href="javascript:;" style="color:#e60000" class="loginf">登录</a>或者<a href="https://bbs.eeworld.com.cn/member.php?mod=register_eeworld.php&action=wechat" style="color:#e60000" target="_blank">注册</a></div>';
if(parseInt(discuz_uid)==0){
(function($){
var postHeight = getTextHeight(400);
$(".showpostmsg").html($(".showpostmsg").html());
$(".showpostmsg").after(loginstr);
$(".showpostmsg").css({height:postHeight,overflow:"hidden"});
})(jQuery);
} </script><script type="text/javascript">(function(d,c){var a=d.createElement("script"),m=d.getElementsByTagName("script"),eewurl="//counter.eeworld.com.cn/pv/count/";a.src=eewurl+c;m.parentNode.insertBefore(a,m)})(document,523)</script> <p>可以,还用上了 逻辑分析仪检测输入波形</p>
<p>有直接测试的那种上位机软件吗? </p>
页:
[1]