I need help understanding FETs.
November 17, 2009 6:18 AM   Subscribe

I need some electronics help - why is this FET not doing what I expect it to?

(Please use small words as this mechanical engineer does not often understand the world of electrons.)

I have a circuit that's driving me up a wall! In an effort to build a weather observation station, I have a capacitative humidity sensor that is built into an op-amp integrator circuit. Something similar to this (pdf, see figure 3). I'm using an Arduino to control everything, basically following the same functional block diagram as is in the document - power HI, find the time at V1, time at V2, do some math and figure out the capacitance which is then converted to relative humidity. Then flip the power to LOW and do the same thing in reverse.

The problem, as is common with integrator circuits like this, is that the sensor/cap needs to be discharged occasionally. Based on some other suggestions I found on the internet, I added a JFET in parallel with the sensor and modified my code so that the JFET would close after every hi/low cycle, shorting the sensor and removing the built-up charge.

Unfortunately, it seems that it's in a constant state of short-circuit. If the JFET is in place (and I'm sure that I have the pins where they should be), the integrator circuit does not work. The sensor simply does not build a potential across its terminals, and I'm at a loss why the JFET won't stay in an "open" state.

Is a JFET not the right tool for the job here? Is there some quality of FETs that I'm not understanding? I've done all the most obvious troubleshooting and I'm still at a loss.
posted by backseatpilot to Technology (17 answers total) 2 users marked this as a favorite
 
I've never used a JFET, but based on the Wikipedia page and modified by my experience with MOSFETs, it sounds like you need a control voltage that might be outside the normal 0-5V you're working with to turn a JFET completely off. For example, Wikipedia says:
To pinch off the channel needs a certain reverse bias (VGS) of the junction. This "pinch-off voltage" varies considerably, even among devices of the same type. For example, VGS(off) for the Temic J201 device varies from -0.8V to -4V.[1] Typical values vary from 0.3V to 10V.
To switch off an n-channel device requires a negative gate-source voltage (VGS). Conversely, to switch off a p-channel device requires VGS positive.
So, if you're seeing the JFET looking like it's on all the time, my first guess would be that it is on. If you post your JFET part number, we can look it up and check.

Another possibility is to just use another GPIO pin to discharge the sensor cap. If you disable all pullups & pulldowns on an input, then it should be very high impedance, and not affect your measurement too much. When you want to discharge, switch the pin to output mode and pull the sensor cap low. Switch back to input and measure again.
posted by spacewrench at 7:03 AM on November 17, 2009 [1 favorite]


BTW, although people (including myself) sometimes post electronics questions in AskMe, I've found a better forum for that topic is All About Circuits.
posted by spacewrench at 7:06 AM on November 17, 2009 [1 favorite]


I had a similar situation to what spacewrench describes recently when building the lighting system for my 3rd-gen bookscanner. Basically, I was driving a huge mass of LEDs using a FET. The datasheet said that it would gate at 2v, but the gate wouldn't fully saturate until 5.2V, which seemed a bit nuts to me. I realize this doesn't help you directly, but here it is anyway.
posted by fake at 7:32 AM on November 17, 2009


Let me see if I understand this correctly - to stay "off", an n-type JFET needs a potential from collector to emitter of something around -.8 to -4V? So that would mean it's not the best solution for this particular problem, since top and bottom of the integrator cycle have no voltage drop across the sensor.

Would a normal transistor work instead of a FET in this case? What would be the advantage of using a FET over a standard transistor?
posted by backseatpilot at 9:36 AM on November 17, 2009


