Auto-ranging voltmeter circuit with PIC uC ADC

I want to design an autoranging voltmeter with a PIC microcontroller and its ADC.

Requirements:

• Measure voltages from +0.2v to +50v
• Protect against reverse inputs or slightly higher voltages
• Input impedance can be quite low, drawing up to a few mA.
• Accuracy of around 1% or better (although not necessary for smaller voltages)
• Sample time of around 0.5ms or better

I have a circuit in mind, and would appreciate feedback. Perhaps there are simpler circuits I could use. The PIC will be on a 5v supply. I would probably use a basic, cheap op-amp running from 0v and a +12v rail. The tristate uC outputs would either set the input voltage dividers or alter the gain of the op-amp circuit to higher than unity.

simulate this circuit – Schematic created using CircuitLab

Does this look reasonable?

-

I'm not 100% on this but I think most PIC ADCs are 10 bit (1 in 1024 resolution) but can have up to 10x LSBs inaccuracy - this means you're just about at the 1% accuracy stage without considering resistor accuracies.

Using PIC outputs as pull downs isn't a good idea either because there will be leakage currents from the pins that will add/subtract a voltage from the signal via the resistors. Also, you appear to be relying on PIC outputs going exactly to ground but neither is this the case and your accuracy on the lowest range will be dented.

Also, I think the zener won't be needed because R1 will limit current into the op-amp and it will self protect - 50V across 50k gives 1mA and most op-amps are capable of dealing with this sort of current using their internal diodes. I'd run the op-amp from 5V too - this means there's no chance it can stuff a killer voltage (6V or above) into the PIC ADC pin. Use something like an AD8605 - it is rail to rail but, because you can't exactly achieve 5V, scale things down by 10% and restore in the CPU with a frig-factor.

Having an op-amp that is self-protecting (due to the 50k) means negative voltages are also protected against but read the data sheets on the op-amp to be absolutely sure. If you still think you need the zener, consider that a zener will be starting to draw current at voltages significantly below 5V - it isn't an on-off thing as soon as you hit 4.99 volts.

-
Thank you. I will look into the leakage currents and logic 0 level digital outputs of the uC pins. Perhaps I could use NPN transistors to minimise leakage currents for the pull-downs, and consider drop of those. However with any luck I can compensate for the leakage and non-zero pull down voltage of the uC pins in software –  Jodes Jan 16 at 11:57
I'd use MOSFETs or analogue switches - they'll switch without much leakage and their on resistance will be a fraction of an ohm if you pick the right one. –  Andy aka Jan 16 at 12:18
My approach would be so design each range separately (maybe with a common front end), connect each to a different A/D pin, and have the PIC switch its A/D input as needed. –  Wouter van Ooijen Jan 16 at 14:08
Correct. The chip already has a mux so why not use that. The catch is that the 'higher gain' input(s) must not output anything outside 0 .. Vcc into the A/D inputs, even when not selected. –  Wouter van Ooijen Jan 16 at 15:06
Personally, unless cost were an issue, my approach would be to use a good serial ADC with a programmable gain amp. Something like ti.com/lit/gpn/ads1146. At less than \$3, cost might not even be that big an issue, considering the big change in component count. –  Scott Seidman Jan 16 at 15:47

Most pic microcontroller has 10 bit ADC and for that you have to convert it by formula like:

$$Value=value*\left(\frac{reference_{mV}}{2^{10}-1}\right)$$

$$Value=value*\left(\frac{5000}{1024-1}\right)$$

$$Value=value*4.89$$

or you visit this link they written it very good explanation with c code.

-
If you are in any way affiliated to that blog, please openly disclose it as self-promotion is deprecated on this site. –  clabacchio Mar 6 at 10:28
@clabacchio Why do you think that? –  Butzke Mar 6 at 10:35
@Butzke based on post history, here and on Stack Overflow. He repeatedly links to blog pages from the same site. –  clabacchio Mar 6 at 10:39
Not to mention also like your last blog post the code is horrible and outside of mikroC that wouldn't compile on any standard C compiler. –  PeterJ Mar 6 at 10:52