Am I wiring my H-Bridge correctly?

This is a loaded question as I am!! lol

But im not exactly sure wether Im doing it the standard way or not! Im using an l293E, for testing and an l6205 in the final bored. Basically im making an AVR based serial motor controller and battery monitor for my robot, then just installing the Arduino boot loader on the chip.

Now where im a bit hung up is my design works fine but I can only have 3 motors with independent speed control, and there PWM frequencys wouldn't even match since pins 5 and 6 use different timers for pwm than 3 and 11 /9 and 10. Right now my bot is 3 wheeled and it works just fine, but id like to be able to plug in 4 motors in the future, not just two.

Currently im running pwm pins 3 and 11 and pwm pins 9 and 10, to the l293s input pins. So each motor is using 2 pwm channels, one for forward and one for reverse. What im thinking is maybe I could send a single pwm signal to the enable pin to set the speed and then flip the l293 inputs with the Arduinos digital pins to dictate reverse and forward. Is this a standard way of controlling four motors?

Heres some code to maybe help make sense of how im doing motor control right now

//Set up motor signal pins
int m1P1 = 3;
int m1P2 = 11;
int m2P1 = 9;
int m2P2 = 10;


void setup() { 
   //Set up 32khz PWM 
   TCCR1B = TCCR1B & 0b11111000 | 0x01; //Timer 1 (PWM pins 9 & 10)
   TCCR2B = TCCR2B & 0b11111000 | 0x01; //Timer 2 (PWM pins 3 & 11)  
   //Set Signals to output
   pinMode(m1P1, OUTPUT);
   pinMode(m1P2, OUTPUT);
   pinMode(m2P1, OUTPUT);
   pinMode(m2P2, OUTPUT);
}
void loop() 
{
  openLoopForward(255,255);
  delay(5000);
  fastBrake();
  delay(2000);
  openLoopReverse(255,255);
  delay(5000);
  fastBrake();
  delay(2000);
}

//Open Loop Motor Controls
void openLoopForward(int rightSpeed, int leftSpeed) 
{
  analogWrite(m1P1, rightSpeed);
  analogWrite(m2P2, leftSpeed); 
  digitalWrite(m1P2, LOW);
  digitalWrite(m2P1, LOW);
}
void openLoopReverse(int rightSpeed, int leftSpeed) 
{
  analogWrite(m1P2, rightSpeed);
  analogWrite(m2P1, leftSpeed);  
  digitalWrite(m1P1, LOW);
  digitalWrite(m2P2, LOW);
}
void fastBrake()
{
  digitalWrite(m1P1, LOW);
  digitalWrite(m1P2, LOW);
  digitalWrite(m2P1, LOW);
  digitalWrite(m2P2, LOW); 
}

void openRamp(int pause)
{
  digitalWrite(m1P2, LOW);
  digitalWrite(m2P1, LOW);
  
  for (int i=0; i <= 255; i++)
  {
    analogWrite(m1P1, i);
    analogWrite(m2P2, i);
    delay(pause); 
 }
}

Also I may want to control a few servos, I can do that using any digital pin correct, no need for a pin with pwm timers tied to it?

rwgast:
Currently im running pwm pins 3 and 11 and pwm pins 9 and 10, to the l293s input pins. So each motor is using 2 pwm channels, one for forward and one for reverse. What im thinking is maybe I could send a single pwm signal to the enable pin to set the speed and then flip the l293 inputs with the Arduinos digital pins to dictate reverse and forward. Is this a standard way of controlling four motors?

Yes. PWM pin for speed. Digital pin for direction.

rwgast:
Also I may want to control a few servos, I can do that using any digital pin correct, no need for a pin with pwm timers tied to it?

Yes, that is correct.

Hmm ok, so is pulsing the enable pin on an h-bridge IC the usuall method of doing this? I was under the impression you send seperate PWM signals for forward and reverse to the l293s inputs. Id like to keep my enable pins as master overides, maybe theres a way to use an or gate or something to split the one pwm line in to two?

You can also PWM either of the direction pins instead of the Enable pins. You only need to PWM one of the three pins for each motor. If you PWM one of the direction pins I think you have to reverse the sense of the PWM:

DIRA1 LOW
DIRB1 PWM: 0=stop, 255=Full Forward

DIRA1 HIGH
DIRB1 PWM: 0=Full Reverse, 255=stop

If I don't need to change the speed,can I use the digitalwrite(m1P1,HIGH) to replace the analogwrite(m1P1,255)?

Jackman:
If I don't need to change the speed,can I use the digitalwrite(m1P1,HIGH) to replace the analogwrite(m1P1,255)?

Yes.

(and in that case you wouldn't need either to be a PWM pin.)