Is the L293B motor driver slow?

Im just starting a little project and Im currently trying to control two lego motors with a L293B H-bridge. It works just fine as long as I add a 100ms delay when I change the motors direction. If I don't I get a 'shoot through' and the Arduino restarts. Here's the code:

int dir1a = 3;
int dir1b = 4;
int pwm1 = 5;
int dir2a = 8;
int dir2b = 9;
int pwm2 = 6;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.


  pinMode(dir1a, OUTPUT);
  pinMode(dir1b, OUTPUT);
  pinMode(dir2a, OUTPUT);
  pinMode(dir2b, OUTPUT);
  pinMode(pwm1, OUTPUT);
  pinMode(pwm2, OUTPUT);
  delay(5000);
  
}

// the loop routine runs over and over again forever:
void loop() {
  
  
  startM1("forward", 255);
  delay(1000);
  startM1("reverse", 255);
  delay(1000);
  startM1("stop", 0);
  delay(1000);
  startM2("forward", 255);
  delay(1000);
  startM2("reverse", 255);
  delay(1000);
  startM2("stop", 0);
  delay(1000);
  
}

void startM1(String dir, int speed)
{
  if(dir == "forward")
  {
    digitalWrite(dir1a, LOW);
    digitalWrite(dir1b, LOW);
    delay(100);
    digitalWrite(dir1a, LOW);
    digitalWrite(dir1b, HIGH); 
    analogWrite(pwm1, speed);
  }
  
  else if(dir == "reverse")
  {
    digitalWrite(dir1a, LOW);
    digitalWrite(dir1b, LOW);
    delay(100);
    digitalWrite(dir1a, HIGH);
    digitalWrite(dir1b, LOW); 
    analogWrite(pwm1, speed);
  }
  
  else if(dir == "stop")
  {
    analogWrite(pwm1, speed);
    digitalWrite(dir1a, LOW);
    digitalWrite(dir1b, LOW);    
  }
}

void startM2(String dir, int speed)
{
  if(dir == "forward")
  {
    digitalWrite(dir2a, LOW);
    digitalWrite(dir2b, LOW);
    delay(100);
    digitalWrite(dir2a, LOW);
    digitalWrite(dir2b, HIGH); 
    analogWrite(pwm2, speed);
  }
  
  else if(dir == "reverse")
  {
    digitalWrite(dir2a, LOW);
    digitalWrite(dir2b, LOW);
    delay(100);
    digitalWrite(dir2a, HIGH);
    digitalWrite(dir2b, LOW); 
    analogWrite(pwm2, speed);
  }
  
  else if(dir == "stop")
  {
    analogWrite(pwm2, speed);
    digitalWrite(dir2a, LOW);
    digitalWrite(dir2b, LOW);    
  }
}

Notice the delay(100) in the startM1 and startM2 functions. If I remove that or decrease it to 10 I get a 'shoot through'. Can anyone please explain why and how that is?

Arduino resetting is usually a result of power circuit layout. How is the motor power supplied? Get you motor power BEFORE the Arduino board regulator NOT from it.
Please describe your circuit.

The Arduino and the motors are currently powered by a 9v battery. The Arduino and the L293 outputs is powered directly from the 9v battery and the logic part of the L293 is powered from the regulated 5v pin on the Arduino board. The Arduino and the L293 have common ground.
Am I making any sense or do I need to make a drawing?

Thank you for your time

You are not getting shoot-through at all. Shoot-through is when both high- and low-side switches
of an H-bridge are on simultaneously (even for microseconds)

You are getting the supply voltage "crowbarred" by overloading it.

When you power down and let the motor stop before starting it in the other direction you reduce the
peak current demand of the motor by about 2 (compared to reversing instantly).

However your main issue is that 9V PP3 batteries are simply not up to powering a motor, they are
not designed for it and cannot provide enough current for the peak loads for even a small motor.

Rechargable AA packs are the way to go.

You might be on to something there. I am indeed using a crappy 9v battery, although it is powerful enough to power both motors simultaneously. Perhaps immediate change of directions causes a power surge that the battery just can't handle. I've got an 11,1v Li-Po. I'll hook that bad boy up to my stuff tomorrow. I really hope that works since there are no fuses or other protection on my little rig.

Hi Garberg,
You should really use seperate supplies for the Arduino and motors! Having said that! I've build a few buggys that use the L293 to drive 2 DC motors, and I power it from 6xAA Nimh batts with the raw 7.2v going to the VCC on the L293 then to the Arduino (and VC on L293) via a LDO 5v reg. You should certainly have a 100nF cap to ground on both and even a 47-100uF somewhere. As MarkT says you're not getting Shoot-through that often kills the L293 or H bridges in general, as a very large current flows through both transistors/Fets.

I always stop my motors, if only for a very short time before reversing or changing direction!... Try changing the delay to 50, 30 or even 10! Hope it helps!

Regards

Mel.

Garberg:
You might be on to something there. I am indeed using a crappy 9v battery, although it is powerful enough to power both motors simultaneously.

Powering at no-load is not the issue, reversing a motor suddenly causes twice the stall current
to be demanded.