I am trying to create a circuit which will allow me to scale and offset a voltage (be it AC or DC) to within the range of the Arduino ADC.

The voltage could be anything between + and - 250V, but I also need to have good sensitivity over lower voltage ranges too.

To this end I am looking at a circuit whereby you can vary the voltage range that it expects the input to be and amplify/attenuate it accordingly.  How I will be making the decision and setting the different gains is for another topic for now.  I am only interested in the scaling and offsetting at the moment.

So far I have come up with this circuit:



Which appears to do just what I want for the +/- 250V range.  I don't know how "safe" this circuit is, and if I am endangering any of the components with the 250V or not.  The graphs at the bottom are (left to right) the input voltage, the power consumption of the bottom 10M resistor, the voltage across the 100M resistor (which is simulating the Arduino ADC input) and the power consumption of the upper 10M resistor.

Now, if I drop the input voltage to just +/- 2.5V and tweak the op-amp feedback resistor accordingly, for some reason the offset voltage the op-amp is adding jumps right up.  I don't know for sure if this is the fault of the simulator I am using, or if it is really what will happen, as I haven't yet breadboarded this circuit (I guess that's the next stage).

This is the output from the 2.5V version:



You can see how the offset has jumped up and the output is clipping massively.

If I drop the lower 10K resistor to the virtual ground offset voltage divider to just 3.3K it compensates, but that's not nice - I would like to just vary the one resistor.  

The op-amp is (will be) a 5V single supply rail-to-rail I/O one.

The two diodes are to protect the input of the op-amp against over voltage - I don't know if this circuit strictly needs them, but I guess it doesn't hurt to have them there.

Also, I don't know if the resistor values are quite what I want - I chose them to keep the power consumption right down and the impedance right up.  I don't want them to impact the frequency response of the circuit more than I can help - the input waveform could be anything from DC up to around 500KHz or so, and I need that reproducing at the ADC end as faithfully as I can.  (I know the Arduino can only really sample at lower speeds than that, but the Arduino is just for experimenting - the final system will use a dsPIC with 1.1Msps ADC).

So, what can I do to A) get a more stable offset, B) allow the varying of the input sensitivity without nuking either the op-amp or the ADC, and C) make the circuit safe to connect to, for example, a European mains voltage?


Question: A Question on Auto-Adjoint functors
Answer: It's a good question; the answer is no. 

Suppose $F \dashv F^{op}$ with unit $\eta: 1_C \to F^{op} F$ and counit $\varepsilon: F F^{op} \to 1_{C^{op}}$. Since $\varepsilon$ is the unique transformation $\theta: F F^{op} \to 1$ such that 

$$1_{F^{op}} = (F^{op} \stackrel{\eta F^{op}}{\to} F^{op} F F^{op} \stackrel{F^{op}\theta}{\to} F^{op})$$ 

the question is whether $F^{op}\eta^{op} = (\eta F^{op})^{-1}$. 

Take $C$ to be an commutative group $G$, considered as a category with one object $\bullet$. Here we may simply identify $G^{op}$ with $G$, i.e., the identity $1_G \colon G \to G$ may be seen as a contravariant functor because we have $1_G(g h) = 1_G(h)1_A(g)$ by commutativity. Now take $F$ and therefore $F^{op}$ to be the identity on $G$. Any element $u \in G$ as morphism $\bullet \to \bullet = F^{op} F \bullet$ can serve as the unit transformation (naturality also follows from commutativity). But then, as soon as $u$ is not equal to $u^{-1}$, we have $F^{op}u^{op} = u \neq u^{-1} = (u F^{op})^{-1}$. Therefore taking $G$ to be the additive group $\mathbb{Z}$ and $u = 1 \in \mathbb{Z}$, we reach a counterexample.