Subtracting a constant voltage from an input voltage - Page 1
Forum section: electronics / projects

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 23, 2016, 07:57:36 pm
content: In the interest of getting my hands dirty with a bit of analog circuitry, I am trying to convert a 13V - 9V voltage swing of a battery to the 0 - 3.3V measurable by the adc of my mcu.Now I realized that a simple voltage divider with a division 4 would give me a one volt swing, so the 12 bit adc of the mcu would give me more than enough data, but this is more a learning exercise than a practical engineering challenge.My Idea was to:Take the 13-9 voltage swingDivide it by 3 to yield a 4.34 - 3 V swing using a voltage dividerUse a simple opamp buffer as to not load the dividerSubtract 2.8 V from it using a differential amp, yielding a 1.5V to 0.2 V swingand then amplify the signal by 2.1, yielding the desired 3.15 to 0.42 V swing.The voltage divider and buffer are easy enough to implement. The multiplication by 2.1 can be achieved using a non inverting amplifier.It is the subtraction of 2.8V that is proving to be challenging.My idea was to setup a differential amp with a gain of 1, and set the non-inverting input to the 2.8V. This would however require a relatively precise 2.8V. I could implement a zener voltage reference, but that seems to be a very complex solution to a simple subtraction.Is there a better way to scale this signal? I have a 5V and a 3.3V rail available.Even if there is, Any ideas on how you could subtract 2.8V from a signal, that is not a differential amp?

author: Vgkid
author_rank: Super Contributor
timestamp: October 23, 2016, 08:04:12 pm
content: For the 2.8v you could use a tl431. Look into opamp external offset circuits for some examples.https://www.maximintegrated.com/en/app-notes/index.mvp/id/803

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 23, 2016, 08:06:32 pm
content: If I understand this correctly, certain (I am guessing higher end) op amps include a offset pin? Very interesting...!

author: Vgkid
author_rank: Super Contributor
timestamp: October 23, 2016, 08:07:50 pm
content: That offset pin is for the offsets in the millivolt range.

author: rob77
author_rank: Super Contributor
timestamp: October 23, 2016, 08:20:39 pm
content: is a high impedance a must ? (e.g. monitoring a batery) or can it be low impedance ? (e.g. battery charging)...if low impedance is not a problem you can shove in an tl431 shunt regulator set to 9V in series with the input and that will bring down the voltage to 4-0V - you can then divide and buffer that.something like this:

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 23, 2016, 08:23:42 pm
content: Sadly this is battery monitoring, so a shunt regulator really is not optimal.

author: Ian.M
author_rank: Super Contributor
timestamp: October 23, 2016, 10:02:36 pm
content: Its easier if you invert the input signal to the ADC, then invert the ADC result.For a 9V-13V input range gives a 3.066V-0.072V (approx) output range. It can easily be trimmed for gain and offset. It does depend on the stability of the 3.3V rail but as most MCU ADCs are ratiometric to AVdd/AVref, you cant do better without a precision reference. There's probably a better choice of rail-to-rail OPAMP - that was the first LTSPICE one I could find that could run at 3.3V with sub-uA bias current.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: October 23, 2016, 10:11:38 pm
content: When using a TL431 you can juse the adjust pin to tun the TL431 off between measurements.Or add a little mosfet to switch your input circuit.

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 24, 2016, 10:13:26 am
content: Quote from: Ian.M on October 23, 2016, 10:02:36 pm'Wow. That is very elegant. Could you point me towards some recourseces/names so I could learn more about this kind of circuit?

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 24, 2016, 10:16:32 am
content: Quote from: Ian.M on October 23, 2016, 10:02:36 pmI noticed that at vd, the voltage swing is extremly low (1.22 - 1.26V). To my understanding this would make the circuit very sensitive to noise, as even the slightest noise at this node would cause huge voltage swings after the amplification?

author: Alex Nikitin
author_rank: Super Contributor
timestamp: October 24, 2016, 11:31:27 am
content: It is an inverting amplifier configuration, so vd is very close to the virtual ground point, hence the small voltage variations. It is not a problem, it's a feature.CheersAlex

