chenliangmoto 发表于 2008-1-4 19:45:10

为何我的电机不能同时转

刚用L298驱动了2个电机,写了个简单的测试程序,按照如下程序只有leftmoto电机工作,另一个电机却不动,为何啊?
#include <avr/io.h>
/*IN1-PD2,IN3-PD3,右电机ENA-PD4(OC1B),左电机ENB-PD5(OC1A)*/
#define rightmoto_zhen()   PORTD|=0X04
#define rightmoto_fan()      PORTD&=(~0X04)
#define rightmoto_control()    PORTD&=(~0X10)
#define leftmoto_zhen()      PORTD|=0X08
#define leftmoto_fan()       PORTD|=(~0x08)
#define leftmoto_control()   PORTD&=(~0X20)
int main(void)
{       
        DDRD|=0X3C;
        PORTD=0XFF;
        while(1)
                {        //rightmoto_control();
                        //leftmoto_control();
                        rightmoto_fan();
                        leftmoto_zhen();
               
               
                }


}

ghost2 发表于 2008-1-4 19:51:26

#define leftmoto_fan()       PORTD|=(~0x08)
改成
#define leftmoto_fan()       PORTD&=(~0x08)

chenliangmoto 发表于 2008-1-4 20:22:57

我改了后还是不行啊,
当我执行leftmoto_control();把rightmoto_control();注释掉
这样就是leftmoto电机停掉,rightmoto能够正常转动,这证明rightmoto没问题啊;
        while(1)
                {        //rightmoto_control();
                        leftmoto_control();
                        rightmoto_fan();
                        leftmoto_zhen();
               
               
                }
那为什么2个电机不能一起转呢?
while(1)
                {      //rightmoto_control();
                        //leftmoto_control();
                        rightmoto_fan();
                        leftmoto_zhen();
               
               
                }

chenliangmoto 发表于 2008-1-4 21:20:18

不好意思,反相器没接电源
页: [1]
查看完整版本: 为何我的电机不能同时转