I want to invert, difference, and amplify the 11.3-12V decaying (upwards to 12V) signal from the metal detector coil in the circuit at https://www.lammertbies.nl/electronics/pi-metal-detector into a 0-5v range signal compatible with microcontroller ADCs.

I looked at Level shifting a +/- 2.5V signal to 0 - 5V and the answers there, especially the https://electronics.stackexchange.com/a/37096/30711 which contains the only example of an inverting level shifter I've found, but since I want amplification and the input signal is not centered on zero, my use-case seems a couple steps more complicated.


simulate this circuit – Schematic created using CircuitLab

I figure that this will clip with 0+-2.5V on the output, but I'm not quite sure how to inject an offset to push it up an additional 2.5v.

Do I sum in another voltage on the negative input?

Or would I adjust the positive input to something else?


For clarity, I'd like for the circuit to do approximately V_out = (12-V_in) * 7. I make plenty of sign and order of operations errors in my day job, and I'm curious how to translate this operation into an opamp. My attempt above seems like it would do V_out=(12-Vin)*7+(12V+0V)/2

Some completely fabricated curves of simulated input and desired output are below.

# R code:
y1= 12-0.7* ifelse(x < 0.010,1,exp(-200*(x-0.010))); plot(x,y1,'l',col='black')
y2= 12-0.7* ifelse(x < 0.008,1,exp(-250*(x-0.008))); lines(x,y2,'l',col='red')
y3= 12-0.7* ifelse(x < 0.012,1,exp(-150*(x-0.012))); lines(x,y3,'l',col='blue')
y1= 7*0.7* ifelse(x < 0.010,1,exp(-200*(x-0.010))); plot(x,y1,'l',col='black')
y2= 7*0.7* ifelse(x < 0.008,1,exp(-250*(x-0.008))); lines(x,y2,'l',col='red')
y3= 7*0.7* ifelse(x < 0.012,1,exp(-150*(x-0.012))); lines(x,y3,'l',col='blue')

Simulated sample transient input voltages:

enter image description here

Simulated sample transient output voltages:

enter image description here

  • \$\begingroup\$ It's unclear to me when you say "invert". Do you want 11.3 V to go to 0 V and 12 V to go to 5 V or 11.3 V to go to 5 V and 12 V to go to 0 V? \$\endgroup\$
    – user173271
    Nov 18, 2021 at 22:56
  • \$\begingroup\$ Are you interested in the DC component or is it possible to AC-couple the signal to get rid of DC? \$\endgroup\$
    – bobflux
    Nov 18, 2021 at 23:10
  • \$\begingroup\$ would I adjust the positive input to something else? That's the way to do it. \$\endgroup\$ Nov 18, 2021 at 23:21
  • \$\begingroup\$ @james -- by invert I mean multiply by -1 -- the metal detector circuit has a low-side switch om the coil and is emitting a signal tat decays back to +12v. I would like it to decay from near 5v towards zero for the ADC. \$\endgroup\$
    – Dave X
    Nov 18, 2021 at 23:32
  • \$\begingroup\$ AC couple it - if you attempt to just do a DC offset it will require constant adjustment when the 12v power drifts. \$\endgroup\$ Nov 18, 2021 at 23:44

2 Answers 2



$$ output = ( 12V - input ) * ( 5/0.7 ) $$


simulate this circuit – Schematic created using CircuitLab

R1,R2 gives the needed -7.14 gain

R3,R4 gives the needed bias to give 0V out when in is 12V (by symmetry)

use 1.1K in series with 300 ohms for R1 and R3

a good thing about ther LM358 is that its output goes to the negative supply, but unfortunately the input can only go to withing 2v of the positive supply.

there;s also a problem in that the output is not limited to 5V if the input goes out of range. but ther LM358's waek output stage is unlikely to be able to do any damage.

That power supply requirement is a pain. So, can better be done?



simulate this circuit

Here I've added 2k resistors pulling fown on the inverting and non inverting inputs.

This reduces the input votlage to the op-amp to arounnd 7V (I have not done the arithmetic) allowing it to operate off a 12V supply. or even lower.

Because it's symmetical this change does not alter the operating point of the amplifier output.

  • 4
    \$\begingroup\$ Specify the rails for the LM358 (it's not a great opamp) and the error bounds given a specified resistor tolerance and bias and offset currents and I think this answer is worth lots of +1 from everyone. Nice topology. I'm +1, anyway. But I'd like to see more written about it. \$\endgroup\$
    – jonk
    Nov 19, 2021 at 4:58
  • 1
    \$\begingroup\$ true, that naiive circuit is not as simple as it first appearsed \$\endgroup\$ Nov 19, 2021 at 9:14
  • \$\begingroup\$ To keep the single 12V supply, and accommodate the LM358's Vin < Vcc-2V constraint, I suppose I could run the input through a 10/12 voltage divider, increase the gain to `G=5/0.7*12/10=-8.57... // Ah, I see--the "(by symmetry)" is that at 0V, Vin- = Vin+, so you design the V+ bias voltage to match the desired 0V output. \$\endgroup\$
    – Dave X
    Nov 19, 2021 at 16:44
  • \$\begingroup\$ For high-side operations like this, maybe the TL081 would be good with it's input range of (Vcc-+1.5V to Vcc+) as compared to the LM358's range of (Vcc- to Vcc-1.5C) ti.com/lit/ds/symlink/tl081.pdf vs ti.com/lit/ds/symlink/lm158-n.pdf \$\endgroup\$
    – Dave X
    Nov 20, 2021 at 3:36
  • 1
    \$\begingroup\$ by addign two resistors the output can be brought into the acceptable range for the op-amp (see edit) \$\endgroup\$ Nov 20, 2021 at 4:53

Level Translator

If input signal drifts with the power rail then output accuracy should be maintained.

  • \$\begingroup\$ Why does it take eight (8) resistors to bias the non-inverting input? \$\endgroup\$
    – AnalogKid
    Nov 19, 2021 at 2:06
  • \$\begingroup\$ @AnalogKid To get the accuracy. Thevenin equiv cct of R7/R9/R1/R8 is 11.65 V voltage source in series with 9k1 resistor. This Thevenin voltage must be equal to the mid-voltage of the input range. Thevenin equiv cct of R4/R5/R10/R11 is 2.5 V voltage source in series with 65k resistor. This Thevenin voltage must be equal to the mid-voltage of the output range. The two Thevenin resistances must be equal to the two resistances connected to the inverting input and there ratios are equal to 5V/0.7V. \$\endgroup\$
    – user173271
    Nov 19, 2021 at 2:23
  • \$\begingroup\$ So the feedback gives a 65K/9.1K=7.14 gain, and on the + terminal, the 12V* (312k)/(312k+9370) voltage divider gives a 11.65V reference which is the center of the range of interest, and the (82100)/(82100+312e3)*12 voltage divider gives a 2.5V reference, which is the center of the output range. How do you choose the particular voltage dividers? // I'm reading your comment about matching the Thevenin resistances of the input and feedback resistors, but could you point me at why? \$\endgroup\$
    – Dave X
    Nov 19, 2021 at 2:56
  • \$\begingroup\$ you're not getting 4 figures of voltage accuracy by using 8 5% resistors. or even 1% resistors. \$\endgroup\$ Nov 19, 2021 at 4:04
  • \$\begingroup\$ @Jasen Yes, I agree. Yours is a better solution. \$\endgroup\$
    – user173271
    Nov 19, 2021 at 4:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.