2
$\begingroup$

I'm trying to build a self-balancing two-wheeled segway-like robot. I'm currently using two 12v DC motors that draw approximately 600milliamps of current each. I've noticed that when my robot tries to switch directions, it often does weird things like not switch at all or completely stop rotating altogether. I suspect that when the motor controller (L298N H-Bridge) switches direction, it may be drawing even more current on it and this current is somehow affecting my microcontroller.

If that is the case, what can I do about it? How can I prevent this large spike in motor current draw from affecting my microcontroller?

$\endgroup$
3
$\begingroup$

As explained in my answer to What is stall current and free current of motors? when switching direction on a motor, you can end up drawing more than the maximum normal current rating. This can cause trips to be thrown, amplifier shutdown or voltage drops and loss of control.

One option is to try to reduce the stress on the motor and amplifier. For instance instead of going from -100% to +100%, try going from -100% to 0% briefly, before going to +100%, or limiting the rate of change of the torque demand.

What you specifically need to do will depend on the time constant of your mechanical system, the control loop update rate and the responsiveness/stability that you require. All of these factors should be balanced to keep you system within it's physical limits.

$\endgroup$
3
$\begingroup$

I've experienced a similar problem before. For me, the root cause was insufficient battery power. When my motor tried to draw peak power it caused the battery supply bus to brown out. This led to supply voltage dropping below the minimum rated voltage for the motor controller. The master board was fine as the brownout voltage was still above that minimum.

When the motor controller browned out it cleared its own enable bit and the motor stopped responding. Additionally, it required a certain "arming" sequence before it would respond to speed commands, and I had only programmed those to be sent on initial startup. Since the master board was never reset, the master continued sending valid speed commands to the motor controller, but the motor controller failed to respond because it hadn't been (re-)armed.

Potential solutions for you:

  1. Check that your existing battery is actually fully charged.
  2. You can add more batteries (or battery packs, depending on your configuration) in parallel to boost your supply capacity. As with all batteries, they should all be fully charged before you connect them all together.
  3. If your issue is that your controller is getting reset, you could provide two different batteries. One larger battery to run the H-bridge chip and the motor and a (not necessarily) smaller battery to run your controller. You will need to ensure that the controller, H-bridge, and motor all share a common ground or the H-bridge may fail to respond to PWM signals. This is a less-desirable option, because the motor response will be limited by your supply power (they'll accelerate slowly), but it's a quick/cheap fix if your existing batteries are hard to source.
  4. You could try adding a capacitor as jdios said. I would argue it would be better to use a large capacitor on the battery-supply-side of the H-bridge than to put it next to the motor, but just because the motor is bidirectional. Large capacity electrolytic capacitors are pretty easy to come by, but they're polarized. As I mentioned in my comment in jdios' post, the capacitor does smooth voltage, and it provides a short-duration current surge during high-demand conditions by preventing the supply voltage from falling.

Mark Booth's answer is also valid, and would probably be my go-to answer (it was how I solved my own problem), except for the fact that you're trying to do control. Adding a rate-limiting scheme as described there is effectively creating an actuator saturation limit, which then will cause more problems for your controller (control windup).

$\endgroup$
  • $\begingroup$ As it stands, I already had two different power supplies (one for the motors + H Bridge and the other for the arduino controller) with the grounds connected. Can a brown out still occur when using two separate supplies? Also, can you elaborate on why the motors must necessarily accelerate more slowly when using the two power supplies? $\endgroup$ – Paul Oct 1 '18 at 3:42
  • $\begingroup$ @Paul - By your problem description, the power supply you have attached to the motors is insufficient (wired power supply, battery bank, etc.) If you choose not to upgrade that power supply, then you should still be able to avoid browning out the microcontroller by providing the microcontroller with its own power source. This would prevent the microcontroller from resetting on undervoltage, but it's not going to do anything to fix the under-supply issue for the motors, so the motors should continue to try to rotate (as opposed to stopping completely, as described in your question). $\endgroup$ – Chuck Oct 1 '18 at 20:02
1
$\begingroup$

You can try to put a capacitor in the motor terminal. Very close to the motor.

$\endgroup$
  • $\begingroup$ You put a capacitor there to smoothen the voltage, not to absorb current spikes. $\endgroup$ – Paul Sep 20 '18 at 13:43
  • 1
    $\begingroup$ Welcome to Robotics jdios. Thanks for your answer but we are looking for comprehensive answers that provide some explanation and context. Very short answers cannot do this, so please edit your answer to explain why it is right, ideally with citations. Answers that don't include explanations may be removed. $\endgroup$ – Mark Booth Sep 20 '18 at 13:50
  • $\begingroup$ @Paul - Voltage dictates current. Voltage is the potential, current is the flow. If the capacitor smooths the voltage, it necessarily damps the current spikes, because current can only spike if voltage does (or, in your case, current can only drop because voltage drops). $\endgroup$ – Chuck Sep 20 '18 at 17:31
  • $\begingroup$ Could you elaborate on where “on the motor terminal, close to the motor” means? Can you show a picture or schematic of what you mean? $\endgroup$ – Paul Sep 22 '18 at 17:53
1
$\begingroup$

It's maybe not this at all, but when a motor or any inductive system suddenly stop it create a short opposite surtense that can affect your microcontroleur. The solution is to ad a flyback diode within your motor driver. Most of the motor's driver (including the H-bridge) are provide with flyback diode built-in but you can check if yours got one.

Here the wiki if you want to lear more about flyback diode https://en.wikipedia.org/wiki/Flyback_diode

Hope I've help you.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.