• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Arduino w/ PWM expander and DC motor issue

pidgin

New Member
Hi there.

I am new to the forum. so.. Hi everyone:)

I am trying to control several DC 3-5v motor/pump with Arduino, using PCA9685 PWM expander.
I have connected one such motor, with a rectifying diode (IN4007), to 5V using a BC337 transistor, 2.2K resistor, the PCA9685 module, Arduino Due and 3.3V and 5V sources (with common ground). as in the diagram below.

The program on it runs a sweep on 0-100% and back on port 0.

Now..
IF I do NOT connect the motor, but instead put some random resistor load, everything works fine. I can measure across the load resistor a voltage going up from 0 to 5 and back down. All works 100% fine.

HOWEVER..

IF instead, I connected the motor where it should be, the program goes crazy as soon as the load across the motor gets to about 2-3 volts (or about 1.5V on the port 0 PWM).
The PWM stops updating and the serial console debugging clearly shows that something drags down the Arduino (the console stats updating slowly instead of the regular speed), due to I2C communication issues apparently (which hints that the PWM expander module went crazy). The Arduino can't seem to communicate with it anymore.
Disconnecting the motor at this stage doesn't help. Even then, the PWM doesn't update. The voltage on the 0 port remains stuck at the same level.. same for the motor. Things just get stuck.
Resetting the Arduino doesn't help.
If I disconnect the PWM module, the console logging goes back to regular speed (again, hinting that the PWM module went "crazy" and it is what is causing the console log drag).
Also, plugging the PWM module back in, doesn't solve the issue right away all the time, even at the beginning. It sometimes needs to "rest" for a bit. Then, once plugged in again it resumes working again like before.. meaning, only for the first second or so, until it goes crazy again.

I have no idea what is going on.
At first, I thought it has to do with a voltage created by the engine.. so I've added the rectifying diode. But that didn't help. Same issue.
I've also added a diode on the base, thinking maybe for some reason there is a current trying to flow back into the PWM module through the (orange) PWM port. But that also didn't help.

I am kind of lost here :/

Why would the PWM module go crazy like that?
What causes it?
How do I fix it?

Would greatly appreciate any help.

pwm-issue.png
 
Last edited:

rjenkinsgb

Well-Known Member
Most Helpful Member
Do you have really heavy wires between the various grounds?
Or, the logic boards as one circuit and the motor as another, with no interconnection except from the PWM output and ground to the transistor base resistor and emitter.

The motor could be taking quite a bit of current in short pulses; possibly enough to upset the supply voltage to one part of the circuit, if any ground wires are shared between the two parts.

Another possibility is that you need a schottky or fast-recovery diode across the motor, rather than the 4007.
The 1N4000 series are slow recovery diodes and can continue to conduct for a short time after they are reverse biassed, which can really mess up some high speed circuits.
 

pidgin

New Member
There aren't heavy currents really. the motor is small.
PWM port sends the signal to the base at 1mA. that's low.
the motor draws about 400mA. Also nothing really serious. right?
The wire I use are regular jumper wires. Nothing gets hot. Not the transistor, not the PWM module, not the buck converters that are connected to a 30A 12V PSU.
So I don't think it is current or power issue. Would you agree?

As for the diode.. do you really think that a tiny 3.3V DC motor is so disruptive, that it gets the PWM module out of whack? And so much so that a rectifying diode (that is the recommended diode from what I can tell for such motors and simple coils) is not enough in this case?

How would a reverse voltage get to the PWM module anyway? how would it go from the collector all the way to the base.. and then to the PWM module?

