为何我的电机不能同时转
刚用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();
}
} #define leftmoto_fan() PORTD|=(~0x08)
改成
#define leftmoto_fan() PORTD&=(~0x08) 我改了后还是不行啊,
当我执行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();
} 不好意思,反相器没接电源
页:
[1]