Author Topic: PIC voltage ref  (Read 7437 times)

0 Members and 1 Guest are viewing this topic.

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
PIC voltage ref
« on: May 29, 2018, 08:25:12 pm »
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.
You can release yourself but the only way to go is down!
RJD
 

Offline jeduffy

  • Contributor
  • Posts: 28
  • Country: us
Re: PIC voltage ref
« Reply #1 on: May 29, 2018, 11:18:55 pm »
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.
 

Offline JS

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ar
Re: PIC voltage ref
« Reply #2 on: May 30, 2018, 03:45:00 am »
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
If I don't know how it works, I prefer not to turn it on.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
Re: PIC voltage ref
« Reply #3 on: May 30, 2018, 09:16:55 am »
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?
You can release yourself but the only way to go is down!
RJD
 

Offline JS

  • Frequent Contributor
  • **
  • Posts: 947
  • Country: ar
Re: PIC voltage ref
« Reply #4 on: May 30, 2018, 02:55:06 pm »
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
If I don't know how it works, I prefer not to turn it on.
 

Offline Old Printer

  • Frequent Contributor
  • **
  • Posts: 832
  • Country: us
Re: PIC voltage ref
« Reply #5 on: May 30, 2018, 03:03:01 pm »
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.



 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
Re: PIC voltage ref
« Reply #6 on: May 30, 2018, 03:29:21 pm »
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!
You can release yourself but the only way to go is down!
RJD
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1982
  • Country: us
Re: PIC voltage ref
« Reply #7 on: May 30, 2018, 04:33:45 pm »
How accurate are the voltage reference in PICs.
To 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!
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
Re: PIC voltage ref
« Reply #8 on: May 30, 2018, 05:12:32 pm »
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!
You can release yourself but the only way to go is down!
RJD
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5528
  • Country: gb
Re: PIC voltage ref
« Reply #9 on: May 30, 2018, 05:55:22 pm »
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.
« Last Edit: May 30, 2018, 06:00:56 pm by Howardlong »
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1982
  • Country: us
Re: PIC voltage ref
« Reply #10 on: May 30, 2018, 06:43:00 pm »
Edit: at least on most devices the FVR is significantly more stable than trying to use Vdd as Vref.
This 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.)
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5528
  • Country: gb
Re: PIC voltage ref
« Reply #11 on: May 30, 2018, 09:25:22 pm »
Edit: at least on most devices the FVR is significantly more stable than trying to use Vdd as Vref.
This 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.)

Accuacy != stability.
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1982
  • Country: us
Re: PIC voltage ref
« Reply #12 on: May 30, 2018, 11:42:24 pm »
Accuacy != stability.
You'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!
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5528
  • Country: gb
Re: PIC voltage ref
« Reply #13 on: May 31, 2018, 06:54:02 am »
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.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
Re: PIC voltage ref
« Reply #14 on: May 31, 2018, 01:01:47 pm »
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.
You can release yourself but the only way to go is down!
RJD
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5528
  • Country: gb
Re: PIC voltage ref
« Reply #15 on: May 31, 2018, 02:26:33 pm »
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.
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1982
  • Country: us
Re: PIC voltage ref
« Reply #16 on: May 31, 2018, 03:34:35 pm »
...use a TL431 for example, these are pennies even at B grade 0.5% in reasonable quantities.
True, 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....
 

Offline IDEngineer

  • Super Contributor
  • ***
  • Posts: 1982
  • Country: us
Re: PIC voltage ref
« Reply #17 on: May 31, 2018, 03:36:43 pm »
...the accuracy and compensation question is intriguing. I particularly like the idea of a correction factor calculated on-the-fly.
You 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.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
Re: PIC voltage ref
« Reply #18 on: May 31, 2018, 03:38:20 pm »
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?
« Last Edit: May 31, 2018, 04:47:40 pm by PerranOak »
You can release yourself but the only way to go is down!
RJD
 

Offline Howardlong

  • Super Contributor
  • ***
  • Posts: 5528
  • Country: gb
Re: PIC voltage ref
« Reply #19 on: May 31, 2018, 06:58:56 pm »
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.
 

Offline PerranOakTopic starter

  • Frequent Contributor
  • **
  • Posts: 581
  • Country: gb
Re: PIC voltage ref
« Reply #20 on: May 31, 2018, 07:01:17 pm »
OK cheers.
You can release yourself but the only way to go is down!
RJD
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->