Author Topic: Subtracting a constant voltage from an input voltage  (Read 14082 times)

0 Members and 1 Guest are viewing this topic.

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Subtracting a constant voltage from an input voltage
« on: October 23, 2016, 07:57:36 pm »
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 swing
Divide it by 3 to yield a 4.34 - 3 V swing using a voltage divider
Use a simple opamp buffer as to not load the divider
Subtract 2.8 V from it using a differential amp, yielding a 1.5V to  0.2 V swing
and 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?


 

Online Vgkid

  • Super Contributor
  • ***
  • Posts: 2710
  • Country: us
Re: Subtracting a constant voltage from an input voltage
« Reply #1 on: October 23, 2016, 08:04:12 pm »
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
« Last Edit: October 23, 2016, 08:06:40 pm by Vgkid »
If you own any North Hills Electronics gear, message me. L&N Fan
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Re: Subtracting a constant voltage from an input voltage
« Reply #2 on: October 23, 2016, 08:06:32 pm »
If I understand this correctly, certain (I am guessing higher end) op amps include a offset pin? Very interesting...!
 

Online Vgkid

  • Super Contributor
  • ***
  • Posts: 2710
  • Country: us
Re: Subtracting a constant voltage from an input voltage
« Reply #3 on: October 23, 2016, 08:07:50 pm »
That offset pin is for the offsets in the millivolt range.
If you own any North Hills Electronics gear, message me. L&N Fan
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Subtracting a constant voltage from an input voltage
« Reply #4 on: October 23, 2016, 08:20:39 pm »
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:

 
The following users thanked this post: BurnedResistor

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Re: Subtracting a constant voltage from an input voltage
« Reply #5 on: October 23, 2016, 08:23:42 pm »
Sadly this is battery monitoring, so a shunt regulator really is not optimal.
 

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Subtracting a constant voltage from an input voltage
« Reply #6 on: October 23, 2016, 10:02:36 pm »
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.
 
The following users thanked this post: BurnedResistor

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3358
  • Country: nl
Re: Subtracting a constant voltage from an input voltage
« Reply #7 on: October 23, 2016, 10:11:38 pm »
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.
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Re: Subtracting a constant voltage from an input voltage
« Reply #8 on: October 24, 2016, 10:13:26 am »
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.
'


Wow. That is very elegant. Could you point me towards some recourseces/names so I could learn more about this kind of circuit?
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Re: Subtracting a constant voltage from an input voltage
« Reply #9 on: October 24, 2016, 10:16:32 am »
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.

I 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?
 

Offline Alex Nikitin

  • Super Contributor
  • ***
  • Posts: 1177
  • Country: gb
  • Femtoampnut and Tapehead.
    • A.N.T. Audio
Re: Subtracting a constant voltage from an input voltage
« Reply #10 on: October 24, 2016, 11:31:27 am »
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.

Cheers

Alex
 
The following users thanked this post: BurnedResistor

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Subtracting a constant voltage from an input voltage
« Reply #11 on: October 24, 2016, 11:55:12 am »
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.
« Last Edit: October 24, 2016, 12:02:10 pm by Ian.M »
 
The following users thanked this post: BurnedResistor

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Subtracting a constant voltage from an input voltage
« Reply #12 on: October 24, 2016, 12:07:05 pm »
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.
« Last Edit: October 24, 2016, 12:09:29 pm by Kalvin »
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Subtracting a constant voltage from an input voltage
« Reply #13 on: October 24, 2016, 12:17:13 pm »
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.

you 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.
 
The following users thanked this post: BurnedResistor

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: Subtracting a constant voltage from an input voltage
« Reply #14 on: October 24, 2016, 12:20:01 pm »
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:


The 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.
« Last Edit: October 24, 2016, 12:22:01 pm by Hero999 »
 
The following users thanked this post: BurnedResistor

Online Ian.M

  • Super Contributor
  • ***
  • Posts: 12860
Re: Subtracting a constant voltage from an input voltage
« Reply #15 on: October 24, 2016, 12:26:43 pm »
Add a high side P-MOSFET to switch it off, and you've got something usable for battery monitoring . . . .
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Subtracting a constant voltage from an input voltage
« Reply #16 on: October 24, 2016, 12:28:48 pm »
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.

you 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.

That'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.
 

Offline Kalvin

  • Super Contributor
  • ***
  • Posts: 2145
  • Country: fi
  • Embedded SW/HW.
Re: Subtracting a constant voltage from an input voltage
« Reply #17 on: October 24, 2016, 12:30:24 pm »
Add a high side P-MOSFET to switch it off, and you've got something usable for battery monitoring . . . .

An 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.
« Last Edit: October 24, 2016, 12:38:09 pm by Kalvin »
 

Offline rob77

  • Super Contributor
  • ***
  • Posts: 2085
  • Country: sk
Re: Subtracting a constant voltage from an input voltage
« Reply #18 on: October 24, 2016, 12:46:06 pm »
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:


The 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.


agree 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 ;)
 

Offline Alex Nikitin

  • Super Contributor
  • ***
  • Posts: 1177
  • Country: gb
  • Femtoampnut and Tapehead.
    • A.N.T. Audio
Re: Subtracting a constant voltage from an input voltage
« Reply #19 on: October 24, 2016, 12:58:10 pm »
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.

Cheers

Alex
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: Subtracting a constant voltage from an input voltage
« Reply #20 on: October 24, 2016, 03:48:35 pm »
Add a high side P-MOSFET to switch it off, and you've got something usable for battery monitoring . . . .
That 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.
« Last Edit: October 24, 2016, 06:18:52 pm by Hero999 »
 
The following users thanked this post: BurnedResistor

Offline rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Subtracting a constant voltage from an input voltage
« Reply #21 on: October 24, 2016, 05:25:28 pm »
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
 
The following users thanked this post: BurnedResistor

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 19520
  • Country: gb
  • 0999
Re: Subtracting a constant voltage from an input voltage
« Reply #22 on: October 24, 2016, 06:15:29 pm »
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
Yes, 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.pdf

For 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.

« Last Edit: October 24, 2016, 06:17:09 pm by Hero999 »
 
The following users thanked this post: BurnedResistor

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Re: Subtracting a constant voltage from an input voltage
« Reply #23 on: October 24, 2016, 07:10:38 pm »
Wow you guys are crazy. Thank you all :)
 

Offline BurnedResistorTopic starter

  • Regular Contributor
  • *
  • Posts: 192
  • Country: at
Re: Subtracting a constant voltage from an input voltage
« Reply #24 on: October 26, 2016, 08:33:37 pm »
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

I 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?
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf