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?