I need to level shift a voltage that has a range of ~3V and sits between ~2 & 5V, to a non-inverted 0 - ~3V to feed to a PIC ADC input (PIC is running on 5V).
And it of course needs to done simply and cheaply (when doesn't it).
Idea #1 (ignore the resistor values for the moment, they are placeholders) open to other ideas but pcb real estate is limited.
The cap is to try and keep out any rubbish that might be on the incoming voltage and the op-amp is a rail-to-rail device TLV2371.
Nope. You want to shift the input signal range downward. But an attenuator referenced to a voltage that is greater than the average value of the input signal will shift that signal upward.
The classic four-resistor difference amplifier seems simple, but many circuit implementations perform poorly. Based on actual production designs, this article shows some of the pitfalls encountered with discrete resistors, filtering, ac common-mode rejection, and high noise gain.
www.analog.com
The 20K that connects to 5V should be grounded (output reference), and the 20K grounded should be at 2V (input reference)
And the Vin 10K & 20K should be opposite values.
Since the slope of your curve is a fixed G, all you need is an offset.
You can get a +/- 2% zener, 2V, and a R, say 1K, and that will do the offset.
Or use a 3 term adjustable Vref (the LM385 is functioning as an adjustable zener)
Note the symbol is screwy because I could not find a standard spice model for the part.
Also the 385 may be obsolete but there are replacements for it, TI, Analog Devices.....
This particular model was 2.4V I think, but you get the idea. The zener / Vref gives you a fixed
Voffset which is all you need. 2V and 2.048 V seem common as references.
The incoming voltage of interest is a user adjustable DC voltage, so slow moving at best, but it is in an RF environment so likely to have some artifacts impressed on it.
Left side of attached diagram is the bit of interest (right side is a preset - not user adjustable).
Marked voltages are assuming components are 'ideal' and 8V line is actually 8V, something we know is unlikely to happen in the real world, hence the use of ~ above.
Trying to avoid that if possible - lot of disassembly work to get to it and possibly not enough room anyway - unfortunately, I don't have the piece of equipment in front of me, it's on the opposite side of the globe.
There is an easily accessible connector that carries the voltage to tap in to.
I don't need absolute accuracy, it is a piece of (old) equipment still much in use, but I can't say much more about that until I know if this is going anywhere or not (it may be a one off or it may be a reasonable volume bit of kit).
I still need to do the numbers re the ADC reference but I would like as far as possible to have at least 1000 of the 1024 bits of the ADC available to cover the 3V, allowing for a few bits at each end and center of the range for a bit of dead band.
I'm poking this in to a 16F1827 (with software being moved across - with some additions - from an older chip)
And looking at the schematic, the Vref+ pin is being used for something else so it will have to be the internal 4.096V Ref and probably a little bit of up-scaling of the range via the op-amp.
I'll see what happens and move pin functions around if needed (I've got a couple spare).
Doing it completely in software will give a range of ~600. That is 0.16% per bit. Surely that is accurate enough as I can't position a dial to that accuracy. Note, that would be using Vdd as the reference. Is your Vdd a stable 5V supply?
No, because you have a differential amp with a gain of 1/2, thus your output offset is -1V, and the output swing is 1/2 the input swing.
Below is the LTspice simulation of your circuit adjusted for your original requirements and using a stable reference:
First I calculated the value of R1 to give an inverting gain that generates -2V output offset from the TL431 2.5V shunt reference voltage.
Then I determined the R4 and R5 input resistor values to give the desired non-inverting gain (+1 here) at the output.
In this case it can be just the same values as R1 and R2.
From that, the simulation shows the output (yellow trace) going from ≈ 0V to 3V for an input of ≈ 2V to 5V (green trace) as calculated.
Did actually try that and the output dropped from 1.2V to 1V - but it is possible I had a bad connection - been too hot and sticky in the back room today.
Turns out I had shorted a wrong resistor (In the test bed I had 2 x 10k in series for the 20k) - correcting that now gives me 0 - 2.53V output for 1.82 - 4.35V input.
I'm going to try using 100k resistors to (hopefully) lighten the load on the incoming line to restore it back to it's original 2 - 5V range.