Switching a reference voltage with a MOSFET - Page 1
Forum section: electronics / beginners

author: HwAoRrDk
author_rank: Super Contributor
timestamp: December 08, 2016, 11:10:39 pm
content: On my project I have a need to switch a reference voltage - being input to a current-sense amplifier - between 0V and VCC (5V). (I'm doing bi-directional current sensing and need an asymmetrical output, not one centred around the ref. voltage.) I was going to just use an output pin of my MCU to provide the reference voltage - by setting the pin state high or low - but I now am in need of this I/O pin for something else. I realised that the state of my ref. voltage corresponds to the state of one of the I/O pins I'm using to actuate the load being measured by the amp, so I'm thinking I can use that existing I/O to switch the state of the reference too.So, I figured a solution would be using a P-channel MOSFET as follows:- Source connected to VCC.- Drain connected to REF input on amp.- Gate connected with 220R resistor in series to existing I/O line.I/O line will normally be low, so MOSFET will be on, feeding VCC to the REF. When I/O toggles high, MOSFET will be off, leaving the REF input at ground.But I have some questions:- Do I need a pull-down resistor on the REF input? I have a feeling yes; the drain from the MOSFET will probably be floating, and not give me a proper 0V reference. If so, how big?- Is the current-limiting series resistor on the gatereallynecessary? I have read you should always have one, but then other sources say it's only really necessary when you have high switching frequencies (I don't - I'll be lucky if it approaches 1Hz).- Small through-hole package P-channel MOSFETs (e.g. TO-92) are scarce and expensive for some reason (like 5x price). I already have some N-channel - is it possible to do something similar with one of those?

author: trophosphere
author_rank: Frequent Contributor
timestamp: December 09, 2016, 05:09:31 am
content: QuoteYou are correct in assuming the REF input will be floating when the MOSFET turns off. The pull-down resistor will need to be sized such that the amount of current your circuit sinks to the REF pin does not cause a large enough voltage variation to cause your reference to go out of the allowable tolerance of your specifications. Check how much current your circuit sinks into the reference pin, how much of a deviation you can tolerate, and calculate your resistance from there with some overhead.QuoteIt's not necessary in the sense that it won't absolutely work without one but it's good practice to include one.QuoteYes. Source to ground, Gate to MCU Output, and Drain to REF pin with a pull-up resistor. Note that the MOSFET can now only turn on when the output of the MCU pin is pulled up so you will need to invert it.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: December 09, 2016, 04:53:38 pm
content: Quote from: trophosphere on December 09, 2016, 05:09:31 amAh, yes, thanks.Not sure why the thought didn't occur that I can use an N-channel to take the voltage 'away' rather than a P-channel to switch it in.If I'm working things out correctly, I won't need to invert the logic on the gate, as the exact same I/O state will have the desired effect with an N-channel. I/O line goes high, MOSFET turns on, grounds the REF input - matches what I had before.Here's a question: will the pull-up resistor and the RDS(on)on-resistance of the MOSFET form a voltage divider that affects the 0V level? I have some 2N7000 on hand to play with, but I'm not sure what brand they are, so I don't have an exact datasheet to hand. Hmm, I suppose I could look up the figures for several different brands and take a worst case figure and do the maths...Edit:Assuming so, it appears RDS(on)will be around 5-10R according to various datasheets, so if I take 10R as worst-case and use a 10K pull-up, that gives me: (5×10)/(10000+10) = 0.005V. I think that's tolerable for a '0V' reference.

author: Cerebus
author_rank: Super Contributor
timestamp: December 10, 2016, 02:24:29 pm
content: There's an alternative, which is to use both a p-channel and an n-channel to actively switch both VCC and ground. That way you don't need any pull-ups or pull-downs and you get a low impedance path in both directions.Moreover there's a very cheap, widely available, prepackaged version of this, a standard CMOS inverter or buffer chip. It's quite common to see a 74HC04 (hex inverter) or 74HC4050 (hex non-inverting buffer) used for this - the 74HC04 is used to switch some of the reference slopes in the venerated HP 3458 8.5 digit multimeter. Just connect your voltage source to the VCC pin on the inverter/buffer. You need to make sure that your logic input to the inverter/buffer is in the right range for the voltage you're switching but in your case where everything is 5V that's not an issue. If using this, remember to tie any unused inputs to a rail to prevent floating inputs causing shoot-through.The 74HC04 is specced up to an absolute maximum +-25mA output which is way more than enough for most reference voltage switching purposes. Looking at the NXP datasheet for a 74HC04 the equivalentworst caseRDSONfor the n and p channels respectively is 65 ohms and 130 ohms (at 4mA load). The 74HC4050 has identical values. The 74HC4050 is particularly useful for this kind of application as it will tolerate 15V inputs regardless of the 'supply' voltage.

author: HwAoRrDk
author_rank: Super Contributor
timestamp: December 13, 2016, 07:26:50 pm
content: Thanks for the suggestion.I had forgotten about inverters.I had a 4069 knocking around, so I did some experiments with that. Given the results, I think I'll definitely go with a single-gate CMOS inverter (either 741G04 or 741G14), as it's proved to be of benefit in terms of preserving voltage level on the reference output.With a 10K pull-up on the 2N7000, it was dropping the 'high' reference voltage a little bit (~10mV). It would be nice to keep my 'high' reference as near to VCC as possible (although I'm notthatbothered if it isn't), but using a stronger (3K) pull-up to remedy this made the current draw needlessly high (a couple of mA).The inverter gives me output exactly equal to VCC with no fuss.And another benefit of the inverter is that I no longer need either a gate resistor nor pull-up, just a decoupling cap.