Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 16:51 02 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Calibrating Voltage Divider

Author Message
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 06:50am 10 May 2018
Copy link to clipboard 
Print this post

I have a project that uses a MX170 to monitor and report voltage levels. The analog pin of the PIC has a voltage divider of 10K/ 50K and the voltage is read after the drop over a polarity protection Schottky Diode. In my calibration code I do a measurement with 4.00 volts (V1) applied and then a measurement at 14.00 volts (V2). I assumed that if I use the equation 10/(V2-V1) should give me the gradient and therefore the factor to convert the pin voltage to the real voltage disregarding the voltage drop across the diode. To get the voltage drop across the diode I used the equation 4-(V1*(10/V1-V2)).

I am not getting the accuracy that I would like. I realise that there will be some current flow into the PIC but I believe it should be insignificant.

Have I forgotten something?
 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 07:40am 10 May 2018
Copy link to clipboard 
Print this post

Hi OA47
I think I recall reading somewhere that the PIC Chip likes input impedances less than about 2k. I would try a 10k - 12K & a 1k8 or 2k2 & see how that goes. I haven't had any problems with this arrangement. Also, if the Schottky Diode is a low leakage type (some aren't), I would put it reversed biased across the bottom resistor (lower value one, input to ground) rather than in series with the voltage divider. The 3.3 volts to the MX170 also needs checking & calculations adjusted accordingly if not exactly 3.3V. Geoff mentions this in the manual. Actually, this would be taken care of if you compare your input volts with what the MX170 reads & go from there.
On one of mine I have a 3k9 & a 1k for measuring up to ~15V & the calcs come out as
Bat_Volts = pin(25) * 4.705
Hope this helps.
Edit. Just did a check. Slightly out (12.1V at 12.25V). Needs a re-cal
Edit 2. Cal factor is now 4.76. I must have put the extra 0 in the original & didn't check it.Edited by Chopperp 2018-05-11
ChopperP
 
palcal

Guru

Joined: 12/10/2011
Location: Australia
Posts: 1993
Posted: 08:56am 10 May 2018
Copy link to clipboard 
Print this post

If you have a voltage divider of 50K and 10K that is 60K total. Assuming the 10K is the grounded end the voltage at the junction will be 10/60 or 1/6. So if your reading is 4 volts the voltage would be 24 volts.
Paul.

"It is better to be ignorant and ask a stupid question than to be plain Stupid and not ask at all"
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 10:48am 10 May 2018
Copy link to clipboard 
Print this post

@ Chopperp. The pic is reading the supply voltage to the circuit, so the diode is in the supply line. I chose the higher resistances as I wanted to draw the minimum amount from the supply. The PIC wakes every second for a couple of microseconds and does the read then returns to sleep.

@palcal. The 4V/14v are set as the supply voltage to the circuit so the voltages that the pic sees are 0.666 and 2.333V respectively from the divider.

 
Chopperp

Guru

Joined: 03/01/2018
Location: Australia
Posts: 1097
Posted: 01:19pm 10 May 2018
Copy link to clipboard 
Print this post