author: Ian.M
author_rank: Super Contributor
timestamp: October 24, 2016, 11:55:12 am
content: In- is a virtual earth. You expect a very small voltage at vd because the circuit is essentially current driven. The current through R7 must be equal to the current through R5 to keep in- at the same voltage as in+ (vr).I only labelled vd to make it convenient to detect if the input was entering a non-linear region as the output approached the rails.Of course, with a 1.8Meg input resistor it is going to be sensitive to noise - that's unavoidable if you want a very low drain on the battery. You could scale R1, R2, R5 & R7 by a factor of 1/10 without affecting circuit operation to decrease the input impedance.Alternatively, try this new version that includes caps to roll-off its response above 1.3KHz and also reduces the impedance of various nodes. To check if its still in its linear region, do a transient analysis, plotting V(vm,vr) in a separate plot plane, which should only be +/- a few uV. You will see its spiking up because the output is hitting the -ve rail a little too hard, so decrease the gain a smidgen by increasing R7 to 22K.

author: Kalvin
author_rank: Super Contributor
timestamp: October 24, 2016, 12:07:05 pm
content: Something like this could work:- The R1 and R2 will be selected so that the current is suitable for the zener or TL431.- The R1 and R2 will be selected so that the voltage will be scaled nicely for the 3V3 output voltage range.- The 1Mohm resistor will limit the input current into op amp when the N-MOSFET is not enabled.- The N-MOSFET is used to enable/disable the voltage subtractor in order to minimize the current consumption when the battery voltage is not measured.- For even further current consumption reduction the N-MOSFET can also be connected to the negative power supply of the op amp.

