Issues with TB6612FNG with arduino on battery power

Go To Last Post
7 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

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. Is this anything related to how battery power powers the chip and motor controller, or which reaches first, VM or VCC, or something like this?

 

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);
  }
}

 

Attachment(s): 

Robot building is all about sharing & learning
-----------------------------------
www.robotplatform.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What power supply voltage do you use and what battery voltage. Difference with full speed and variable speed is no PWM. Can you verify that you have stable PWM with battery power? Does it stay the same (duty cycle and stability of duty cycle) when you disconnect the motor?

 

There is a distinct LACK of power supply bypassing on each MCU power pin, including AVcc. If you are using the ADC, you should also have Vref bypassed. I would use a good 0.1uf to 1.0uf ceramic cap to ground from each Vcc pin.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

Last Edited: Tue. Mar 23, 2021 - 09:48 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Power is supplied by two Lithium Ion Cells - 2500mAh at 7.4v.

 

Difference with full speed and variable speed is no PWM. Can you verify that you have stable PWM with battery power? Does it stay the same (duty cycle and stability of duty cycle) when you disconnect the motor?

Whether the motor is connected or not, there is no PMW signal at all. When the speed is full (255 or -255), voltage is around 6.25-6.5v and when speed is less (say when set to 150 or 200), voltage across motors or motor pins is 0 (zero).

 

There is a distinct LACK of power supply bypassing on each MCU power pin, including AVcc. If you are using the ADC, you should also have Vref bypassed. I would use a good 0.1uf to 1.0uf ceramic cap to ground from each Vcc pin.

I have not added any capacitors to VCC and AVcc pins. Is this the reason for PWM not working? For now, I am testing and using only motors and not using ADC.

 

Robot building is all about sharing & learning
-----------------------------------
www.robotplatform.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You NEED capacitors on those Vcc pins. In extreme cases, that can cause the program execution to be "crazy". Driving almost any motor is an extreme case.

 

Also, do you have the required capacitor on the output of the voltage regulator? Depending on the linear regulator, you need somewhere from 10uf to 470uf. The regulator may be unstable without that cap, especially with relatively "soft" sources, such as batteries.

 

Jim

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

praveen_khm wrote:
Is this anything related to how battery power powers the chip and motor controller, or which reaches first, VM or VCC, or something like this?
Try powering the motor controller VM from BATRAW instead of BATN unless the battery can be wired in reverse.

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

praveen_khm wrote:
Power is supplied by two Lithium Ion Cells - 2500mAh at 7.4v.
Marginal for a 1117 regulator (dropout) due to the drop across diode D1 especially when the motor is driven.

1117 are a good choice though its NPN output has some drop; p pass transistors will be better for dropout though can have a stability issue (PMOS voltage regulators are near jelly beans)

1117 aren't all alike; the output capacitor's characteristics (ESR range) will vary between 1117 manufacturers.

 


NCP1117LP - Voltage Regulators, 1.0 A Low-Dropout Positive, Fixed and Adjustable

 

Power Supply | AVR® Microcontroller Hardware Design Considerations

 

"Dare to be naïve." - Buckminster Fuller

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Also, do you have the required capacitor on the output of the voltage regulator? Depending on the linear regulator, you need somewhere from 10uf to 470uf. The regulator may be unstable without that cap, especially with relatively "soft" sources, such as batteries.

 

Yes. There is a 100uF 16v Tantalum cap on both input and output on the voltage regulator. I will try adding a capacitor and check the results.

 

Marginal for a 1117 regulator (dropout) due to the drop across diode D1 especially when the motor is driven.

I have tried removing the diode but still the results are the same.

Robot building is all about sharing & learning
-----------------------------------
www.robotplatform.com