Issues with TB6612FNG with arduino on battery power

Hi,

I have a custom board with TB6612FNG and Atmega328P with arduino uno bootloader. When I program it, the motor controller works well with PWM control. However, when I switch power from USB power to battery power, the motor no longer works, it kind of jitters and no motor movement. However, if I update speed to 255 or -255, it works on full speed.

So to sum it up, the motor controller works nice at full speed irrespective of USB power or battery power. However, if I reduce speed to anything but 255 or -255, it just does not work on battery power, but only on USB power. When I connect both battery and USB power, even then it does not work on lower speeds.

Battery (VM) is connected to a regulator (1117 - 5V - VCC) which powers the board and the motor controller and direct power - VM is connected to TB6612FNG VM pin.

Please find below code and also the schematic of custom board. Any help is appreciated.

#define PWMA 5
#define AIN1 10
#define AIN2 4
#define BIN1 7
#define BIN2 8
#define PWMB 6
#define motor_A 0
#define motor_B 1
#define FORWARD 1
#define REVERSE 0
#define RIGHT 1
#define LEFT 0

void setup()
{
  pinMode(PWMA, OUTPUT);
  pinMode(AIN1, OUTPUT);
  pinMode(AIN2, OUTPUT);
  pinMode(PWMB, OUTPUT);
  pinMode(BIN1, OUTPUT);
  pinMode(BIN2, OUTPUT);
  delay(5000);
}

void loop()
{
  motor_brake();
  delay(1000);
  motor_drive(FORWARD, 150);  // if this replaced with 255, it works on battery also, but at full speed
  delay(1000);
  motor_brake();              
  delay(1000);
  motor_drive(REVERSE, 150); // if this replaced with 255, it works on battery also, but at full speed
  delay(1000);
  motor_brake();             
  delay(1000);
  motor_turn(RIGHT, 150, 150); // if this replaced with 255, it works on battery also, but at full speed
  delay(1000);
  motor_brake();
  delay(1000);
}

void motor_brake()
{
  digitalWrite(AIN1, 1);
  digitalWrite(AIN2, 1);
  digitalWrite(PWMA, LOW);
  digitalWrite(BIN1, 1);
  digitalWrite(BIN2, 1);
  digitalWrite(PWMB, LOW);
}

void motor_drive(char direction, unsigned char speed)
{
  if (direction == FORWARD)
  {
    motor_control(motor_A, FORWARD, speed);
    motor_control(motor_B, FORWARD, speed);
  }
  else
  {
    motor_control(motor_A, REVERSE, speed);
    motor_control(motor_B, REVERSE, speed);
  }
}

void motor_turn(char direction, unsigned char speed_A, unsigned char speed_B )
{
  if (direction == RIGHT)
  {
    motor_control(motor_A, REVERSE, speed_A);
    motor_control(motor_B, FORWARD, speed_B);
  }
  else
  {
    motor_control(motor_A, FORWARD, speed_A);
    motor_control(motor_B, REVERSE, speed_B);
  }
}

void motor_control(char motor, char direction, unsigned char speed)
{
  if (motor == motor_A)
  {
    if (direction == FORWARD)
    {
      digitalWrite(AIN1, HIGH);
      digitalWrite(AIN2, LOW);
    }
    else
    {
      digitalWrite(AIN1, LOW);
      digitalWrite(AIN2, HIGH);
    }
    analogWrite(PWMA, speed);
  }
  else
  {
    if (direction == FORWARD)
    {
      digitalWrite(BIN1, LOW);
      digitalWrite(BIN2, HIGH);
    }
    else
    {
      digitalWrite(BIN1, HIGH);
      digitalWrite(BIN2, LOW);
    }
    analogWrite(PWMB, speed);
  }
}

Have you tried measuring the voltage on the motor in the two situations?

What sort of battery are you using?
Can it produce the current you need?
Is it flat?

Voltage when powered by USB will be around 2-2.5v and when powered by battery, its 0V.
However, when I change the speed to 255, voltage across the motor is 6.5v (on battery). Motors used are N20 motors which can be powered from 3v to 8v.

Battery are two Lithium Ion battery with rating upto 2500mAh and yes, it does produce enough current since the motors run at full speed when "speed" is set to 255 or -255.

Can this be anything related to how battery power powers the chip and motor controller, or which reaches first, VM or VCC, or something like this?

Perhaps the LM1117 is not giving you the 5V you get with the USB connection. I realize its rated for 800ma but it's in that path.

You mentioned "custom" board. Have you looked at how the traces and grounds are run?

I assume the USB power comes in on the UART connector. If this is the case how does U2 get BatIn voltage?

Output is 5.06V through regulator and 800mA, I am not sure though.

You mentioned "custom" board. Have you looked at how the traces and grounds are run?

Can you please explain more on this as I am not sure if there is an issue here.

I assume the USB power comes in on the UART connector. If this is the case how does U2 get BatIn voltage?

This is the surprising fact. Though U2 does not have anything on VM when connected through UART, it still runs the motor, but a lot more slower.

Hi,
Can you post a picture of your project so we can see your component layout?
Can you post a jpg export of your PCB so we can see your PCB track layout?

Battery are two Lithium Ion battery with rating upto 2500mAh and yes, it does produce enough current since the motors run at full speed when "speed" is set to 255 or -255.

How are they connected, series or parallel.
Have measured the 5V output of the 1117 when you have this fault?
What is the switch that changes to battery, how is it configured switch wise and does it work?

Thanks.. Tom... :slight_smile:
PS, Can you produce a schematic with ALL the wires connected to show power and signal flow.
The one you provided is okay for PCB design, but useless for troubleshooting.

The cells are connected in series giving 7.4v @ 2500mAH. The 5v output is still around 4.85v when powered on and when at fault. The switch is just a power switch which connects battery to PCB, a break switch. Yes, it does work correctly.

Attached a part component layout, which might help.

Hi,
U3 and U4 I assume are the 1117?
That is not the entire PCB is it.
I see you have a CHG connection as well.
Have you measured the 5V pin on the 328 when the fault occurs?
Some 0.1uF bypass capacitors at IC power pins would help to.

I think an updated schematic is needed.
Please a picture of your project.

Tom... :slight_smile:

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.