System works when powered by USB, but behaves weirdly on switching power supplies

blinkypiper

New member
Hello!

I've found this forum incredibly helpful in the past, but this is my first time reaching out with a question. I'm working on a project that seems like it should be simple, but I'm being deviled by a problem that I think is electrical, rather than rooted in the code.

I'm using a Teensy 4.0 to control two brushed DC motors, which a few electromechanical switches triggering different cases. The basic system is laid out below, BUT, I didn't end up using the coin cell battery AND there are 3 switches AND they are wired with external pullup resistors (10kΩ).

The 24V supply (MEAN WELL LRS-600N2) can supply 25A, the 5V (MW RS-15-5) can supply 3A. The motor driver (Cytron MDD-20A) can supply 20A per channel, and the motors are rated up to 80W @ 24V, but I'm running them at low speeds. The limit switches have wires that are ~6 feet long.

Screenshot 2024-04-02 at 5.47.06 PM.png

Here's what is happening: things work like they should when I have the USB cable plugged into my laptop (on battery) and two power supplies are getting mains power. I now know that I should cut the trace connecting VIN and VUSB on the MCU, but I have not done this yet.

When I do not have the USB cable connected to my computer, the system follows the basic logic, but the drive motor will randomly cut out, or both motors will stop until a switch is hit, triggering the next case. It's almost like something isn't getting enough current. BTW, I've removed all Serial calls in the code.

I would greatly appreciate any insight. I can post my code, but this really seems to be an electrical issue since things work fine sometimes.
 
I don't see any connection in this diagram between Teensy and the dual motor driver.

Assuming there is indeed a connection for Teensy to control the motors, check the GND wire. Perhaps GND is not properly connected between them? And maybe that 24V power supply connects the dual motor driver to earth ground? If so, when Teensy connects to your PC's USB port, which is earth grounded by the AC power cord, maybe that ground connection through the USB cable allows a good enough common ground for it to work.

Just a wild guess really, but we see this sort of issue pretty regularly on this forum where a missing GND wire results in things sometimes working, sometimes failing depending on whether other grounded things are connected (classic example is connecting an oscilloscope probe magically makes the project start working before you even make your first measurement...)
 
I don't see any connection in this diagram between Teensy and the dual motor driver.

Assuming there is indeed a connection for Teensy to control the motors, check the GND wire. Perhaps GND is not properly connected between them? And maybe that 24V power supply connects the dual motor driver to earth ground? If so, when Teensy connects to your PC's USB port, which is earth grounded by the AC power cord, maybe that ground connection through the USB cable allows a good enough common ground for it to work.

Just a wild guess really, but we see this sort of issue pretty regularly on this forum where a missing GND wire results in things sometimes working, sometimes failing depending on whether other grounded things are connected (classic example is connecting an oscilloscope probe magically makes the project start working before you even make your first measurement...)
Thanks so much for the quick reply, Paul. I'm embarrassed by the first drawing I posted, so I made a new and accurate one below.

Both power supplies are connected to mains earth, but I'll double check all the connections to make sure they're ok.
Screenshot 2024-04-24 at 7.00.15 PM.png
 
Is this any chance that the ground wire between the Teensy and the motor driver (with the ferrite bead) is forming a ground loop?
 
Ideally all the wires from mcu to motor driver should go through the same ferrite so it removes common-mode interference but doesn't add differential mode interference.

Definitely add 10nF to 100nF on those limit switch inputs next to the mcu, change 10k to 2k2 as well perhaps.
 
I would also check for continuity between the power supply safety grounds and the V- supply pins of the Power Supplies to make sure you are not creating a ground loop between the safety ground and the Ground pins of the Teensy and Motor Driver. Bad grounding has been a thorn in my side for over 50 years with large systems.

Regards,
Ed
 
Thanks everyone! So far it seems like putting all the wires between the MCU and the motor drive through the same ferrite bead, plus adding bypass caps on the inputs has solved the problem. Because the positional switches take >150ms to fall and rise again, I'm also going to change the code to ignore any switches that are shorter than...75ms or something.

The Teensy forum is the best.
 
Back
Top