Hello guys,
I went into weird problem and I need help, maybe you will see the problem here. I am making robot, made my PCB with L293D and went into problem with control. My first motor wont start running (E1, I1, I2) after it gets char 'Q' and second starts turning (code 1). Weird thing is, that everything is good when running second program, both motors run smooth. (code 2). I checked with multi-meter enable pin1 and it gets 0V. Any ideas why?
Code1:
//Motor set
#define E1 11 // Enable Pin for motor 1
#define E2 6 // Enable Pin for motor 2
#define I1 10 // Control pin 1 for motor 1
#define I2 9 // Control pin 2 for motor 1
#define I3 7 // Control pin 1 for motor 2
#define I4 8 // Control pin 2 for motor 2
const int motorNeutral = 120;
const int turnspeed = 150;
const int speedmax = 255;
void drive()
{
switch (c)
{
case 'C': case 'Q':
{
if (Front > 200 && Front != 0) //160mm
{
digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);
digitalWrite(I3, HIGH);
digitalWrite(I4, LOW);
Lmotor = motorNeutral - Output;
Rmotor = motorNeutral + Output;
}
if (Front < 200 && Front > 10 )
{
digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);
digitalWrite(I3, LOW);
digitalWrite(I4, HIGH);
Lmotor = turnspeed;
Rmotor = turnspeed;
}
// limit rightMotorSpeed
if (Rmotor > 160)
Rmotor = 160;
else if (Rmotor < 0)
Rmotor = 0;
// limit rightMotorSpeed
if (Lmotor > 160)
Lmotor = 160;
else if (Lmotor < 0)
Lmotor = 0;
analogWrite(E1, Lmotor);
analogWrite(E2, Rmotor);
}
break;
code2:
case 'N':
{
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);
}
break;
case 'G' :
{
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);
case 'S':
{
digitalWrite(E1, LOW);
digitalWrite(E2, LOW);
c = '*';
}
break;
case 'F':
// turn it on going forward
{
digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);
digitalWrite(I3, HIGH);
digitalWrite(I4, LOW);
analogWrite(E1, 255); // Run in full speed
analogWrite(E2, 255); // Run in full speed
c = '*';
}
break;
case 'B':
// turn it on going backward
{
digitalWrite(I1, LOW);
digitalWrite(I2, HIGH);
digitalWrite(I3, LOW);
digitalWrite(I4, HIGH);
analogWrite(E1, 255); // Run in full speed
analogWrite(E2, 255); // Run in full speed
c = '*';
}
break;
case 'L':
// turn left
{
digitalWrite(I1, LOW);
digitalWrite(I2, HIGH);
digitalWrite(I3, HIGH);
digitalWrite(I4, LOW);
analogWrite(E1, 255); // Run in full speed
analogWrite(E2, 255); // Run in full speed
c = '*';
}
break;
case 'R':
// turn right
{
digitalWrite(I1, HIGH);
digitalWrite(I2, LOW);
digitalWrite(I3, LOW);
digitalWrite(I4, HIGH);
analogWrite(E1, 255); // Run in full speed
analogWrite(E2, 255); // Run in full speed
c = '*';
}
break;
}
break;
}