完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
大家好,我是PIC单片机的新手,需要一些帮助。我试着在网上寻找,但我只能找到PWM速度控制。我用的是PIC18F26K22。我使用ECP来控制RB2和RC2上的增强型PWM。我把我的马达连接到那些引脚上,我需要弄清楚如何编程UC来反转马达。这是我的代码:谢谢。
以上来自于百度翻译 以下为原文 Hello, I am new to pic microcontrollers and I need some help. I tried looking online but I could only find PWM speed control. I am using a PIC18F26K22. I am using the eccp to control the enhanced PWM on RB2 and RC2. I connected my motor to those pins and I need to figure out how to program the uC to run the motor in reverse. Here is my code so far: void CleanStep() { DisUSR = ultrasonic(1); //get distance from ultrasonic sensor 1 DisUSL = ultrasonic(2); //get distance from ultrasonic sensor 2 uint16_t dutycycle = 638; //62.5% while (1) { while (DisUSR > 1) { //keep going Right till the distance from obstacle is 1cm PORTBbits.RB2 = 0; //is it right to set the pins to LOW before running the PWM? PORTCbits.RC2 = 0; dutycycle = 638; EPWM1_LoadDutyValue(dutycycle); //Set the speed at 62.5% DisUSR = ultrasonic(1); } dutycycle = 0; EPWM1_LoadDutyValue(dutycycle); //set speed to 0 PORTBbits.RB2 = 0; //also is it right to set the pins to LOW after running the PWM? PORTCbits.RC2 = 0; while (DisUSL > 1) { //keep going Left till the distance from obstacle is 1cm PORTBbits.RB2 = 0; PORTCbits.RC2 = 0; dutycycle = 638; EPWM1_LoadDutyValue(dutycycle); DisUSR = ultrasonic(1); } dutycycle = 0; PORTBbits.RB2 = 0; PORTCbits.RC2 = 0; } } Thank you |
|
相关推荐
2个回答
|
|
|
|
|
|
我使用的是12V直流电动机,但我用H桥来控制它。我使用的是MOSFET的I2110
以上来自于百度翻译 以下为原文 I am using a 12V dc motor, but I am using an h-bridge to control it. I am using an IR2110 with MOSFETs |
|
|
|
只有小组成员才能发言,加入小组>>
5006 浏览 9 评论
1923 浏览 8 评论
1853 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3067 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2143 浏览 5 评论
578浏览 1评论
432浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
477浏览 0评论
367浏览 0评论
IPECMD命令烧录AVR128DA48芯片,报找不到芯片错误
853浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-8-17 12:56 , Processed in 1.166661 second(s), Total 80, Slave 64 queries .
Powered by 电子发烧友网
© 2015 www.ws-dc.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号