(#IWishIHadAScope)
 

Musicmanager

Active Member
I'm no expert but I would like to offer a couple of thoughts .. .. .

1. The PCA9865 module is intended for driving Servo Motors- back and forth - not this type of motor.

2. I think the circuit might give you a better chance if you connect the 5v battery to the green screw terminals and the motor wiring to the red/black pins .. .. this might help .. https://learn.adafruit.com/16-channel-pwm-servo-driver/hooking-it-up
You would then need to add some PWM control to the Arduino sketch and connect a PWM pin to the corresponding yellow pin.

MM
 

pidgin

New Member
I'm no expert but I would like to offer a couple of thoughts .. .. .

1. The PCA9865 module is intended for driving Servo Motors- back and forth - not this type of motor.

2. I think the circuit might give you a better chance if you connect the 5v battery to the green screw terminals and the motor wiring to the red/black pins .. .. this might help .. https://learn.adafruit.com/16-channel-pwm-servo-driver/hooking-it-up
You would then need to add some PWM control to the Arduino sketch and connect a PWM pin to the corresponding yellow pin.

MM
About #1: I am not driving the motor directly with the PWM module. As you can see, I take the PWM output, and pass it as a signal to a Transistor, which translates the 3.3V PWM signal to a 5V motor signal. So, it's not the PWM module that "drives" the motor directly.

about #2:Again, as I don't use the module itself to drive the motor, but rather just serve as a PWM expander, and pass the PWM signal to a transistor, which is the driver for the motor, I don't use the green terminal on the PWM module, and therefore also not the red/black pins on the PWM module, which are basically the same, only laid out for servo/led connectors.
 

pidgin

New Member
hmmm.. the plot thickens..
I've tested it with other types of motors, and it works 100%.
I've tested it with 12V motors even, feeding the collector with 12V, and.. works 100% fine.

The problem is specifically with that motor I need it to work
Something about it makes the PWM expander go crazy and stop working.
I am not sure what, of how it even gets to affect the PWM expander, as I thought the rectifying diode will take care of interferences from the motor, and even when not, that any voltage on the collector, will at best interfere with the transistor, and not find its way to the PWm module.

Any ideas?
 

Pommie

Well-Known Member
Most Helpful Member
Try adding a 10uf capacitor in parallel with the motor. I had exactly the same problem but with the Arduino crashing.

Mike.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
There aren't heavy currents really. the motor is small.
PWM port sends the signal to the base at 1mA. that's low.
the motor draws about 400mA. Also nothing really serious. right?
The wire I use are regular jumper wires. Nothing gets hot. Not the transistor, not the PWM module, not the buck converters that are connected to a 30A 12V PSU.
It's not a matter of heat in such things, it's momentary voltage drops across a wire when current is drawn, that cause the "ground" voltage between different parts of a circuit to be offset. That can cause chaos.
Ground routings between different parts of a circuit can be very critical.

As it works with different motors, try adding a "snubber" across the motor - eg. a ten ohm resistor and a 0.1uF capacitor in series.
That can absorb noise spikes without drawing excess current.

I'm not happy with the idea of a large cap directly across the motor, as each time the PWM transistor turns on that will take a high current pulse that could cause other problems. A cap in a PWM circuit should ideally be fed via an inductor to limit the surge current.


Re. MMs comment, the PCA9685 is a PWM IC intended for LEDs and each output is conventional PWM, regardless of the servo-style connections.
 

pidgin

New Member
Hi all.
When I also tested other motors, which I said work before, it seems they did work.. but only for a bit longer.
Still, after a while the PWM modules gets stuck. (and I've tried two, from two different places)
This was even true with a LED (and 220ohm resistor)

So...

I've decided to simplify things even further, and moved to using an HBridge (L298N) instead of my transistor circuit, just to see if it is something that I do wrong.. maybe choosing a wrong transistor as some suggested, maybe resistor issue.. or capacitor..
But nope. Seems that with the new layout, things still go crazy with that motor.

I'm testing now with other motors as well.. just to see.

As it works with different motors, try adding a "snubber" across the motor - eg. a ten ohm resistor and a 0.1uF capacitor in series.
That can absorb noise spikes without drawing excess current
I will try this next, though with the L298N, it SHOULD be fine without any such intervention. no? Shouldn't the L298N dual H-Bridge module have that already?
Shouldn't that module already implement proper isolation?

PS
I now take even extra precautions and:
1. Connect the Arduino to 5V
2. Connect everything with one supply of 5V
3. Connect the OE on the PWM module to ground
4. Connect the VCC of the PWM module to 5V, despite not using it

pwm-issue.png
 
Last edited:

pidgin

New Member
I'm trying now to use a totally separate voltage source for the motor (basically for the VCC of the L298N.. though, YES.. of course I connect the grounds together)
 

Pommie

Well-Known Member
Most Helpful Member
Agree with the snubber. I was simply turning a motor on/off and hadn't comsidered pwm. From looking on the web, it appears your expander is I2C. This get confused if interrupted during transfer, when you compile is one such interruption. If you can hold the Arduino in reset while you reset the expander board, this will synchronise them again.

Mike.
 

pidgin

New Member
Agree with the snubber. I was simply turning a motor on/off and hadn't comsidered pwm. From looking on the web, it appears your expander is I2C. This get confused if interrupted during transfer, when you compile is one such interruption. If you can hold the Arduino in reset while you reset the expander board, this will synchronise them again.

Mike.
Hi Mike.
I am not sure why the I2C would get interrupted and out of sync?
Any ideas?

Here is an update of an experiment I just ran that I hope will help pinpoint the issue.

OK!.. So...
I have updated the test code to use BOTH a PWM on the Arduino due, as well as on the PWM expander.
I've connected theL298N to use the Arduino Due PWM signal.
So now, the PWM expander module is not connected to any load or any driver. It just sits there generating equivalent PWM to the one on-board of the Arduino Due.

So.. IF the issue was that there is a signal going back from the driver (L298N or my circuit) back to the PWM expander, which causes the expander to hang, then now in the new setup there isn't such connection. Right?

So.. what happens?
The PWM expander module hangs anyway!
WHILE the on-board Arduino Due PWM port continues to function normally.

So.. I think VERY APPARENTLY, the issue is not at all with the fact that the driver or motor takes too much or too little from the PWM expander.
The issue seems to that the motor generates some interference that disrupts the PWM expander.

So what do you think?
Can it be maybe due to some effect the motor has on the power supply?
Or maybe
Can it be that this interference sips into the I2C bus and gets the PWM expander module go crazy?
Or
Do you have any other hypothesis?

I think we are getting closer to the root of the issue. No?
I hope so at least.
 

Pommie

Well-Known Member
Most Helpful Member
Are you able to power the Arduino from a desperate power supply and disconnect the 5v line from the Arduino. The I2C can get interrupted when the Arduino gets reset by the PC to upload new code.

Mike.
 

pidgin

New Member
Are you able to power the Arduino from a desperate power supply and disconnect the 5v line from the Arduino. The I2C can get interrupted when the Arduino gets reset by the PC to upload new code.

Mike.
Hi Mike
I've actually tried before powering the LN298 from a seperate power supply and that didn't help.
Maybe the common ground still passes some interferences.

However, I was able to verify that the issue is not the PWM Expander specifically.. but I2C in general.
How did I verify that?
I've connected an LCD 1602 I2C module to display simple info during the test process.
What happens to the PWM Expander happens to the LCD as well.
Soon after connecting the motor, the LCD freezes and the I2C communication gets interrupted.
A Reset for the Arduino doesn't resolve the hanging state.
What I need to do is disconnect the LCD module, and touch the pins on that module. Maybe that discharges some capacitor on the module.. I'm not sure. But once I do that, I can reconnect it and reset the Arduino.. and then it's back to normal (until I reconnect the motor again, of course)

I will try now to power the Arduino from a separate power source.
For one, I can do that from the PC, no? Without a connection to the 5V of the PSU that runs the motor.
I will try both.
Update soon.
 

pidgin

New Member
Are you able to power the Arduino from a desperate power supply and disconnect the 5v line from the Arduino. The I2C can get interrupted when the Arduino gets reset by the PC to upload new code.
Mike.
I've connected the Arduino AND the LCD unit to a separate power source of 5V.
Connected common ground.
ThePWM port of the arduino goes to the L298N, which is fed by a serparate 5V power source.
Things work until I connect the motor. Then it works for a very brief moment until either the LCD starts showing gargabe.. or totally hangs.
A reset of just the Arduino doesn't help. I need to disconnect and reconnect the LCD module. (and sometimes touch its pins)

Any ideas how to isolate the noise that comes from the engine/L298N? so that it doesn't interfere with the I2C on the Arduino side?
 

pidgin

New Member
I'm thinking of using an opto-coupler, to totally isolate the engine from the arduino and pwm expander side. what do you think?
I don't have experience with optocouplers yet. I'm studying it as we speak. I wonder if they are fast enough to support PWM.
 

Pommie

Well-Known Member
Most Helpful Member
I'm at my daughter's at the.moment and won't be back until Monday. There is a way to "uncrash" the I2C bus which I can post when I'm back. It's just looking at the (I2C) data line and sending clock pulses until it's (edit) high.

Opto should work and are fast enough for WPM.

Mike.
Edit, corrected low to high.
 
Last edited:

Latest threads

EE World Online Articles

Loading
Top