Mr RB
Well-Known Member
...
If it is difficult to do the math in basic would it be better to go with the setup Eric suggested with the op-amp?
...
Hi BigAl if you are talking about using the voltage divider referenced to Vdd 5v the math should be quite easy.
The voltage measured by the divider->ADC will be referenced to +5v.
-12v in = 17v less than ref
-5v in = 10v less than ref
as you can see there is an offset of 5v you need to subtract from both ADC values.
Then you just scale the result with one scaling value (which fixes the resistor divider and also convers ADC units to real volts in one scaling operation).
The easy way is to setup the divider and connect it to 0v, it will display the ADC offset which you can then subtract. Then connect it to -12v etc and display the result, and that gives you the scaling factor.
If you want to work it all out in math first before trimming it then you need to provide the Vref voltage and the 2 resistor values. But you may still need to trim the values later in testing anyway.
Last edited: