Home > other >  About 51 intelligent tracking car motor driver problem
About 51 intelligent tracking car motor driver problem

Time:09-26

Each great god ask car driver problem: program burn into the MCU, power supply starts, L298N are buzzing sound, turn the wheels of the car is not, with the hand will toggle the minimum speed rotation (like power, and only one), the duty ratio is more high, don't know where is wrong, please the great god give criticisms (with 4 section 1.5 v battery, drive 5 infrared tube, ultrasonic module, motor, don't know if the problem of insufficient input voltage, may be I understand wrong PWM principle), here is the car of the code, beginners, for the first time to write, please include more, (if you have other questions can help point out together, trouble you)


# include & lt; Reg52. H>
#include

Sbit IN1=P0 ^ 1;////the left motor
Sbit IN2=P0 ^ 2;
Sbit ENA=P0 ^ 0;
Sbit IN3=P0 ^ 3;////right motor
Sbit IN4=P0 ^ 4;
Sbit ENB=P0 ^ 5;

Sbit Trig P1=^ 1;//ultrasonic module TRIG, specific interfaces need to change//
Sbit Echo=p ^ 2;//ECHO ultrasonic module

# define uc unsigned char
# define the UI unsigned int
25//# define juli distance obstacles//

# define leftgo {IN1=1, IN2=0; }//left motor of
# define leftback {IN1=0, IN2=1; }//left motor reversal
# define rightgo {IN3=0, IN4=1; }//right motor of
# define rightback {IN3=1, IN4=0; }//right motor reversal

Uc ZKBR=0;
Uc ZKBL=0;
Uc t=0;//timer counting number//

Uc FLAG;//ultrasonic beyond measurement range of mark
The UI sum;//the total number of timer 1 meter in ultrasonic module//
Float L;//L for the distance between the ultrasonic module calculation and obstacles//

Sbit L1=P2 ^ 0; Five infrared tracking module////

Sbit L2=p ^ 2;
P1 sbit M=^ 3;
Sbit R2=P1 ^ 4;
Sbit R1=P1 ^ 5;

Void t0go ()////timer 0 start working function
{
TMOD=0x01;//t0 timer works for 1//
TH0=(65536-100)/256; 108.5 us//timer timing//
TL0=(65536-100) % 256;
EA=1;////always interrupt
ET0=1;////open the timer 0 interrupt
TR0=1;////open timer
}

Void t1go ()//timer 1 immediately began to work as a function of the//
{
TMOD=0 x10.
EA=1; The potential for error////
ET1=1;
}

Void t0 () interrupt 1//t0 interrupt function//
{
TH0=(65536-100)/256; Initial value////reinstall the timer is
TL0=(65536-100) % 256;
If (t{
ENA=1;
}
The else
{
ENA=0;
}
If (t & lt; ZKBR)
{
ENB=1;
}
The else
{
ENB=0;
}
+ + t;
If (t>=50)
{
t=0;
}
}

Void t1 () interrupt 3//ultrasonic beyond measurement range//
{
FLAG=1;
}
Small void turnleft1 ()/turn left/turn//
{
ZKBL=30;
ZKBR=10;
}
Void turnleft2 ()/turn left/turn//
{
ZKBL=50;
ZKBR=10;
}
Void turnright1 ()//right turn small//
{
ZKBL=10;
ZKBR=30;
}
Void turnright2 ()//right turn//
{
ZKBL=10;
ZKBR=50;
}
Void the go ()
{
ZKBL=40;
ZKBR=40;
Leftgo;
Rightgo;
}
Void back ()
{
ZKBL=10;
ZKBR=10;
Leftback;
Rightback;
}
Void the stop ()
{
ZKBL=0;
ZKBL=0;
}
Void xunji ()
{
Uc flag;
If ((R2==0) & amp; & (L1==1) & amp; & (L2==1) & amp; & (R1==1))//small right//
{
Flag=1;
}
Else if ((R1==0) & amp; & (R2==0) & amp; & (L1==1) & amp; & (L2==1))//right//
{
Flag=2;
}
Else if ((R2==0) & amp; & (L2==1))//parking
{
Flag=3;
}
Else if ((R2==1) & amp; & (R1==1) & amp; & (L1==1) & amp; & (L2==0))//small left//
{
Flag=4;
}
Else if ((R1==1) & amp; & (R2==1) & amp; & (L1==0) & amp; & (L2==0))//turn left//
{
Flag=5;
}
Else if ((L1==0) & amp; & (L2==1) & amp; & (M==1) & amp; & (R1==1) & amp; & (R2==1))
{
Flag=5;
}
Else if ((L1==1) & amp; & (L2==1) & amp; & (M==1) & amp; & (R1==0) & amp; & (R2==1))
{
Flag=2;
}
Else if ((L1==1) & amp; & (L2==1) & amp; & (M==1) & amp; & (R1==1) & amp; & (R2==1))//special circumstances, when the car can't scan to the black line, the car back//
{
Flag=6;
}
The switch (flag)
{
Case 1: turnright1 (); break;

Case 2: turnright2 (); break;

Case 3: the stop (); break;

Case 4: turnleft1 (); break;
Case 5: turnleft2 (); break;
Case 6: the back (); break;

Default: go (); break;
}
}
Void the send ()//make the module start sending eight square wave//
{
Trig=1;
_nop_();////SCM delay a machine cycle
_nop_();//set the aim is to make the Trig mouth start sending square wave//,
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
Trig=0;
}
Void short ()
{
TH1=0;//place//timer 1 count
TL1=0;
The send ();
while(! Echo);//! Echo=0, already echo=1 output high electric jump out while at ordinary times, the essence is waiting for the start of the output after open timer//
TR1=1;
While (Echo);//wait for the echo mouth after the output level (i.e., the output low electricity at ordinary times) and then close the timer//
TR1=1;
Sum=TH1 * 256 + TL1;//get the timer in process gets the total number of//
L=(sum * 1.87)/100;//have obtained the formula of the velocity of 1.87 to 20 degrees in temperature value 344, L is the unit of cm//
If (L<=juli & amp; & FLAG==0)//obstacles have defined the distance above the minimum distance, the unit is cm//
{
back();
}
If (FLAG==1)//beyond measure
{
FLAG=0;
}
}
Void main ()
{
T0go ();
T1go ();
Leftgo;
Rightgo;
While (1)
{
Xunji ();
Short ();
}
}

CodePudding user response:

Code didn't watch, but can output PWM waveform oscilloscope measurement L298N want waveform,
If the waveform is correct, see if the motor and L298N match, if the motor is too large, motor L298N is sure to bring the fixed

CodePudding user response:

Upstairs makes sense, should be raised or L298 motor drive voltage power supply voltage, a voice and the trend of transfer, no problem

CodePudding user response:

Look at the driving frequency, try out the simple IO drive, high and low level, and if the line, consider the PWM drive!

CodePudding user response:

I watched, seems to be caused by the timer clock frequency is too high

CodePudding user response:

null
  • Related