Arduino w/ PWM expander and DC motor issue

Thread Starter

pidgin

Joined Oct 30, 2020
21
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 BC547 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
 

KeithWalker

Joined Jul 10, 2017
3,063
What are you using to power everything? You are obviously drawing more current than it can supply, so the voltage is dropping to a point where you loose control.
Is the transistor getting hot? If the base voltage falls too low, the transistor will not be saturated and will start dissipating a lot of power. That would explain why the circuit will not reset immediately.
Regards,
Keith
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
What are you using to power everything? You are obviously drawing more current than it can supply, so the voltage is dropping to a point where you loose control.
Is the FET getting hot? If the gate voltage falls too low, the FET will not be saturated and will start dissipating a lot of power. That would explain why the circuit will not reset immediately.
Regards,
Keith
I am using a 20A 12V power supply with two buck converters (5V and 3.3V).

The PWM signal going to the base draws between zero and 1.1mA (basically nothing)..
and the motor draws between 0 and 500mA (also very low). So I don't think it is load/current limit issue.

The Transistor doesn't get hot at all.
I actually moved to BC337, so that one is rated even higher. And even when only using 3.3V on the collector, the same problem occurs.

The "reset" issue is with the PWM module. It is that module that goes crazy and doesn't go back to working normally until after a short rest.

If this was a FET issue, the problem wouldn't affect the Arduino or the PWM. Right?
When disconnecting the motor, things with the PWM should be all fine.. and the PWM signal should show a proper sweep between 0 and 3.3V. But it doesn't. It basically freezes on 1.5 or 1.6V or whatever last value it had.
 

djsfantasi

Joined Apr 11, 2010
9,156
Your picture doesn’t show a connection between the PCA9685 ground and the 5V ground. Without that, there is no reliable reference between your PWM signal and the base of the BC547. Yet you say there is. The fact that it works unreliable hints that the connection is through some component. Can you confirm there is a common ground?
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
Your picture doesn’t show a connection between the PCA9685 ground and the 5V ground. Without that, there is no reliable reference between your PWM signal and the base of the BC547. Yet you say there is. The fact that it works unreliable hints that the connection is through some component. Can you confirm there is a common ground?
Yes.
Though, as I wrote in the first paragraph, grounds are common "(with common ground)".

I think that, when you show the ground symbol, with the three horizontal lines, it means common ground.
no?
 

KeithWalker

Joined Jul 10, 2017
3,063
You are not using enough base current to saturate the BC337. Check the data sheet. They recommend a base current of 50mA to achieve a Vce saturation of 0.7V at a collector current of 500mA. When the base current is 50mA, the Vbe is 1.2V That means that if you have the full 3V from the PWM expander, you need a base resistor of a maximum of 36 ohms.
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
You are not using enough base current to saturate the BC337. Check the data sheet. They recommend a base current of 50mA to achieve a Vce saturation of 0.7V at a collector current of 500mA. When the base current is 50mA, the Vbe is 1.2V That means that if you have the full 3V from the PWM expander, you need a base resistor of a maximum of 36 ohms.
I am checking the datasheet and it seems to indicate 1mA is fine.
https://www.onsemi.com/pub/Collateral/BC337-D.PDF

Also, in effect, it works.
As I said, the voltage and amperage collector-emitter and the motor/load works fine.
The motor runs just fine, for a while.. until the PWM module gets stuck.
So I don't think this is the issue.

The problem is entirely not in the transistor part.. but the PWM.
The problem is that the PWM expander stops working. And even then, the motor works.. only the speed stops changing.. because the base voltage/current gets stuck with the PWM getting stuck.

I hope I am making things clear.
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
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
https://www.aliexpress.com/item/4001120259064.html?spm=a2g0s.9042311.0.0.27424c4dLoAjhh
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?
 

peterdeco

Joined Oct 8, 2019
484
It looks like you're using a regular 1N4000 series diode across the motor. Try 1N4148 and put a capacitor across it too. We use .1uF discs and 10uF electrolytics when noisy motors drive our microcontrollers crazy.
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
It looks like you're using a regular 1N4000 series diode across the motor. Try 1N4148 and put a capacitor across it too. We use .1uF discs and 10uF electrolytics when noisy motors drive our microcontrollers crazy.
How would 1n4148 help? I've tried the capacitor part in its own before. It didn't help.
By the way.. I'm running a test now, for an overnight run without a motor at all, to see if the pwm expander gets stuck anyway, even if it takes longer.. Just to make sure.
 

bertus

Joined Apr 5, 2008
22,270
Hello,

@peterdeco , The 1N4148 will likely be to weak as it is only capable of a current of 100 mA.
When you want a faster diode, have a look at the UF4000-UF4007.

Bertus
 

KeithWalker

Joined Jul 10, 2017
3,063
I am checking the datasheet and it seems to indicate 1mA is fine.
https://www.onsemi.com/pub/Collateral/BC337-D.PDF

I hope I am making things clear.
Which part of the data sheet indicates that 1mA is fine?
Do you understand the data sheet?
The chart below (from your data sheet) shows the base current needed to saturate the transistor for different collector currents:
BC337.jpgIt indicates that with a collector current of 500mA, you need at least 30mA base current to be even close to saturation. 50mA would ensure that it is properly saturated under all conditions.

Fix the obvious problem and the rest will probably go away!
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
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.

I was hoping (and under the impression) that the L298N SHOULD resolve things. Shouldn't the L298N dual H-Bridge module have all the protections, isolations and best practices?

pwm-issue.pngPS
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
 

Thread Starter

pidgin

Joined Oct 30, 2020
21
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)
 
Top