emma1997
Posts: 1088
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

MOSFET vs BJT for Pi Relay Circuit

Fri Feb 21, 2020 11:14 pm

Ok... so Friday night and as usual no game or early weekend partying for me. It's the only time with access to both hobby equipment and internet at the same time so here we go.

This follows up on some interesting discussion in other threads on driving relays, EMF, and RFI. It quickly took on a life of it's own out here in the real world with some animated back-and-forth with a couple of my ham radio pals. For some odd reason there is huge resistance to abandoning the classic junction transistor circuits so popular back in the late 60's, early 70's. Magazines were flooded with them.

It's been a couple years since last working on this stuff so first order was to get up to speed reproducing Brandon's excellent scope captures using NPN transistor. No problem getting those same horrifically noisy traces using the setup shown below in first photo. Turns out they don't really have to be that nasty (even with bipolar) but we'll get to that.

Next pic has a few examples of the relays and transistors used out of the many dozens I tried. A collection of cheap and common 5v chinese relays and to220/to92 bipolar/MOSFET transistors.

Last is a random diagram downloaded from google showing the basic test fixture. Chose to wiggle GPIO14 (pin 8) because of convenient proximity to 5v and ground. The pot allows me to adjust drive current which, not surprisingly, turns out to be very important for the BJTs.

I'll put scope snapshots in separate posts to illustrate subjects clearer.
Attachments
PI_SETUP.JPG
PI_SETUP.JPG (59.18 KiB) Viewed 861 times
RELAYS_TRANSISTORS.JPG
RELAYS_TRANSISTORS.JPG (96.69 KiB) Viewed 861 times
MOSFETT.JPG
MOSFETT.JPG (23.82 KiB) Viewed 861 times

emma1997
Posts: 1088
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: MOSFET vs BJT for Pi Relay Circuit

Fri Feb 21, 2020 11:20 pm

Let's start off with the Ugly and maybe Good and not so Bad in a later post. Notice severe high voltage ringing of the BJT in the first photo. Turn out this is not necessary and caused by turning the pot down to 150ohm or so. Essentially overdriving the base for that particular part but it is what it is.

On the other hand simply unplugging the BJT and inserting a MOSFET shows much tamer behavior. I'm going to rush this one out to keep the posts together and maybe come back with additional comments as time allows.
Attachments
BJT_OVERDRIVE.jpg
BJT_OVERDRIVE.jpg (86.44 KiB) Viewed 844 times
MOSFET_OVERDRIVE.jpg
MOSFET_OVERDRIVE.jpg (70.88 KiB) Viewed 852 times

emma1997
Posts: 1088
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: MOSFET vs BJT for Pi Relay Circuit

Fri Feb 21, 2020 11:30 pm

Here's the exact same arrangement but with resistance of pot turned way up. Again just unplugging the bipolar and replacing with the FET. So these values are not just to avoid damage to the transistor but quite important for noise generation too.

From my assessment there does seem to be an advantage to using a more modern process. Not only lower cost for the same power, but less noise and heat to boot compared to those old fashioned parts. Not saying they don't work because obviously millions or billions in operation all over the world prove otherwise. Just there may be better options.

Hopefully these may be of interest to those hooking this kind of stuff up to a Pi. Also hope I got the pics and details right. If not then I can always correct later... right? Well being somewhat dexlysic myself usually end up editing half dozen times anyway so... lol
Attachments
BJT_PROPER.jpg
BJT_PROPER.jpg (70.15 KiB) Viewed 843 times
MOSFET_PROPER.jpg
MOSFET_PROPER.jpg (68.07 KiB) Viewed 843 times

sparkyhall
Posts: 168
Joined: Mon Aug 27, 2012 9:14 am

Re: MOSFET vs BJT for Pi Relay Circuit

Sat Feb 22, 2020 8:43 am

You seem to have omitted the flywheel/flyback diode across the relay coil, without this you are allowing the back emf to rise to an uncontrolled level which is why you see the high voltage transient during switch off. You can probably get away with this with small relays like the one you have used but large inductive loads will destroy a BJT transistor. Depending on the internal diode avalanche characteristics a MOSFET may fair better.