I think that's correct, although I'm not 100% sure. (To be clear, I think you'd need to hold the JFET gate somewhat below ground if it's N-channel, and somewhat above 5V if it's P-channel, if you want it completely off and not draining charge off your sensor.)

A normal FET would probably work a lot more like you have in mind, and a bipolar transistor might work too, although I think most bipolars have higher leakage current. I think the Microchip circuit works by allowing the sensor cap to charge from P1 through the 6.65M resistor, and timing how long it takes to get to 1/2 Vdd (as set by Rcm1, Rcm2). Then, you want to discharge the sensor cap (back to 0V) through a FET or something, and let it charge up again.

Assuming all that's right, you can use a FET (definitely), a bipolar (probably), and even a JFET (if you have the appropriate gate control voltages, but that's more trouble than it's worth). But don't forget that the AVR output pins are just FETs -- the Atmel datasheet will even show an equivalent circuit for them. You probably don't need a separate discharger device at all; just connect an I/O pin to Vcm. Put it into input mode (with all pull-ups and pull-downs disabled!) when you want to measure, and switch it to output, logic-low when you want to reset the sensor.
posted by spacewrench at 10:13 AM on November 17, 2009


Ah, ok. I'll try the digital pin trick when I get home and see how that works.
posted by backseatpilot at 10:34 AM on November 17, 2009


I have my copy of "The Art of Electronics" open to make sure I get this mostly right.

All JFETs are depletion mode FETs. This means that by default, they will conduct between the source and drain (what you're calling the emitter and collector, although those terms only really apply to BJTs, I think). The only way to turn off an n-channel JFET is to bias the gate negative with respect to the source (the source is your emitter). In other words, if you have the source at ground, you need several volts below ground at the gate in order to turn off the FET. How many volts negative you need is called the threshold voltage, Vth, which should be listed in your FET data sheet. I'm assuming you have the "collector" wired to the high side of your capacitor, with the "emitter" at ground, so it's probably going to be difficult for you to turn off the FET.

The easiest drop-in solution for you will be an n-channel Enhancement Mode MOSFET. You turn on the MOSFET by putting a positive voltage between gate and source - again, this voltage will have to be higher than the threshold voltage, which is probably 1-3 volts, so you should have no trouble turning it on with your microcontroller. Turn the MOSFET off by pulling the gate-to-source voltage below Vth.

You can also use a BJT for this, but you'd probably need some extra components. An Enhancement Mode N-Channel MOSFET will probably suit you best.
posted by RobotNinja at 10:47 AM on November 17, 2009 [1 favorite]


As spacewrench points out, you can also just drain the cap through one of your pins. Attach the "high side" of the cap to an IO pin, and set the pin to tri-state ("high impedance") mode when you don't want the cap to drain (this is probably the same as input mode with all pull-ups disabled. Then just set the pin to output mode, logic low to drain. Good thinking spacewrench!
posted by RobotNinja at 10:50 AM on November 17, 2009


The problem, as is common with integrator circuits like this, is that the sensor/cap needs to be discharged occasionally.

In your application you don't need a reset switch for your integrator because you are integrating both slopes. The capacitor alternately charges and discharges during each half cycle so there is no need to discharge it with a FET.

In the PDF you linked look at Figure 3. Vcm is set to 1/2 of Vdd. Vsen as shown in Fig. 2 varies from near 0 to near Vdd. That is, Vsen is alternately above Vcm and below Vcm. This means that the voltage across Csen is alternately positive and negative on each slope. At some time in between the voltage across Csen is zero which means that it is discharged the same as if you used an external FET. So the integrator effectively resets itself twice over each sampling cycle when Vsen = Vcm = 1/2 Vdd.

Remove the JFET and you should be good to go.
posted by JackFlash at 10:53 AM on November 17, 2009


Both RobotNinja and JackFlash are right. You have a depletion-mode device, which means it can't be completely turned off unless you apply a quite-negative voltage to its gate. If you want the reset-switch, you want to use an enhancement-mode MOSFET.

But the thing is you probably don't need it at all. Because you can integrate in both directions, you can (by adjusting timing) make sure that the integrator voltage stays within whatever bounds you have chosen.
posted by polyglot at 11:32 PM on November 17, 2009


To make it explicit, "Vgs > Vth => conducting". Depletion mode devices have Vth <>
The other thing is that FETs often have a reverse-diode built in so they they will always conduct backwards. If Vds < 0 on a n-channel, it will probably go ahead and conduct regardless of the gate voltage. So your integrator can't ever run a negative balance on the capacitor.
posted by polyglot at 11:51 PM on November 17, 2009


grr, Vth < 0 for depletion mode. Damn less-than and HTML and grumble grumble.
posted by polyglot at 11:51 PM on November 17, 2009


polyglot: The other thing is that FETs often have a reverse-diode built in so they they will always conduct backwards.

This is another reason you really don't want to use a FET for this application. This design puts positive and negative polarity on the sensor cap which will forward bias the FET's body diode and ruin the integration in that direction. You really only need a reset switch on an integrator when you only measure current flowing in one direction. In this application you measure current flowing in both directions so a reset switch isn't needed at all. Removing the FET also eliminates a parasitic capacitance that would affect your calculations.
posted by JackFlash at 12:21 AM on November 18, 2009


To clarify a little bit more, the circuit was originally built without the FET, but leaving it on for several hours causes the RH measurement to drift (usually over 100%). Hence my thinking that I needed the ability to discharge the sensor occasionally.
posted by backseatpilot at 5:06 AM on November 18, 2009


I would suspect a software error. If you had access to an oscilloscope it would be much easier to figure out the problem. Instead you are going to have to put in some software debug diagnostics to figure it out. The problem may be the algorithm and timing that you are using to control the switching of Vint pin in Fig. 3.

The device integrates current over time to measure the precise amount of charge on the sensor capacitor. If you look at Fig. 2, you are supposed to be switching Vint on pin 1 back and forth from 0 to Vdd whenever Vsen crosses either the upper threshold or the lower threshold voltage. Keep in mind that Vsen is a measure of charge on the capacitor because Q = C * V. As long as you keep Vsen near the range Vrl and Vrh in Fig. 2 without overshooting too much, you know that the charge on the cap is within range. So you don't need to discharge the cap, you just need to keep Vsen in the proper range.

If you are taking measurements intermittently, then the voltage on Vsen will go to one rail or the other when you stop the switching. So you may want to throw away the first measurement when you resume switching to allow the charge to get back into the desired range. The other reason for throwing out the first measurement is that the op amp becomes saturated when it hits the upper or lower rail and requires a little bit of time to recover normal operation when Vsen gets back into range.

In Fig. 2 you switch Vint to 0, Vsen should be somewhere below Vrl. You start your timer when you cross Vrl and stop your timer when you cross Vrh. Since the y distance of Vsen is fixed, the time determines the slope of the Vsen line. A longer time means a lower slope and higher capacitance. A shorter time means a steeper slope and lower capacitance.

Very shortly after crossing Vrh, you need to switch Vint to output a 1 so that the slope reverses direction and declines. You don't want to wait too long or Vsen will go all the way to the high rail which will saturate the op amp. When Vsen again crosses below Vrh on the down slope, you start timing again and stop when it reaches Vrl. You then immediately want to switch Vint back to 0 so that Vsen starts climbing again. If you wait too long, Vsen goes all the way to zero which would also saturate the op amp. If you turn off the switching because you only do measurements intermittently, the op amp will start from a saturated state, so that is the reason for discarding the first measurement. It probably is a good idea to take several measurements in a row without letting the op amp saturate and average them. This makes sure that Vsen stays in the desired middle range away from 0 and Vdd. You want to keep a continuous triangle wave going that doesn't go all the way to 0 or Vdd.

Also make sure that interrupts aren't occurring in the middle of your measurements that could throw off your timing. You need to make sure that your algorithm never loses track of which region Vsen is presently located on Fig. 2 -- below Vrl, between Vrl and Vrh, or above Vrh. You determine this when the comparators measuring Vrl and Vrh change and in which direction they change.
posted by JackFlash at 11:09 AM on November 18, 2009


Oh, and if it isn't obvious, this is an inverting integrator. When you apply a 0 to Vint, Vsen increases. When you apply a 1 to Vint, Vsen decreases.
posted by JackFlash at 11:13 AM on November 18, 2009


Ok, so "I'll try this tonight" turned into "I'll try this before the end of the next decade", but I did finally edit the software last night. Ran the fix overnight and the readings stayed stable for the entire time without drifting appreciably in either direction. I think the answer was that the op amp was getting stuck on one of the rails, so discarding the first reading and averaging a larger number of measurements seems to have done the trick. Thanks!
posted by backseatpilot at 5:17 AM on January 6, 2010


« Older Looking for Outlook setting.   |   How can I access files from a fritzed Windows Home... Newer »
This thread is closed to new comments.