milk1995
New Member
3 Posts |
Posted - Aug 23 2017 : 04:16:36 AM
|
Greetings~ I am confusing about controlling DC motor by L298N. My program is as following: #include <reg51.h> #define uchar unsigned char #define uint unsigned int sbit ENA=P1^2; sbit IN1=P1^3; sbit IN2=P1^4; sbit ENB=P1^5; sbit IN3=P1^6; sbit IN4=P1^7;
uint MA=0; uint speedA=50; int flag=0;
void timeinit() { TMOD=0x01; TH0=(65536-10000)/256; TL0=(65536-10000)%256; EA=1; ET0=1; TR0=1; }
void Ques1() { switch(flag/10) { case 0: TR0=0; if(MA<speedA) { ENA=1;ENB=1; IN1=1;IN2=0; IN3=0;IN4=1; } else { if(speedA<=MA<100) { ENA=0; ENB=0; } else { MA=0; flag++; } } TR0=1; break; case 1: TR0=0; if(MA<speedA) { ENA=1;ENB=1; IN1=0;IN2=1; IN3=1;IN4=0; } else { if(speedA<=MA<100) { ENA=0; ENB=0; } else { MA=0; flag++; } } TR0=1; break; default : flag=0; break; } }
void time0() interrupt 1 { TH0=(65536-10000)/256; TL0=(65536-10000)%256; MA++; }
void main() { timeinit(); while(1) { Ques1(); } } This is the datasheet of L298N: http://www.kynix.com/uploadfiles/pdf9675/L298N.pdf . Why can’t this program control positive and negative rotation of motor at the same time. Now my question is the motor controlled by IN1 and IN2 work after pressing RESET,and the motor controlled by IN3 and IN4 will stop rotating after 5 seconds. Why? ? #65311; Your help will be appreciated! |
|