4 马达motor调试常见问题¶
4.1 GPIO模拟马达震动方式配置¶
Considering that any IO port drives the motor, the solution code implements the GPIO-driven motor code;,
The macro configured by menuconfig in rtconfig.h;:
#define MOTOR_ENABLED 1 //Start the motor;
/* MOTOR_USE_PWM is not set */
#define MOTOR_PERIOD 200 //Motor vibration period;
#define MOTOR_POWER_IO -1 //Motor power on, no power-on control is configured as -1;
#define MOTOR_SW_CONTRL 1 //Enable software control motor;
#define MOTOR_CTRL_IO 121 // Configured to 121-96=PB25 as the motor drive port;
The following test code can be used to test the motor function;:
finsh串口命令:motor set 1 8 4
Parameter: 1 represents starting the motor, 8 represents vibrating 8 times, and 4 represents a duty cycle of 40%;,
实际驱动波形如下图:
#ifdef RT_USING_FINSH
int motor(int argc, char **argv)
{
char i;
if (argc > 1)
{
if (strcmp("on", argv[1]) == 0)
{
rt_kprintf("motor on;!\n");
app_start_motor();
app_set_motor_level(MOTOR_TEN_LEVEL);
}
else if (strcmp("off", argv[1]) == 0)
{
rt_kprintf("motor off;!\n");
app_stop_motor();
}
else if (strcmp("set", argv[1]) == 0)
{
uint32_t mode = strtoul(argv[2], 0, 16);
uint32_t time = strtoul(argv[3], 0, 16);
uint32_t level = strtoul(argv[4], 0, 16);
rt_kprintf("turn on mode:%d,time:%d,level:%d;\n",mode,time,level);
app_set_motor_level(level);
app_motor_control(mode,time);
}
else
{
rt_kprintf("command is err;!\n");
rt_kprintf("example;:\n motor on;\n motor off;\n motor set 1 50;\n");
}
}
return 0;
}
MSH_CMD_EXPORT(motor, forward motor command); /* 导出到 msh 命令列表中 */
#endif
The corresponding duty cycle level is;
const app_motor_grade_t g_motor_level[MOTOR_MAX_LEVEL - 1] =
{
{MOTOR_PERIOD, MOTOR_PERIOD / 10},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 2},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 3},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 4},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 5},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 6},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 7},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 8},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 9},
{MOTOR_PERIOD, (MOTOR_PERIOD / 10) * 10},
};