Your last scope image shows the MOSFET is limiting the back emf to a lower voltage, I guess this is down to the parasitic capacitance between the drain and gate providing negative feedback due to the large gate series resistance used. If this is the case this will be rather unpredictable and vary wildly from device to device.

Interesting little experiment though.

btidey
Posts: 1637
Joined: Sun Feb 17, 2013 6:51 pm

Re: MOSFET vs BJT for Pi Relay Circuit

Sat Feb 22, 2020 9:34 am

I do normally use MOSFET as logic switches to get better characteristics (lower voltage drop when on, less heat, easier driving).

I don't use the 2N7000 series though. Although the threshold is fairly low (2.5V) this is when the device just starts to conduct. Like a lot of MOSFETS the 2N7000 only has worst case RDSon specified for gate voltages above the 3.3V logic levels e.g 4.5V. For lowish drain currents it probably works Ok with 3.3V but is not guaranteed to be turned hard on.

I normally use smd parts so my goto devices for medium current use are the AO3400 (n channel) and AO3401 (p channel). These have specified low RDSon with 2.5V gate drive.

User avatar
rpdom
Posts: 17705
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: MOSFET vs BJT for Pi Relay Circuit

Sat Feb 22, 2020 12:41 pm

btidey wrote:
Sat Feb 22, 2020 9:34 am
I normally use smd parts so my goto devices for medium current use are the AO3400 (n channel) and AO3401 (p channel). These have specified low RDSon with 2.5V gate drive.
I've used the AO3400 and NDS331N for my relay boards. They seem to work well.
Unreadable squiggle

Diablo2_Fan
Posts: 21
Joined: Thu Aug 01, 2019 6:47 pm

Re: MOSFET vs BJT for Pi Relay Circuit

Sun Feb 23, 2020 7:03 pm

A good choice for a TO-220 MOSFET is the IRF3708.

emma1997
Posts: 1088
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: MOSFET vs BJT for Pi Relay Circuit

Mon Feb 24, 2020 12:04 pm

Sorry for late reply. In the interest of domestic tranquility weekends are considered 'analog time' around the 'ol homestead. Somewhat. :)

I do like IRF3708, cheap and specially good for high freq switching converters. They were included in my first go-around few years back.

I really like those AO parts though. Same package as SOT23 version of 2n7000 but orders of magnitude better specs. Not great for that plug-in fixture (not impossible though). How small is something when you lose it falling in your lap. YOUR LAP!

Those complementary pairs very popular during the heyday of RC models. Used in virtually all the cheap chinese quadcopter and micro airplane toys (Airhogs etc). Essential for DIY too. I built several tiny robot foamie planes out of bamboo sticks, picnic plates, and attiny84 controller using those. More than a few DIY pager based nano-quads too. Ahhh,,, those were the days.
sparkyhall wrote:
Sat Feb 22, 2020 8:43 am
You seem to have omitted the flywheel/flyback diode across the relay coil,
That was intentional. This whole exercise started in a couple other threads here with my suggestion that flyback diodes were not always needed. Specially with MOSFETs where spikes are minimized as seen in my pics.

I did mention that for critical or commercial design I would include the diodes. More for liability than technical issues though. That part seemed to fall on deaf ears in the shock of the moment. A new term was coined: Anti-Social Engineering. lol
sparkyhall wrote:
Sat Feb 22, 2020 8:43 am
You can probably get away with this with small relays like the one you have used but large inductive loads will destroy a BJT transistor. Depending on the internal diode avalanche characteristics a MOSFET may fair better.
Not by much if you push it. The problem with avalanche is they don't just die right away but get closer with every abusive pulse until... But for hobby use it is a nice experiment to see what you can get away with as far as minimizing component count. I do have about a dozen 2n7000 driving relays all by themselves scattered around the house.
sparkyhall wrote:
Sat Feb 22, 2020 8:43 am
Your last scope image shows the MOSFET is limiting the back emf to a lower voltage, I guess this is down to the parasitic capacitance between the drain and gate providing negative feedback due to the large gate series resistance used.
First set of snapshots too. Some of those higher current MOSFETs have extreme gate capacitance, even up to a microfarad or so. Then of course Miller Effect kicks in too and no wonder it takes so long for the voltage to build up. However responsible for very nice waveform compared to BJT.

