PIC voltage ref - Page 1
Forum section: electronics / general

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 29, 2018, 08:25:12 pm
content: How accurate are the voltage reference in PICs.I have a 16F1827 using 1.024V internal ref and an LM35 and wondered how accurate the temperature reading would be.Thanks.

author: jeduffy
author_rank: Contributor
timestamp: May 29, 2018, 11:18:55 pm
content: page 342 of the PIC datasheet gives the fixed voltage reference for the ADC as +6-8% for 1.204V, the LM35 datasheet gives +-3/4C over the full range. At 10mV/C, that's +8.2-6.1 for the pic, +-0.75C for the sensor, so should be about +9-7 degrees C, if my math's not off. Could be made much more accurate by calibrating the pics reference though, as it's likely not going to drift over that entire range.

author: JS
author_rank: Frequent Contributor
timestamp: May 30, 2018, 03:45:00 am
content: Calibrating the internal reference is a good way to start, I'd also calibrate the LM35, or you could just calibrate it and the reference all together if temperature is the only thing you are measuring.So, start with the circuit, have it working, measure two temperatures with your circuit and another thermometer you trust, tweak some parameters in the code, have as good temperature reading as you can with the circuit.If you still need better you should do it different, many ways of measuring temperature, the best one will depend on the application.JS

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 30, 2018, 09:16:55 am
content: Thanks both.Currently, the voltage directly from the LM35 (via Fluke 87V) is reading 218mV, the temp on a good commercial thermometer is reading 21.4C and the PIC is showing 19.9C: it all seems to be well within parameters.As for altering the code, is it likely to be an arithmetically or geometrically varying difference? That is, I could (in the example above) add 1.5C (21.4 - 19.9) to every reading or I could add 7.54% (1.5/19.9) to them.Which is most likely to give a result that is stable over the largest temp range? Can I deduce this from the data sheet?

author: JS
author_rank: Frequent Contributor
timestamp: May 30, 2018, 02:55:06 pm
content: That's why I suggested 2 points, so you do both. you might have an offset error due to an offset in the adc input or the LM35 not outputing 0V when it's 0ºC (what you called arithmetical) and a gain error due to slope error on the LM35 and reference voltage error (what you called geometrical). To correct for both, the LM35 and the ADC/REF errors you need an external thermometer, not just reading the voltage at the LM35. If you do so you will be only correcting for the ADC/REF errors and not the LM35 ones, which might or might not be good enough for your application.JS

author: Old Printer
author_rank: Frequent Contributor
timestamp: May 30, 2018, 03:03:01 pm
content: I am currently working on a project with the LM35 & an Arduino. The first link is from an engineer at TI and he gets into a method for using the entire voltage range of the ADC to get better accuracy. The second vid was next to it on a search, I have not watched it yet, but the title looked good. If you get something worked out please post a brief of your method.

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 30, 2018, 03:29:21 pm
content: JS: yes you did say two, sorry can't read(!)OLD Printer: excellent thank you. I'll watch those and will post if I ever get anywhere!