Yeh, I thought that may be the reason for the high resistances. Understand now about the diode.
P49 of the MM Manual says for accurate readings, the source impedance should be <5k, which is the lower resistor in a divider.
If you multiply the PIN(ADC_IN) volts by 6 (you're division ratio) in your program, do you get a ball park reading for the voltage after the series diode? The diode drop (which would need to be measured with a DMM) should just be added to this figure to give the battery volts. If the load current to the circuit isn't changing much, the diode drop should be fairly constant at around 0.3V - 0.4V.
Does it read more accurately if it doesn't go to sleep? You may also have to to take a couple of readings & then average them.
Also some circuits put a 10R resistor between the 3V3 supply & the ADC supply pin (28) & bypass that with a low ESR Cap to isolate it.
All I did to calibrate mine initially was to connect the MM in terminal mode, read the pin volts with the PIN() command & adjust the multiplication factor until I got the right result.
Hope this helps. (Got me thinking a bit more)
ChopperP
 
isochronic
Guru

Joined: 21/01/2012
Location: Australia
Posts: 689
Posted: 02:49pm 10 May 2018
Copy link to clipboard 
Print this post

What is the required accuracy ? Is it a DC or AC measurement ?
The pic input is fairly low impedance for AC and some meg or so resistance for DC. Often an opamp is (or should be) used to drive the pic ad inputs.
Drawing a microamp from a 10k/50k divider will cause a few millivolts error.
Ordinary multimeter measurements are often surprisingly off in the first place.
Is the diode a leakage path ? schottkys often leak.
Also the pic ad supply is often via 10 ohm resistor, so the milliamp or so power drawn by the AD when it is active will cause a small difference from a rail reference level.
Filtering out noise is important too...
I once went through the exercise, with voltage references and a 22 bit A/D,
eventually getting to about 10 ppm accuracy limited by suburban noise. It takes a serious effort though.
 
Volhout
Guru

Joined: 05/03/2018
Location: Netherlands
Posts: 5091
Posted: 02:55pm 10 May 2018
Copy link to clipboard 
Print this post

Dear OA47,

You complain about not getting the accuracy you want. Please explain the expectation, and the actual result.
Are you lacking absolute accuracy, or do you observe an offset?

Please note that the ADC in the mx170 is 12 bits. If you use part of its range, you will even get less.
And it allways +/- 1 bit.
So regardless of your voltage divider, if you are at the lower 10'th of the range, your 12 bit adc will look like it has only 1 or 2 percent accuracy.

The is also a report in this forum, where the micromite (mx170) appears less accurate than a maximite.

So please explain your concern in detail.
PicomiteVGA PETSCII ROBOTS
 
OA47

Guru

Joined: 11/04/2012
Location: Australia
Posts: 986
Posted: 05:11am 11 May 2018
Copy link to clipboard 
Print this post

  Quote  So please explain your concern in detail.


The Micromite is monitoring a 12 V Lead Acid battery so I would expect the highest readings would be around 14V. I chose the 10K/50K divider to utilise a large amount of the 0-3V3 range of the analog input (typically around 2.5 V @14.4V ) and still have a safety overhead. I tried to set up a calibration routine spot checking 2 or 3 voltages in the program and self calculating the gradient and offset when I had a few to set up to make the process quicker but found I was out sometimes by 0.2 V. The accuracy can be adjusted by trial and error and give good results across 3.5V to 15V supply.

My reason for the post was to make sure that my mathematics were logical and that I had not allowed for something.

OA47
 
jimbotron
Regular Member

Joined: 27/11/2013
Location: Australia
Posts: 50
Posted: 02:36pm 11 May 2018
Copy link to clipboard 
Print this post

Hi OA47,
The equation appears to have some errors. The proper equation is:

Vs=4+Vd+(Vin-V1)*10/(V2-V1)
Where:
- Vs is the supply voltage
- V1 is the ADC value at 4V
- V2 is the ADC value at 14V
- Vin is the ADC value during normal operation
- Vd is the average voltage drop across the protection diode.

This assumes the zero offset in the ADC is negligible.
To account for the diode drop, the 4 and 14V calibration voltages should be measured where the diode connects to the voltage divider and not at the supply.Edited by jimbotron 2018-05-13
 
jimbotron
Regular Member

Joined: 27/11/2013
Location: Australia
Posts: 50
Posted: 03:16pm 11 May 2018
Copy link to clipboard 
Print this post

Silly me, I misread the original post. Ignore my previous message. I mistook the calculation for the constant term for the voltage.
There is an error in that formula, it should be:

Diode Voltage Drop and zero offset = 4-V1*10/(V2-V1) or 14-V2*10/(V2-V1)

Final equation is:
Vsupply = 4-V1*10/(V2-V1) + Vadc*10/(V2-V1)
= 4 + (Vadc-V1)*10/(V2-V1)

Which is almost the same, except this time you don't need to measure the diode voltage drop.
 
Print this page


To reply to this topic, you need to log in.

The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025