News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Calibration for ADC.

Started by david, Nov 06, 2023, 07:05 AM

Previous topic - Next topic

david

Hi All,
I need to make a small number of circuit boards and one of the primary functions is to measure the voltage of a 6 cell Lipo battery.  Fully charged this is 6x4.2V=25.2V and I want to indicate approximate charge rather than actual voltage - e.g. Batt Good, Batt OK, Batt Bad.  Above 23.52V is good, 22.68V to 23.46V is OK and below 22.68 is bad.  I was going to use a resistive divider using 18k and 3.9k resistors and the nominal 5.0V supply as Vref.  With this arrangement and ADC count above 856 would be good, 827 to 853 would be OK and below 827 is bad.
Now the biggest sources of error will be the 5% resistors used leading to a possible +10% or -10% error and on top of that is the 5V reference error - perhaps +/-0.1V.
Can I include in my main software a short calibration routine such that after assembly of the board I apply 24.0V and hold a cal pin low and the micro runs some special code where it reads the ADC value and writes it to EEPROM?  In normal use the cal pin is pulled high and the normal software function reads any ADC value and multiplies it by the EEPROM stored ADC val for 24V/Ideal ADC value for 24V.
It seems simple enough which usually means I'm overlooking something....

Cheers,
David

Stephen Moss

Quote from: david on Nov 06, 2023, 07:05 AMNow the biggest sources of error will be the 5% resistors used leading to a possible +10% or -10% error and on top of that is the 5V reference error - perhaps +/-0.1V.
Obviously you will have to may more for them than an 5% resistors, but 0.1% resistors have been around for a long time now, so if your reference tolerance is also 0.1% as you stated then at worst your unit to unit variation (error) would be no more than +/-0.3% from ideal.
As you gave example values in the 800-900 range I presume you would therefore be using a 10 bit ADC in which case the error value would be approximately +/-3, would that keep your error low enough so that the calibration was not required?

ken_k

Hi David
I like Stephens idea of using better resistors as they are quite cheap these days. I see nothing wrong with using a calibration pin and have used the idea successfully in the past with no problems at all, for some reason I have always held my cal pin low and used high to calibrate. My main source of error was often Vref so the cal data from one input was good enough to adjust multiple inputs.

david

Hello Stephen,
Many thanks for your thoughts there.  Yes I could use 0.1% resistors to ensure the divided Vin was correct and I also considered adding a small rheostat to adjust the divided input correctly but I'm also curious about the feasibility of using standard parts and a self-calculated correction factor of an ideal 24.0V input ADC value divided by the actual measured 24.0V input ADC value.    Please note I got this fraction inverted in the last post.
If you refer to the attached examples it shows a nominal and two extremes of the 5% divider values. No Vref tolerance included at this stage.
So if we have a board as per the middle example and the calibration code measures the ADC value (949) and stuffs it in to EEPROM and then in normal use we measure any input value and multiply the resulting ADC value by the ideal 24V input ADC value (875) divided by the previously tested value stored in EEPROM (949)
So for that particular board with a divider that's too high, all ADC values are multiplied by 875/949.
I think you can apply the same thinking to the Vref and just measure and store the resulting ADC value.  In some cases, such as a high resistive divider and a high Vref, the two errors will tend to cancel.  The same applies to a low resistive divider and a low Vref.
It all seems a bit too good to be possible so I do wonder if I'm missing something here.

Cheers,
David

david

Ken,
Thanks for your reply.  It's somewhat comforting that your "prior art" was working ok.  As you can see, my requirement is across a relatively small range of ADC values.
I may end up using the MCLR pin which I need for programming in circuit but I can at least enable an internal pull-up for it, hence the idea to have the cal mode as grounded.

Cheers,
David

trastikata

Are the boards ready? A 0.2% voltage reference costs 20 cents, might be an option?

david

Hello trastikata,
No, the little pcb has yet to be designed and made so it's still an option to use a voltage reference.  It wouldn't compromise anything to add it as an option.

Cheers,
David

david

Just a quick follow up  - encouraged by ken_k's experience I added a few lines of calibration code which looks to see if the cal pin is grounded at start up and if so it measures the ADC value 16 times when a known voltage is applied (24.00V), averages the total and writes it to EEPROM.  A second later you power down and remove the jumper and you're good to go.
In measurement mode, varying the supply voltage indicated that the battery alarm levels were within 1 ADC count of where they should have been or within 20mV when measuring 23.48V.   Voltage divider was 18k and 3.9k 5% resistors and the Vref was a random pick 78l05 regulator.   I can't believe it's taken me 20 years to figure this one out.  All those preset resistors I wasted.
I guess the one calibration point is effectively a slope correction which takes in to account the variation in both the resistive divider and the Vref voltage.

David