DC motor spins at power ON

Hi,

I am using an arduino UNO clone I made which is working fine, got the same problem with official Arduino.

See attached the full schematic.

Here is a simple code :

//motors
int motor_Right = 5;         // PIN n°11
int motor_Left = 6;        // PIN n°12
int enable_motor_Right = 8;  // PIN n°14
int enable_motor_Left = 9; // PIN n°15

//Const
const int motor_Stop = 127;  //PWM at 1/2 to stop motors

//INITIALISATION
void setup() {
  // Set PWM to 62500 Hz
  TCCR0B = TCCR0B & 0b11111000 | 1;

  pinMode(motor_Right, OUTPUT);            //motor_Right as output
  pinMode(motor_Left, OUTPUT);           //motor_Left as output
  pinMode(enable_motor_Right, OUTPUT);     //motor_Right as output
  pinMode(enable_motor_Left, OUTPUT);    //motor_Left as output

  digitalWrite(enable_motor_Right, LOW);
  digitalWrite(enable_motor_Left, LOW);
  analogWrite(motor_Right, motor_Stop);  //motor_Right OFF
  analogWrite(motor_Left, motor_Stop); //motor_Left OFF
 
}

//MAIN
void loop()
{
}

I am using a 14.8 V, Lithium-ion, 3.45 Ah battery and 12 V, 18 t/min, 8 N-cm motors. I know 15V is a little bit hard for my 12V motors but this, I think, is not the problem.

I am controlling the motors with a simple L293D H bridge and I have even tried with a H bridge based on a HIP4080AIPZ.

My problem is at power ON. Before the Arduino gets totally setup my motors spins and sometimes I have to switch on and off multiple times the board before it gets really on.

I believe this is what is happening : at cold power ON, capacitor C35 and C23 are discharged, so the peaks current from the two motors (spinning at power ON even though they shouldn't) are dropping the battery current so the system can't start, but after a few tries the caps are charged so they can absorb the peaks current.

I tried pull-down resistors on enable and command pins but nothing changed.

What am I doing wrong ? What should I do to prevent the motors from spinning at power ON ?

Hope I made myself understandable.

Thank you for your help.

Check that digital pin 8 is a PWM capable pin on your board.

const int motor_Stop = 127;  //PWM at 1/2 to stop motors

That's 50% speed, try:

const int motor_Stop = 0;  //PWM at 1/2 to stop motors

Also, PB0 (Arduino pin 8 ) is not a PWM pin.

Hi,
Can you post a picture of your project please?

Thanks.. Tom... :slight_smile:

tagadac:
My problem is at power ON. Before the Arduino gets totally setup my motors spins and sometimes I have to switch on and off multiple times the board before it gets really on.

Add 10k pull-down resistors to any signal that needs to be inactive during reset/power cycle.

tagadac:
What am I doing wrong ? What should I do to prevent the motors from spinning at power ON ?

You haven't done anything wrong. That's what the system is meant to do in the existing condition that you have it.

It's more of a case of what else you need to do. So now you are at a stage where you must learn about 'initial conditions'. This means, your system needs to have features included so that you get the desired start-up conditions every time you reset the system, and every time you do a power-up (or restart).

MarkT mentioned the use of pull-down resistors. This methods at the hardware level will help to keep control signals at a fixed value .... eg. 0V, until the arduino gets itself together for a start-up.

6v6gt:
Check that digital pin 8 is a PWM capable pin on your board.

Digital pin 8 is used as Digital pin. But I think I understand why you are telling me this.

outsider:
const int motor_Stop = 127; //PWM at 1/2 to stop motors
That's 50% speed, try:
const int motor_Stop = 0; //PWM at 1/2 to stop motors
Also, PB0 (Arduino pin 8 ) is not a PWM pin.

Actually in my case if you apply 50% duty cycle you have my motor stopped. Because you have 50% duty cycle from each branch of the H-bridge so you have no difference of potential applied to the motor so it is stopped.

MarkT:
Add 10k pull-down resistors to any signal that needs to be inactive during reset/power cycle.

I already tried putting pull-down resistors.

I think I find something while reading your messages (PWM on pin 8 ) and how I use the duty cycle, maybe I should put input 1A/2A and 3A/4A from L293 as Digital output on my Arduino (and not as PWM output) to select the direction of rotation and using the enables pins as speed control with PWM, with pull down resistor for start-up state...

I try this and let you know.

Thank you for you help !

@TomGeorge : At the moment it's just a board with two motors, nothing fancy :wink:

tagadac:
@TomGeorge : At the moment it's just a board with two motors, nothing fancy :wink:

Then why doesn't your schematic just show UNO board and the motor driver chip and how it is connected to your power supplies.

Tom... :slight_smile:

TomGeorge:
Then why doesn't your schematic just show UNO board and the motor driver chip and how it is connected to your power supplies.

Because it is NOT an UNO board but a custom board with an ATMEGA328P "Arduino Inside" with H-bridges.

But if you insist I can send you a picture of the board when I can ! ^^

tagadac:
Actually in my case if you apply 50% duty cycle you have my motor stopped. Because you have 50% duty cycle from each branch of the H-bridge so you have no difference of potential applied to the motor so it is stopped.

An h-bridge is meant to have one diagonal path active while the other diagonal path is cutoff, right?

Might be possible that your assumption or interpretation of usual desired h-bridge operation is incorrect.

tagadac:
Because it is NOT an UNO board but a custom board with an ATMEGA328P "Arduino Inside" with H-bridges.

But if you insist I can send you a picture of the board when I can ! ^^

I insist.
Thanks.. Tom.. :slight_smile: