HiSpark_WiFi_IoT智能小车开发套件试用——安装踩坑 原创

曙光设计
发布于 2021-9-23 21:06
浏览
0收藏

非常感谢鸿蒙社区提供的开发板试用活动,本人非常幸运得到此次试用资格,后续我会利用好这次试用机会,学习鸿蒙系统的移植,并分享自己的学习经历。

外观展示

HiSpark_WiFi_IoT智能小车开发套件试用——安装踩坑-鸿蒙开发者社区
请参考官方安装历程,内有详细安装步骤。
HiSpark_WiFi_IoT智能小车开发套件试用——安装踩坑-鸿蒙开发者社区

小车电机PWM控制代码分析


{

 GpioInit();

 //引脚复用

 IoSetFunc(WIFI_IOT_IO_NAME_GPIO_0, WIFI_IOT_IO_FUNC_GPIO_0_PWM3_OUT); 

    IoSetFunc(WIFI_IOT_IO_NAME_GPIO_1, WIFI_IOT_IO_FUNC_GPIO_1_PWM4_OUT);  

 IoSetFunc(WIFI_IOT_IO_NAME_GPIO_9, WIFI_IOT_IO_FUNC_GPIO_9_PWM0_OUT); 

    IoSetFunc(WIFI_IOT_IO_NAME_GPIO_10, WIFI_IOT_IO_FUNC_GPIO_10_PWM1_OUT); 




 //初始化pwm

 PwmInit(WIFI_IOT_PWM_PORT_PWM3);

    PwmInit(WIFI_IOT_PWM_PORT_PWM4);

 PwmInit(WIFI_IOT_PWM_PORT_PWM0);

    PwmInit(WIFI_IOT_PWM_PORT_PWM1);

}
//小车前进,后退,转向
void pwm_stop(void)

{

 //先停止PWM

 PwmStop(WIFI_IOT_PWM_PORT_PWM3);

    PwmStop(WIFI_IOT_PWM_PORT_PWM4);

 PwmStop(WIFI_IOT_PWM_PORT_PWM0);

    PwmStop(WIFI_IOT_PWM_PORT_PWM1);

}

//前进

void pwm_forward(void)

{

 //先停止PWM

 PwmStop(WIFI_IOT_PWM_PORT_PWM3);

    PwmStop(WIFI_IOT_PWM_PORT_PWM4);

 PwmStop(WIFI_IOT_PWM_PORT_PWM0);

    PwmStop(WIFI_IOT_PWM_PORT_PWM1);




 //启动A路PWM

 PwmStart(WIFI_IOT_PWM_PORT_PWM3, 750, 1500);

 PwmStart(WIFI_IOT_PWM_PORT_PWM0, 750, 1500);

}




//后退

void pwm_backward(void)

{

 //先停止PWM

 PwmStop(WIFI_IOT_PWM_PORT_PWM3);

    PwmStop(WIFI_IOT_PWM_PORT_PWM4);

 PwmStop(WIFI_IOT_PWM_PORT_PWM0);

    PwmStop(WIFI_IOT_PWM_PORT_PWM1);




 //启动A路PWM

 PwmStart(WIFI_IOT_PWM_PORT_PWM4, 750, 1500);

 PwmStart(WIFI_IOT_PWM_PORT_PWM1, 750, 1500);

}

//左转

void pwm_left(void)

{

 //先停止PWM

 PwmStop(WIFI_IOT_PWM_PORT_PWM3);

    PwmStop(WIFI_IOT_PWM_PORT_PWM4);

 PwmStop(WIFI_IOT_PWM_PORT_PWM0);

    PwmStop(WIFI_IOT_PWM_PORT_PWM1);




 //启动A路PWM

 PwmStart(WIFI_IOT_PWM_PORT_PWM3, 750, 1500);

}

//右转

void pwm_right(void)

{

 //先停止PWM

 PwmStop(WIFI_IOT_PWM_PORT_PWM3);

    PwmStop(WIFI_IOT_PWM_PORT_PWM4);

 PwmStop(WIFI_IOT_PWM_PORT_PWM0);

    PwmStop(WIFI_IOT_PWM_PORT_PWM1);




 //启动A路PWM

 PwmStart(WIFI_IOT_PWM_PORT_PWM0, 750, 1500);

}

踩坑

请注意小车的电机马达上面有1,2标号,1号马达在左边,2号马达在右边,请不要装反,否则小车向后移动。

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
2
收藏
回复
举报
回复
    相关推荐