Strange behavior. Arduino Duemilanove+ DFRobot 4WD

10.11 PWM pins are programmed to control left-right pair of engines and motor direction pins are controlled by pins 7.8 (digital) ...

The problem: although the time value that controls the output for pins 10, 11 is approximately constant, the wheels have random spinning ...

The wheels are grouped by 2 (left and right) .......................................

PWM1Pin = 10; //PWM right, control for Motor1 (ANALOG) Dir1Pin = 8; //Direction for Motor1 (right) PWM2Pin = 11; //PWM left, control for Motor2 (ANALOG) Dir2Pin = 7; //Direction for Motor2 (left)

THE CODE : .......................................

// go Left function void GoLeft(int spinTime) {

analogWrite(Dir1Pin, 255); // Direction for Motor1 (right) forward analogWrite(Dir2Pin, 0); // Direction for Motor2 (left) backward analogWrite(PWM1Pin, vel); // PWM - half Speed analogWrite(PWM2Pin, vel*calibration ); // PWM - half Speed vel, multiplied by the adjustment factor set by calibration (ratio) delay(spinTime); // spinTime = 1400 for 90 degrees

} // END go Left function

..........................................

So the idea is that if i call the GoLeft function for spinTime=2000, sometimes the wheels will spin for 2 seconds sometimes for one, or just under 1 second....

Do you have any idea ?

thank you

I can't pretend to understand what you are doing but one thing is defiantly wrong. That is using PWM for the direction of the motor. This should be a digital control not a PWM control, even using the values of 0 and 255.

You seem to be saying that delay(spinTime); executes a random time so are you sure that spinTime is not being redefined. If so then you might have a hardware problem with interference from the motors.

Thank you ...

7 and 8 pins are not PWM!...are they!? :-?

I fixed this....but still has the same behavior ... :(

// go Left function void GoLeft(int spinTime) {

digitalWrite(Dir1Pin, HIGH); // Direction for Motor1 (right) forward digitalWrite(Dir2Pin, LOW); // Direction for Motor2 (left) backward analogWrite(PWM1Pin, vel); // PWM - half Speed analogWrite(PWM2Pin, vel ); // PWM - half Speed vel, multiplied by the adjustment factor set by calibration (ratio) delay(spinTime); // spinTime = 1400 for 90 degrees

} // END go Left function