Wednesday, August 14, 2013

Why is my FET hot? Circuit detective work...

I was using an ATtiny85 to drive a large computer fan (brushless DC motor) using a FET and pulse-width modulation and I was surprised at the amount of audible noise. A quick Google search turned up the article below on reducing PWM noise with BDC motors. In short, the article recommends using a resistor and capacitor to slow down the turn-on time (slew rate) of the FET to reduce acoustic noise.

http://ww1.microchip.com/downloads/en/AppNotes/00771b.pdf

I tried the recommended approach with the FET below (it is a hefty 75 amp, N-FET with an on resistance of 0.002 ohms that I usually have in my parts bin). The fan did run much quieter but the FET was getting HOT with only a 5A load!

http://www.irf.com/product-info/datasheets/data/irf2804.pdf

I expect that a TO-220 package can dissipate 1 to 1.5 Watts before needing a heat sink. Using 1.5 W as an upper limit and applying P=(I^2)R, the FET should conduct 27.4 amps without getting too hot to touch (a very subjective measure I know). At 5 amps, the power loss in the FET should be about 0.05 W, not enough to even get warm.

Perhaps the slowing of the gate on the FET was causing the heating. (Very slow gate transitions can cause a FET to heat up because they spend so long conducting current in the linear resistive region before the FET reaches it's low resistance at  full turn on.) So I let the FET cool and removed the slew rate limiting capacitor and tried running the fan at full power. Under these conditions the FET should remain cool to the touch. But the FET heated up very quickly. I was perplexed. The gate voltage was only 4.5 volts from the ATtiny but I though that would be enough for only a 5 amp load. So back to the FET datasheet.

The answer came from taking a closer look at Figure 1 from the datasheet, below. The figure shows a family of curves with each curve showing the FET current as a function of the voltage across the FET (Vds) at a given fixed gate voltage (Vgs).



I finally noticed that the VGS=4.5V curve shows that the FET gate requires almost 11 volts (Vds) to reach 5 amps! This would be 55W of dissipation in the FET while driving only a 5A load. No wonder the FET is hot! I had not bothered to see if the devices was rated for logic-level drive and clearly it is not! I should have checked the datasheet before using the 2804 but it has such a low Rds that I thought it would have no problems with the 5A load. So I need to either switch to a logic level FET or find a way to raise the gate voltage.

A quick on-line search points to a good candidate in the IRLB8748PbF which has an Rds of 5.5 mOhm at Vgs=4.5V and would fit the bill nicely with a current limit of over 16A for a 1.5W dissipation. At our 5A current the power dissipation would still be less than 0.14W and should run cool.

http://www.irf.com/product-info/datasheets/data/irlb8748pbf.pdf

I could also use a gate pull-up resistor to Vin (12 volts) on the FET that I pull down with an NPN transistor driven by the ATtiny. In the end, I dropped in a high-side FET driver that I had on hand. Now the original IRF2804 FET runs cool even with the slew-rate limiting capacitor installed to reduce acoustic noise! Yea!

http://www.micrel.com/_PDF/mic5014.pdf

I hope you find this helpful when chasing your next circuit gremlin. Just keep digging, there is a reason for everything the circuit is doing!


PS: In post analysis, I noticed in Fig 1, that just an extra 0.5V on the gate would shift us up to the next voltage curve, reducing the FET resistance enough to bring the power well below 1.5 W. So I was not too far off in my expectation that this FET should have performed well enough in this application. A microcontroller would usually have an output closer to 5V. Perhaps I previously over-stressed the pull-up on that output pin and it was out of spec (I could have tried another pin! The joy of hindsight). Perhaps I could have added an external pull-up resistor to the FET's gate, say 5k to +5V, and let the microcontroller pull the gate down to turn it off. Not an ideal solution but may get the job done if you have few other options at hand.


Tuesday, August 13, 2013

Using Sensors with Arduino

Using Sensors with the Arduino Uno

Most projects require some kind of input from the user or environment. Inputs can include push-buttons, rotary knobs, temperature sensors, light sensors or any number of other options. These sensors are typically read using an analog input.

Analog Inputs
The Arduino Uno provides 6 analog inputs that report a number between 0 and 1023 which corresponds to a voltage between 0 and 5 volts. For example, a reading of 511 would indicate that input pin was near 2.5 volts. These 10-bit analog inputs provide a resolution of 4.88 mV per bit.

It is important to keep the voltage at the analog inputs from exceeding 5 volts. You may not damage the chip when you exceed 5 volts but you know nothing about your signal, other than it is over +5 volts.

Voltage dividers are used to measure signals that can exceed the 5 volt limit. For example a vehicle electrical system can vary from 11 volts with a low battery to 14 volts when idling (with transients much higher and lower during engine starting and switching of high power accessories like AC).

For measuring battery voltage I typically connect a 1k resistor between the analog input and ground and a 3k resistor between the analog input and the battery to be monitored. This produces a four to one divider and allows up to 20 volts before reaching the 5 volt input limit.

These resistors present a fixed 4k load to the battery, drawing a nominal (I=12V/4k) load of 3mA while connected. This load can be reduced, up to a point, by using larger divider resistors. Very large divider resistors will contribute error to the measurement. There is a very cool trick you can use with a p-FET between the battery positive and the resistor divider to reduced the steady-state current to effectively zero.

Measure Battery Voltage with Zero Steady State Divider Losses, http://jeelabs.org/2013/05/18/zero-power-measurement-part-2/

Low Voltage Signals
There are many options for working with low voltage signals you can use an op-amp or instrumentation amplifier to boost your signal. You can also change the Arduino analog reference voltage from 5 volts (DEFAULT) to (INTERNAL) which is 1.1 volts. The INTERNAL reference provides a resolution of 1.074 mV for the analog inputs. This can help you get more accurate readings for lower signal levels. Just remember you need to keep your analog inputs below 1.1 volts when using INTERNAL.

analogReference(INTERNAL);   //set full scale to 1.1 volts

Please read the analog reference notes at the Arduino site. There are some important details on switching between INTERNAL and EXTERNAL references.
http://arduino.cc/en/Reference/AnalogReference

You can also specify an external reference and use a lower or custom reference voltage. Be sure you have a reference connected if you use EXTERNAL or you may get random readings from your analog inputs.
analogReference(EXTERNAL);  //use external analog reference, user supplied

The Arduino environment has several functions that come in handy when working with sensors (see Arduino-> Reference-> MATH). One of the most useful is the Map function that allows you to automatically generate a specific output from an input range.

map(inputSignal, 0, 1023, 0, 255);  //will map an analog input to 8-bit analog write values

The ATtiny84 can use Vcc, an external reference or an internal 1.1 volt reference for analog inputs (from 16.12.1 of the device manual). 

Smoothing
Low pass filters and averaging. Often a signal will have noise or jitter that needs to be removed to make the signal more useful or easy to display. A resistor and capacitor can be used as a low-pass filter. Taking multiple readings and averaging can also smooth date to reduce the impact of glitches or noisy data.

Digital interfaces
Digital interfaces are used on an increasing number of devices. I recommend looking for working example code when using digital interfaces. Google can help you find other people working with the same or similar devices. The vendor website may have sample code for another platform that you can translate into Arduino. Hit the Forums and post your question if you are still having trouble. There will probably be someone who can give you a hand up on getting your code working.

Polarity Protection with FET for Near-zero Voltage Drop
I first saw this trick on the Pololu Baby Orangutan B controller board (with a p-FET connected to Vin). 
http://www.pololu.com/docs/0J14/3

The TI document below discuss the technique in section 2.1 and provides these examples. Note the load serves as the gate pull-down resistor to keep the gate voltage from floating. Also note Figure 2 should be captioned PMOS in Positive Path. 
http://www.ti.com/lit/an/slva315/slva315.pdf

The NMOS version will be cheaper and/or have a lower voltage drop.


The PMOS is more expensive but maintains the integrity of the load ground connection.

Carl Nobile pointed out this video that explains the p-fet version of the circuit.
http://www.youtube.com/watch?v=IrB-FPcv1Dc



Arudino Prototyping Tips:
Use an Arduino Uno with a DIP socket for the 328p processor. ($24.95)
https://www.sparkfun.com/products/11021

Buy spare Arduino chips with boot-loader ready to go ($5.50 each)
https://www.sparkfun.com/products/12060

Buy an organized assortment of resistors at Amazon.
http://smile.amazon.com/Resistor-Land-1280pcs-Value-Assortment/dp/B00MQ9FZOY/ref=sr_1_3?ie=UTF8&qid=1434328778&sr=8-3&keywords=resistor+assortment

Adafruit - full-featured multimeter for $59.95
https://www.adafruit.com/products/308

Sparkfun Inventor's Kit ($99.95)- great start if you do not have a well stocked parts bin.
https://www.sparkfun.com/products/12060


Other Resources
I have no connection with any of these sites. I just think they are cool and or handy.

Measure Battery Voltage with Zero Steady State Divider Losses
http://jeelabs.org/2013/05/18/zero-power-measurement-part-2/

Omega Handbooks - Free!.  Great resource for information about measurement and control. Check out their website. Temperature book has great information on tuning PID controllers. 
http://www.omega.com/literature/

Adafruit  - great tutorials for using sensors with Arduino, more info added frequently
http://learn.adafruit.com/category/sensors

SparkFun Inventors Kit Guide Book- buy the paper book or...

download the free PDF of the Inventors Kit Guide!
https://cdn.sparkfun.com/datasheets/Kits/RedBoard_SIK_3.2.pdf

Pololu - great power boards, motor drivers, very cool 328p with motor driver! They also have some simple motor drives that fit amazing power into tiny boards.
Rocket Scream - Great low power library and low power (Mini Ultra 8 MHz , 1.7uA) board

Nathan Chantrell - blogger with a cool ATtiny based board, wireless sensors

Jeelab - Low power, one device on battery power for 3 YEARS!
http://jeelabs.org/2013/09/08/3-years-on-one-set-of-batteries/

JeeLab - Arduino compatible, 328p, small form factor, wireless, plug in boards, very cool
http://jeelabs.org/2010/12/18/rethinking-the-arduino-hardware-interface/

Modern Devices - US vendor of the JeeNode v6 kit ($22.95), many other cool parts
http://moderndevice.com/product-category/jeelabs/