User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Servo goes crazy with transistor

Thu Jan 02, 2014 12:25 pm

Aw yeah! my very first post!

I have a question about the following diagram.
Screen-Shot-2014-01-02-at-13.12.37.jpg
Screen-Shot-2014-01-02-at-13.12.37.jpg (58.15 KiB) Viewed 3548 times
I want to switch on the servo myself so that right after I switch it on I can
send a position. This way the power-on twitch is as small al possible (right?)

I've noticed the power-on twitch (without position command) is larger and longer (movement) than without
the transistor... Anyone knows how this is?

My servo goes from 700 to 2300. But when I initialise the servo when it already is under a position of 1000
it goes full-power to under the 700. And thus damaging itself.
This does not happen when I take out the transistor...

What am I doing wrong? Any help would be very appreciated!

P.s. I'm thinking about PWM controlling a 12v toy motor after this.
It only has to go one way. would a diagram as shown work for this?

User avatar
joan
Posts: 14357
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 1:48 pm

It is not clear when the twitch happens.

Does it twitch when you switch the Pi on.

Does it twitch when you switch gpio4 high (I'm assuming high switches power to the servo).

What is gpio24 set as (input/output high/low PWM)?

User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 2:05 pm

joan wrote:It is not clear when the twitch happens.

Does it twitch when you switch the Pi on.

Does it twitch when you switch gpio4 high (I'm assuming high switches power to the servo).

What is gpio24 set as (input/output high/low PWM)?
The twitch happens when the servo starts receiving power
- without the transistor in the circuit (no R1, R2, GPIO 04) - at powering the circuit
- with the transistor - base goes high and gives the servo power.

GPIO is output, PWM from "RPIO"
The PWM itself works fine if I take out the transistor (p2n2222a)
from 700 to 2300, all works fine and fluid.

The reason to use the transistor for me is that I want to minimize the power-on twitch
by powering it and at the same time send it a position.

maybe I should make two scenarios where the problem occurs.
The problem only occurs when I use the transistor
S1:
1- Q1 is off (base is low, GPIO 04) --> servo is off
2- servo start position is at ~1600
3- Q1 is on (base is high, GPIO 04) --> servo is on
4- GPIO 24 sends servo to 1500
5- result, all works fine and servo now is at 1500

S2
1- Q1 is off (base is low, GPIO 04) --> servo is off
2- servo start position is at ~1000
3- Q1 is on (base is high, GPIO 04) --> servo is on
4- GPIO 24 sends servo to 1500
5- result, problem, servo runs to under 700 and stays there

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 2:25 pm

Hi,
Sabine wrote:The problem only occurs when I use the transistor
There is some voltage drop on the transistor... so it could be that the servo doesn't like when GPIO (initial) low level on pulse input has lower potential than it is on servo's "-" pin ?
If this is the case, then you could solve this by adding transistor+resistors circuit also on pulse input (be aware that similar circuit with 2N2222 transistor would inverse the PWM ratio).


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 2:44 pm

I've just swapped the transistor with an IRFZ44N mosfet.
The problem is gone. Not a single hiccup...

BUT

When I was playing with the transistor I've noticed something else...
While running the test script (only does GPIO 04 = HIGH
and GPIO 24 position to 1500) I've noticed the following.

With the GPIO 24 cable in my hand I tapped several times on
the transistor base. Most of the time it went to 1500 as it should
and some random times it went out of bound under 700

With the multimeter I measured the following on the servo cables.
- If I tapped it and it worked like it supposed it was ~5v
- if I tapped it and it wend out of bound under 700 it was ~ 2V

I find this very strange

User avatar
FLYFISH TECHNOLOGIES
Posts: 1750
Joined: Thu Oct 03, 2013 7:48 am
Location: Ljubljana, Slovenia
Contact: Website

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 3:07 pm

Hi,
Sabine wrote:I tapped several times on the transistor base.
FETs are voltage-controlled elements... and these elements don't like to be touched, especially their Gate pin (for transistors).


Best wishes, Ivan Zilic.
Running out of GPIO pins and/or need to read analog values?
Solution: http://www.flyfish-tech.com/FF32

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 3:49 pm

5Vdriver.png
5Vdriver.png (18.85 KiB) Viewed 3478 times
you could try to place the power switch in the +5V line and connect the servo GND to GND. I would think that the servo electronics receives some current with the ground lead floating and the signal lead connected to a lower voltage than 5V.

User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 6:09 pm

Tage wrote:
5Vdriver.png
you could try to place the power switch in the +5V line and connect the servo GND to GND. I would think that the servo electronics receives some current with the ground lead floating and the signal lead connected to a lower voltage than 5V.
Do you mean exactly like the diagram? I've placed it like my diagram in the 5v line and I had the same problem.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 6:41 pm

All or this pain could have been avoided by using this:

Image
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 8:21 pm

Sabine wrote:
Tage wrote:
5Vdriver.png
you could try to place the power switch in the +5V line and connect the servo GND to GND. I would think that the servo electronics receives some current with the ground lead floating and the signal lead connected to a lower voltage than 5V.
Do you mean exactly like the diagram? I've placed it like my diagram in the 5v line and I had the same problem.
perhaps the GPIO starts up with high level when the Pi is powering up, causing the supply for the servo to be applied before the PWM signal appears. you could try to connect the base to 3.3V and the 1k resistor to the GPIO instead of to GND. the GPIO then needs to pull low to turn on the 5V to the servo.

I have not tried this circuit with a servo and the Pi myself.

my schematic shows how to use a pnp as the power switch, so you can move the switch from the GND lead of the servo to the 5V lead. the npn functions as a constant current source for the pnp base. one advantage of this configuration is that the external supply for the servo can have any voltage from 4V to 40V or whatever the transistor voltage ratings are.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12338
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Servo goes crazy with transistor

Thu Jan 02, 2014 11:24 pm

my take on it is that if you switch the servo's power with a transistor/FET in its ground lead, is that when you turn the transistor/FET off the servo looses its ground reference for the PWM signal, if the servo has a tiny bit of energy in an internal capacitor left, it will use the energy to drive the motor, but with an undetermined PWM signal.

You should disconnect the servo's power from the high side (5V side) not from the GND side, the GND should be permanently connected, so the servo keeps seeing a valid PWM signal, even during the time it is loosing the power.

User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Re: Servo goes crazy with transistor

Fri Jan 03, 2014 2:33 pm

Thanks mahjongg and Tage, I now understand why I should buy a PNP transistor! I hope I find time tomorrow!

For the meanwhile I'm using the same solution as I have used for the DC motor. (although I haven't tested it with
the RPI. As a test for the circuit I've used 3V3 and a push button to simulate the GPIO, this did work)

The thing is, that the IRF 630 N MOSFET gets REALY hot within a few minitus. Also the DC motor runs a lot slower
than connecting it directly to 12V.
Screen-Shot-2014-01-03-at-15.28.09.jpg
Screen-Shot-2014-01-03-at-15.28.09.jpg (50.39 KiB) Viewed 3339 times

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Servo goes crazy with transistor

Fri Jan 03, 2014 3:05 pm

The problem with the dc motor driver heating up is that there is not enough gate voltage when driving from 5V. connect the collector of the optocoupler to 12V instead.
the most natural thing would be to get an n-channel MOSFET that has lower gate threshold and drive it directly from the GPIO as in your original setup. but you need a MOSFET that has Rdson specified at 3V or below. Sometimes it will work with one that has 4.5V RDson spec, if the transistor has a much higher current rating than the motor current. use a 1k resistor in series with the GPIO to avoid current spikes damaging the Pi as the GPIO is switching the large gate capacitance of the MOSFET.

keep the PWM frequency low, because the MOSFET will be switching very slowly, so the switching power losses are high. to switch at high frequency you need a gate driver, or select a low threshold MOSFET that is as small as possible (for example one that has Rdson spec at 2.5V and only 2A continuous current rating, and lowest possible gate capacitance so it switches fast even with a large resistor in series with the gate). the optocoupler you use is also very slow, so the problem with heat may be related to switching losses.

User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Re: Servo goes crazy with transistor

Fri Jan 03, 2014 4:49 pm

Ah! sweet! 12V to the optocoupler's collector did the trick! Thanks Tage!

I think I'm starting to understand it all a lot better because of all the help I get here! Thank you so much!

Yesterday I went to my local electronics retailer and I asked for a FET with a low gate threshold of around 3V3 which was capable of PWM. It had to drive a DC motor of 12V, 1.5A (Continuous). And they gave me the IRF630 (RDSon specs below). But now it seems I can only drive it with 12v instead of 3V3?
As from what I understand is that they gave me an incorrect FET, right?
Screen Shot 2014-01-03 at 17.17.44.png
Screen Shot 2014-01-03 at 17.17.44.png (60.71 KiB) Viewed 3308 times

User avatar
Tage
Posts: 287
Joined: Fri May 24, 2013 2:29 am
Location: St Thomas, Ontario Canada

Re: Servo goes crazy with transistor

Fri Jan 03, 2014 8:16 pm

the IRF630 only has a 10V specification for Rdson, so it is not suitable when the gate voltage is only less than 3.3V. it is a common beginners mistake to look only at the gate threshold spec (2V to 4V in this case) and forget that this threshold voltage is specified at very low drain current. when you use larger current you need a lot more gate voltage, otherwise the MOSFETs goes into the linear region where is acts basically as a current source. so the drain voltage goes up as the current increases, and you get a hot transistor. P = I * V
I forgot the partnumbers, but if you read my older comments you will find examples of MOSFETs that can be controlled by 3.3V and have fairly good current handling capability. or you could search the websites for distributors that allow you to search suitable n-channel MOSFETs with 2.5V Rdson spec, etc. Look at devices with 20V Vds rating.

Examples in SOT-23 package:
Si2302CDS, Si2312CDS,PMV16UN,DMG3414U,DMN2075U
Last edited by Tage on Fri Jan 03, 2014 9:23 pm, edited 2 times in total.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 12338
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Servo goes crazy with transistor

Fri Jan 03, 2014 8:21 pm

many FETs with low Vgs-On values are called "digital FET's" which is still misleading, as they are guaranteed to turn fully on with 5V gate-drain voltages, as for 5V logic. This still doesn't mean they do as well with 3V3 logic.

User avatar
Sabine
Posts: 10
Joined: Thu Jan 02, 2014 12:14 pm

Re: Servo goes crazy with transistor

Sat Jan 04, 2014 10:01 am

Doh! Of course !
Thats, aside from the fact it's better to switch the servo on from the high side, the reason the servo was tripping!
As a first test I had GPIO to optocoupler, 5V from optocoupler to N-MOSFET, switching the 5V servo on/off. (problem!)
Second I had GPIO to optocoupler, 12V from optocoupler to N-MOSFET, switching the 5V servo on/off. (problem solved)

In the first attempt with the MOSFET I drove it with 5V, which did not open the MOSFET complete. After that I drove it with 12V it was solved. Result: smaller twitch (just like connecting servo directly to power rails) BUT, most importantly NO servo problems! Now, no matter what initial position it starts perfectly.

I guess that solves all my problems!
ToDo: go to the store and buy N-MOSFETs with low RDSon threshold and Buy a P-MOSFET for the servo.

Thank you guys so much, You Rock!

Return to “Beginners”