author: IDEngineer
author_rank: Super Contributor
timestamp: May 30, 2018, 04:33:45 pm
content: Quote from: PerranOak on May 29, 2018, 08:25:12 pmTo answer the specific question in the original post: Not very! (Accurate, that is.)I dug into this in some detail a while back, including opening a ticket with Microchip and covering it with their staff. As mentioned by others, the spec sheets for various PIC's show variations in these "references" of well over 5%. This applies to all of the voltage "references" on PIC's regardless of voltage (some PIC's have multiple "references" with different names, and some of those then divide down the voltage to offer yet further voltages). Many linear regulators are more accurate, and you can often use the positive supply rail as the internal reference by properly configuring the on-chip peripherals.There are a few, more recent PIC's that characterize the on-chip "references" at the factory and store calibration data in internal memory. Your firmware can read this calibration data to obtain better accuracy.The consensus among the heavy PIC users on Microchip's own forums is that the on-chip "references" are good for little more than detecting a low battery condition on portable equipment. I certainly wouldn't use one as any sort of A/D or other measurement reference, since you likely already have a 5% voltage regulator sitting right there and 2% voltage regulators are common, inexpensive, and pin compatible.Hope this helps!

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 30, 2018, 05:12:32 pm
content: Thank you.That's a shame because the voltage ref of 1.024V is ideal for the LM35 as it gives a simple one-to-one relationship … makes the maths easier!

author: Howardlong
author_rank: Super Contributor
timestamp: May 30, 2018, 05:55:22 pm
content: I agree, the band gap/FVRs on PICs are pretty dire.It’s not unknown for there to be other errors, not just tolerance, for example missing ADC codes if used as an ADC reference in the PIC16F161x, PIC16F153xx and several other newer devices for example, and even a device reset in certain contions on the PIC16F1508/9.The solution is to use an external Vref+ with something such as a TLV431. Frustratingly on some devices like the PIC16F161x, Vref+ is also shared with a programming pin. Doh!Edit: at least on most devices the FVR is significantly more stable than trying to use Vdd as Vref.

author: IDEngineer
author_rank: Super Contributor
timestamp: May 30, 2018, 06:43:00 pm
content: Quote from: Howardlong on May 30, 2018, 05:55:22 pmThis is specifically NOT true, unless you've found a FVR with better specs than I have (or the other folks on the Microchip forums have). As I said, the rule of thumb is, in order of increasing accuracy, 1) on-chip "references", then 2) standard (~5%) voltage regulator, then 3) precision (<2%) voltage regulator, and finally 4) standalone reference connected to the PIC's external reference pin, which can be had in almost any accuracy you're willing to pay for! (Including hand-trimming at assembly and periodic calibration over its lifetime.)

author: Howardlong
author_rank: Super Contributor
timestamp: May 30, 2018, 09:25:22 pm
content: Quote from: IDEngineer on May 30, 2018, 06:43:00 pmAccuacy != stability.

author: IDEngineer
author_rank: Super Contributor
timestamp: May 30, 2018, 11:42:24 pm
content: Quote from: Howardlong on May 30, 2018, 09:25:22 pmYou're correct, I misread what you typed. My mistake.If you determine that the on-chip references are more stable than the supply rail, you could combine them to gain the best of both worlds. At power up, use the supply rail as the A/D reference, measure the FVR, and derive a correction factor. (Could average many such conversions to minimize the effects of supply instability.) Then switch to using the FVR for measurements. Now you are insensitive to the FVR absolute (in)accuracy, while enjoying its supposed improved stability.Again, apologies for misreading your comment!

author: Howardlong
author_rank: Super Contributor
timestamp: May 31, 2018, 06:54:02 am
content: No worries!I first came across this when discounting the FVR for its accuracy problems, and choosing the ADC Vref=Vdd instead. Despite my best efforts, I simply couldn't get the ADC to give reasonably noise free results, typically with at least the 2 LSB of a 10 bit result being largely a random number. Switching to the FVR fixed that, despite its crap accuracy.You're right, if you use an accurate Vdd and use a sample average to derive the FVR's real voltage you can correct for this, depending on your application. In some cases, though, this might lead to missing or duplicate adjacent codes which may or may not be a problem in your application.

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 31, 2018, 01:01:47 pm
content: This is fascinating!I only started really because I wanted to practice using 7-seg displays but the accuracy and compensation question is intriguing. I particularly like the idea of a correction factor calculated on-the-fly.I must admit that using an external voltage ref seems like a "cheat" - I am mostly interesting in the programming. However, I will probably do this, at some time, for the experience though all those at 1.024V seem to be surface mount and they're only 1% accuracy! Voltage regs at 1% are only 90p.

author: Howardlong
author_rank: Super Contributor
timestamp: May 31, 2018, 02:26:33 pm
content: Does it have to be 1.024v?I don’t know your application, but could you use a TL431 for example, these are pennies even at B grade 0.5% in reasonable quantities. It’s also in TO92, but you may end up paying more over a SOT23 for example.I’m not sure about the retiscence over surface mount, if it’s for prototyping, I always keep a good stock of breakouts for this sort of thing.

author: IDEngineer
author_rank: Super Contributor
timestamp: May 31, 2018, 03:34:35 pm
content: Quote from: Howardlong on May 31, 2018, 02:26:33 pmTrue, but its accuracy is only as good as that of the resistors that set its output voltage, and a pair of 0.5% or better resistors may well cost more than the IC and they require even more real estate.That's why I really like the idea of factory characterization of on-chip references with the value recorded in readable memory. You get the on-chip stability with predictable accuracy, with zero extra components and zero extra PCB real estate. Sadly, this isn't offered in any of the MCU's we presently use. Maybe in the future....

author: IDEngineer
author_rank: Super Contributor
timestamp: May 31, 2018, 03:36:43 pm
content: Quote from: PerranOak on May 31, 2018, 01:01:47 pmYou can take that one step beyond my original suggestion, and maintain a running average during power-on rather than just averaging a few measurements at startup. It's basically the same code, just a simple architecture change.

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 31, 2018, 03:38:20 pm
content: Yes I see. This would help with the changes that temperature may make to the results.BTW is there any way to output the PIC voltage ref to a pin?

author: Howardlong
author_rank: Super Contributor
timestamp: May 31, 2018, 06:58:56 pm
content: Not directly with this device. There are two FVRs, one for the comparator & DAC, and the other for the ADC.You could figure out the first one somewhat by usng the DAC, but only a fraction of the voltage as it goes through a resistive divider.Some PICs have opamps that you could use as a buffered version of the FVR, particularly the PIC16F17xx series.

author: PerranOak
author_rank: Frequent Contributor
timestamp: May 31, 2018, 07:01:17 pm
content: OK cheers.