PWM Motor Speed with Trinket

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

PWM Motor Speed with Trinket

Post by skr0d »

I am working on a project that needs me to control the speed of a motor (actually, a pair of motors).

The power supply is 4 C batteries, and when I connect the motors across the batteries, they work fine. When I attempt to connect across the NPN transistor, I get a voltage drop to about .4v. I tested everything with an LED, and it worked fine, but switching to the motors doesn't appear to work. Do I need something more powerful than a 2N2222 transistor?

I basically followed the tutorial here: https://learn.adafruit.com/adafruit-ard ... -dc-motors

The only difference, is that I have 2 motors instead of one, and I used 220 ohm resisters instead of 270, cuz I didn't have any. ;)

When the analogWrite is at 128-240 I hear a small whine from the motors, like they are trying to spin, but they don't. When I increase to 255, I get nothin.

Switching from analogWrite to digitalWrite does not help the situation.

Oh, btw, I also have a string of NeoPixels (6) on a different pin, and they are working fine. Removing them from the equation does not help.

Thanks for any input!

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: PWM Motor Speed with Trinket

Post by adafruit_support_mike »

sKr0d wrote:Do I need something more powerful than a 2N2222 transistor?
That's possible. How much current do the motors draw when they're connected directly to the battery stack?
sKr0d wrote:When the analogWrite is at 128-240 I hear a small whine from the motors, like they are trying to spin, but they don't. When I increase to 255, I get nothin.
That sounds like a low-current situation. The pulses of current flowing through the coils are enough to make them vibrate, but not enough to make them spin.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PWM Motor Speed with Trinket

Post by zener »

Can you provide a good picture of your connections?

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

After some digging, I discovered that the two motors had some internal circuitry that may be causing some issues. There were 4 resisters in an x-formation with some smaller caps, probably for noise reduction. I'm going to remove all of that and get down to the bare motors and see if that makes a difference.

The motors are part of a nerf gun, and I didn't see the circuity buried below all of the plastic. We'll see what happens next!

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

Removing the extra resistors didn't work. :(

When I run the motors (wired in parallel) on the 6v C-Battery stack, they draw 1.1A startup and .7 sustained.

The 6v stack supplies 6.3v to my circuit at idle, and drops to 5.5v when the motors are running.

With PWM set to 128 (50%) I see 5.1v at the collector side of the transistor. That drops to .2v when I attach the motors across the diode.
With PWM set to 255 (100%) I see 6.37v at the collector side of the transistor. That drops to .4v when I attach the motors across the diode.

Solder joints are fresh, and work fine when the mechanism is attached directly to the battery. I only get stuck when attempting to drive the motor through the 2N2222 transistor.

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

I just read that the max base current on a 2N2222 is 700mA, and 500mA on some versions. That probably means that it dues not supply enough current for this application.

So, should I switch to a TIP-120 or something different? I need to be able to do PWM, so fast switching is probably necessary.

User avatar
zener
 
Posts: 4567
Joined: Sat Feb 21, 2009 2:38 am

Re: PWM Motor Speed with Trinket

Post by zener »

The transistor is probably undersized but I don't think it explains the results you are seeing. The collector voltages you are measuring seem reasonable and should be running the motors. If the collector side of the motor measures .2V to ground, the high side should be the battery voltage and the motor should run. Do you have the flyback diode installed in the correct direction?

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

The voltage measurement is between the collector and vcc, as the emitter is tied to ground. The diode has the anode connected to the collector and the cathode connected to vcc.

I'm going to try a TIP-120 today, as they appear to be rated at 2A.

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

YAY for my darling, the darlington transistor!!

Switching from the 2N2222 to the TIP120 made all the difference in the world. The current load of the 2 motors (1.2A) was too much for the 2N2222 that caps out at 700mA. Swapping in the TIP120 give me up to 2A of current.

I'm now able to use PWM to control the speed of both motors, and my project continues! If all goes well, it will make an appearance on Show and Tell!

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

Soooooooo close...

In my circuit, I have two Trinket outputs controlling three motors using PWM. The first output (pin0) runs a pair of motors, and the start as soon as the Trinket boots. When I push a button, the second output (pin1) is supposed to start up a third motor. Now that I have swapped out the 2N2222's for TIP120's, I am having trouble with the second output.

Here is what happens:
Power on, wait for boot, first output sends PWM at 128 (50%). Square wave looks good, motors run.
When I press a button (pin3), the second output sends PWM at 128 (50%) to the third motor. As I watch the pulses on my oscope, I see the first pulse come in, then no further pulses. If I replace the motor with my test LED's, the square wave looks fine.

known knowns:
* The batteries are able to power all three motors at the same time, so I am not exceeding the power draw. If I run the third motor directly to the batteries while the first set are running, everything works.
* The current draw on the third motor is 400mA at start and 200mA sustained. (I guess I could go back to the 2N2222 if necessary)
* If I move the working set of motors to the second output, it has the same behavior. <--wierd
* I have replaced (and swapped) the TIP120 and the diode.

known unknows:
* The third motor has two resistors on it, and a capacitor array. Would these affect its ability to play nice with PWM? Not sure of the values of the cap's, as they are SMT, and impossible to read. The resistors (one on each motor post, in series with the load) are 6.3ohm.
* Changing the value of the resistor between the Trinket and the TIP120 base appears to have little change, except when I went as high as 10k. So, they are at 2.2k, as demonstrated in the knock-lock tutorial


Any suggestions?
I suppose someone is going to ask for a circuit diagram, so I'll see if I can whip one up.

Thanks!

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

Quick update... If I swap the motors, so that the third motor (the one that wasn't working earlier) on the first output, it works fine. When I put the pair of motors on the second output, they magically don't work.

Is it possible that I have a problem with the two outputs on the Trinket? pin0 appears to work all the time, but pin1 is a little finicky.

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

This is basically the circuit. I put it together in iCircuit on my Mac, and it didn't have a built in Arduino component, so I substituted a 5v square wave to simulate the PWM signals coming in to both transistors.
Screen Shot 2014-08-29 at 11.05.55 AM.png
Screen Shot 2014-08-29 at 11.05.55 AM.png (47.99 KiB) Viewed 356 times
The circuit appears to work in iCircuit, so that is why I am wondering if this has anything to do with the Trinket, and the output on pins 0 and 1.

User avatar
adafruit_support_mike
 
Posts: 67454
Joined: Thu Feb 11, 2010 2:51 pm

Re: PWM Motor Speed with Trinket

Post by adafruit_support_mike »

Which of the two Trinket pins is acting flaky?

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

pin 1 has been acting flaky. I'm going to be messing with this project again today, so we will see if the flakiness continues.

User avatar
skr0d
 
Posts: 68
Joined: Sun Nov 25, 2012 9:11 pm

Re: PWM Motor Speed with Trinket

Post by skr0d »

Somehow, the flakiness has gone away. My best guess, is loose connections on the breadboard. Once I moved everything to a protoboard, and soldered it in place, I have not had any repeat performances of flakiness.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”