author: rob77
author_rank: Super Contributor
timestamp: October 24, 2016, 12:17:13 pm
content: Quote from: Kalvin on October 24, 2016, 12:07:05 pmyou would need a constant current sink to keep the current through the zener constant and therefore keep the voltage across zener stable.... your circuit is basically the same as i proposed above (but not usable in OP's case due to low impedance/high current draw). this kind of circuit (with a proper shunt regulator, not a plain zener) is suitable for battery chargers where the few mA draw is not a problem.

author: Zero999
author_rank: Super Contributor
timestamp: October 24, 2016, 12:20:01 pm
content: Quote from: rob77 on October 23, 2016, 08:20:39 pmThe problem with that is the TL431 needs to have at least 1mA flowing through it, otherwise it won't reliably drop the required voltage.As mentioned above. Use a current sink to load the TL431, rather than just resistors. Here's an example which will subtract 19.5V from the input voltage. The component values could be changed and a potential divider added to convert 9V - 13V to 0V to 3.3V.

author: Ian.M
author_rank: Super Contributor
timestamp: October 24, 2016, 12:26:43 pm
content: Add a high side P-MOSFET to switch it off, and you've got something usable for battery monitoring . . . .

author: Kalvin
author_rank: Super Contributor
timestamp: October 24, 2016, 12:28:48 pm
content: Quote from: rob77 on October 24, 2016, 12:17:13 pmThat's why I added an N-MOSFET in order to reduce the current consumption: When the voltage measurement is in progress, the gate of the N-MOSFET will be driven high and the N-MOSFET will be in conduction state. When the voltage measurement is completed, the gate of the N-MOSFET will be driven low and the N-MOSFET will stop conducting. When the N-MOSFET is conducting, the zener voltage and the op amp output will be stable withing a few microseconds ... tens of microseconds. Typically voltage measurement will take few milliseconds max. so the current consumption will not be very high. For example, if the current measurement will take 1 millisecond, it is performed once a second and the current through the zener/TL431 is 10mA or less, the duty cycle is 1:999 thus the equivalent continuous current consumption is 10uA or less.

author: Kalvin
author_rank: Super Contributor
timestamp: October 24, 2016, 12:30:24 pm
content: Quote from: Ian.M on October 24, 2016, 12:26:43 pmAn N-MOSFET will do just fine and it is easier to drive (see my schematics few posts above). The 1Mohm resistor at the input of the op amp will take care of the leakage current when the N-MOSFET is not conductiing. Depending of the op amp, the resistor value can be increased up to 10Mohm quite easily if needed.

author: rob77
author_rank: Super Contributor
timestamp: October 24, 2016, 12:46:06 pm
content: Quote from: Hero999 on October 24, 2016, 12:20:01 pmagree a current sink is better it will hgave a constant current draw across the whole input range, but for the current mirror you need 2 extra transistors. the TL431 can handle from 1mA to 100mA , so it's doable without the current sink. if you choose 100R total resistance for the divider and set the Tl431 for 8,9V drop then you'll will have the 1mA on the low end and 41mA on the high end of the input range... giving you a 100mV - 4,1V range, after division it would be ~ 80mV - 3.3V ... so wasting only few codes on the ADC side (0-80mV wasted). so it's able to do the job. and as i mentioned for a battery charger where you pump amperes to a battery it's not a problem.but as mentioned your current sink with mirror is better in terms of performance

author: Alex Nikitin
author_rank: Super Contributor
timestamp: October 24, 2016, 12:58:10 pm
content: I would rather keep it simple. Here is a version that consumes less than 5uA from the battery V1 and uses the 3.3V reference V2 from the ADC.CheersAlex

author: Zero999
author_rank: Super Contributor
timestamp: October 24, 2016, 03:48:35 pm
content: Quote from: Ian.M on October 24, 2016, 12:26:43 pmThat can be done with my circuit, without any additional components. Simply take V1 from the output of the MCU, which only needs to be high when a sample is taken. It will need to be high for a ms or so before the sample is actually read, to allow the TL431 to stabilise.EDIT:It's still desirable to disconnect the ADC from the TL431 when it isn't used. When Q1 & Q2 are off, a small unknown current will continue to flow into the ADC pin, causing it to discharge the battery.A current source would be better, even if another transistor is required to turn it off/on.Update coming.

author: rstofer
author_rank: Super Contributor
timestamp: October 24, 2016, 05:25:28 pm
content: This entire scale and offset can be done with a single rail op amp and 4 resistors. See Chapter 4 of "Op Amps For Everyone" and follow the examples for solving the equation y = mx + b'b' is the offset that moves the voltages down and 'm' is the scale that gets everything to fit.http://www.cypress.com/file/65366/download

author: Zero999
author_rank: Super Contributor
timestamp: October 24, 2016, 06:15:29 pm
content: Quote from: rstofer on October 24, 2016, 05:25:28 pmYes, you're right. Here's another paper which just deals with the scaling and offset part. A reference still may be required, if the power supply voltage is not accurate enough but if that's the case there will already be one for the ADC.http://www.ti.com/lit/an/sloa097/sloa097.pdfFor completeness here's how to do it with a TL431 and switch it off (including disconnecting it from the ADC) when not required. I was talking BS in my previous post when I mentioned a current source: that wouldn't work! An N-channel JFET can be used as an analogue switch to disconnect it from the potential divider and ADC.

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 24, 2016, 07:10:38 pm
content: Wow you guys are crazy. Thank you all

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 26, 2016, 08:33:37 pm
content: Quote from: Vgkid on October 23, 2016, 08:04:12 pmI attempted to setup a differntial amp to subtract 2.8V, but it is not quite working. Am i messing up with my circuit design or am I messing up with LTspice?

author: BurnedResistor
author_rank: Regular Contributor
timestamp: October 26, 2016, 08:38:01 pm
content: Helps to attach a file

author: Ian.M
author_rank: Super Contributor
timestamp: October 26, 2016, 08:54:49 pm
content: Its hitting the -ve rail hard. Simulate it again with +/- 15V supplies to the LT1881, then use theprinciple of Superpositionon sources V2 and V3 to understand WHY its hitting the -ve rail when operating with a 5V single supply.

author: dannyf
author_rank: Super Contributor
timestamp: October 26, 2016, 10:41:49 pm
content: A summing amp does what you want.

author: strawberry
author_rank: Super Contributor
timestamp: October 27, 2016, 12:00:14 am
content: Rail-to-rail op ampzeners are not good for frequencies

author: Smokey
author_rank: Super Contributor
timestamp: October 27, 2016, 12:46:29 am
content: Lots of good circuits here. As I read through you guys already ticked off all of the ways I was thinking of. Fun!