Funny how those principles work against you in things like BLDC controller and switchers but can save the day in other applications like relay.
sparkyhall wrote:
Sat Feb 22, 2020 8:43 am
If this is the case this will be rather unpredictable and vary wildly from device to device.
Not a big issue with relays where 200% margins are common. In these tests I found wide latitude between coil activation yet minimal EMF.
sparkyhall wrote:
Sat Feb 22, 2020 8:43 am
Interesting little experiment though.
Not so little when I originally built that test jig few years back. Mostly for evaluating relays but proved useful characterizing over a hundred different transistors since then. Made me lots of moolah withthose crazy hourly rates of mine.

Oooops... time to leave for work. Thanks for the interest and comments.

emma1997
Posts: 1088
Joined: Sun Nov 08, 2015 7:00 pm
Location: New England (not that old one)

Re: MOSFET vs BJT for Pi Relay Circuit

Fri May 01, 2020 7:13 pm

Couple days ago someone offline asked what parts were actually tested with that relay circuit. Same thing couple times before so thought it might be a good idea to put up a list here. These were only a fraction of the ones from my day job long time ago but most likely to be of hobby interest now. Voltage and other specs also listed so may come in handy for other DIYers.

Conversion from my database wasn't perfect. Hopefully it's decipherable:

hi power: volt amp
*AO4806 20V 9.4A
AOT290L 100V 140A
*FQP30N06L 60V 30a LOGIC
*FQP50N06 60v 50a 10mhz
*FQPF5N80 800V 2.8A
*FQU2N60C 600V
HY1707 75V 80A xld24/36v
hy3008 100v 80a xld48/60v
*K80E08K3 75V 80A
IRF3205 55V 110A
*irf3607 75v 80a
irf3703 30v 210a 3-4mo
*IRF4905 55V 74A
*IRF510 100V 5.6A 100mhz
IRF530N 100V 17A 90mohm
*IRF540 100V 33A
*IRF740 400V 10A
*IRF840 500V 8A
IRF9540 100V 23A P-Chan
IRLB3034 40V 343A
*IRFB3077 75V 210A
irf83607 75V 80A
*IRFB4110PbF 100V 180A 4.5mo
IRFB4115 150V 104A
*IRFB4410Z 100V 97A 10mo
IRFZ44N 55v 48a 31mO
*irl2703 30v 24a
IRLB8743PBF 30V 150A
*RU7088R 70V 80A
STP75NF75l 75V 95mOh 80A
STP80NF70 68V 82mOh 98A

lo power: db mhz vce hfe amp
*2n2222 4.0 300 40 300
*2n3819 450 25v
*2n3904 5.0 100 40 300
2N5089 2.0 50 25 400-1200
*2N5551 8 100-300 160 80-250 .6a
*2n7000 100 60
2SA970 3.0 100 120 100-700
*2SC3355 1.1 7000 12 50-120-250
*d772 100 60 6a
*d882 100 60 6a
*bc337 210 45 400 .8a
*BC547 2 300 45 110-800 .1
*BC549 4.0 300 30 110-800
bc550 10 45
*bd137 60 40-160 1.5
*BF245B 1.5 700 30
*bfg520 1.6 9000 15 120
BFG540 9GHZ 15V
bf998 1 800 12
*bfp740 .85 44000 13 250
*bs170 100mhz=10ns
*C1815 1 80 50 70-700
*hbfp0420 1.1 10g 4.5 80
mpsa18 1.5 100 45 500-1500
*MPSA42 50 300 40 .5a
*MPSA92 300 .5A
*prf949 1.5 9000 10 100-200
*r25 1.1 7000 12 50-120-250
*S9014 0.9 270 45 60-280-1000
*S8050D 100 25 160-300 1.5a
*si2306 30 2.8a
*ss9018 1100 15 50ma
tip36c 3 80 25 25a

Return to “General discussion”