View previous topic :: View next topic |
Author |
Message |
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
Vref selection |
Posted: Tue Apr 18, 2017 8:53 pm |
|
|
Hi
CCS PCH C Compiler, Version 5.059, xxxxx
PIC18F26K22 & PIC18F26K22
For analog readings I am using VSS_VDD but I would like to have a better
reading accuracy.
I made a search on the forum for internal+Vref and read I think what is relevant still I have a few questions
1.
PIC18FXXK22
Data sheet:
Page 297
The ADC voltage reference is software selectable to either VDD or a voltage applied to the external reference pins.
Page 298
The positive voltage reference can be:
• VDD
• the fixed voltage reference (FVR BUF2)
• an external voltage source (VREF+)
Page 297 is wrong?
2.
Page 304
FVR BUF2 (1.024V/2.048V/2.096V Volt Fixed Voltage Reference)(2)
In the 18F46K22 header file #define VREF_4v096 0xB0
I suppose the above 2.096 should be 4.096. It is correct?
3.
After
Code: | setup_vref(VREF_ON|VREF_ADC_4v096); |
I need also the below?
Code: | setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4, VSS_FVR); |
Or enough
Code: | setup_adc_ports(sAN0|sAN1|sAN2|sAN3|sAN4); |
The board power supply is 5V. Can I expect improvement in the ADC reading using internal Vref 4.096 over the Vref 5V of the power supply?
The analog ground is connected to the top and bottom ground pour, I have 0.1uFcapacitors on all the analog inputs close to the pin,
0.1uF and 100uF on the power supply input
External clock 16MHz, internal 64MHz (PLL enabled)
The reason for the questions is that I want to make a new board with some changes and to include the analog improvements if possible.
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Apr 19, 2017 5:13 am |
|
|
quick reply...
The BEST possible Vref for the ADC will be an external V reference device, say 4.096, volts. It will BE 4.096 volt unlike the internal Vref that can be anywhere from 3.768 to 4.383 ! Now, I didn't see how 'stable' the value is, but that's quite a range and with my luck PIC #1 will be 3.7 and PIC#2 will be 4.38 making it useless without individual calibration
Any ADC over 8 bits and needing good accurate, reliable readings needs a proper Vref device.
jay |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Wed Apr 19, 2017 6:56 am |
|
|
Thanks Jay for the quick reply
I was thinking that the internal Vref is more accurate that the power suppy 5V.
Best wishes
Joe |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9245 Location: Greensville,Ontario
|
|
Posted: Wed Apr 19, 2017 7:32 am |
|
|
It 'should' be but the variation is huge ...
The other option (should always be done..) is to take an 'Olympic average' of the signal. 10 readings, toss high and low, average the 8 (simple shift). It's fast and good for most applications. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Wed Apr 19, 2017 3:32 pm |
|
|
Thanks again Jay
Am doing averaging of 16 readings, shift.
I need 10 bit resolution for some sensors so I will start checking out Vref chips
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Thu Apr 20, 2017 11:01 am |
|
|
Definitely needed for 10bit.
The internal Vref, is potentially great for something like a battery powered circuit, where the supply can vary by a large amount. However for anything requiring reasonable accuracy an external Vref is needed.
The point about Olympic averaging, is it gets rid of 'unexpected' results better than a straight average.
So (for instance):
Code: |
int16 average(void)
{
//assume the ADC is already selected to the channel to average
int16 sum=8; //preload with half a step
int16 max=0;
int16 min=1024;
int16 temp;
int8 ctr;
for (ctr=0;ctr<18;ctr++)
{
delay_us(10); //set to suit your ADC Tacq
temp=read_adc();
sum+=temp;
if (temp>max)
max=temp;
if (temp<min)
min=temp;
} //now have the sum of 18 readings
sum-=max;
sum-=min; //minus the largest and smallest readings
return sum/16;
}
|
The '8' gives after the division, effectively 0.5 added.
So you get the average of the 16 'middle' readings out of 18. |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Thu Apr 20, 2017 3:58 pm |
|
|
Thanks Ttelmah.
Will implement it and compare the results.
Best wishes
Joe |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Tue May 09, 2017 3:31 am |
|
|
First I am aware that maybe the post is not CCS compiler related, so if the forum is not the place to deal with the subject, my apology.
After reading many Vref chips datasheet I am more confused.
Wide range of accuracy, wide range of prices.
Is 0.1% initial accuracy with 4.096 reference is OK for 10 bit resolution?
I am reading noises on the general ground of about 20 mA, it is an obstacle also I suppose.
Is the MCP1501-40 with 0.08% accuracy will do the job?
Using the VDD as reference, reading 10 bit, using just 8 bit I had reasonable results on my past projects, but I would like to have 10 bit accuracy.
Best wishes
Joe |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19546
|
|
Posted: Tue May 09, 2017 3:58 am |
|
|
0.1%, is is almost exactly 10bit. 1/1024 = 0.0976%.
However 'caveat'. You will not achieve 10bit, unless the overall smoothing is good, and the tracking design careful.
In fact if you are careful in this, you can actually exceed 10bit, using oversampling & interpolation:
<www.atmel.com/images/doc8003.pdf> |
|
|
gjs_rsdi
Joined: 06 Feb 2006 Posts: 468 Location: Bali
|
|
Posted: Tue May 09, 2017 11:05 am |
|
|
Thank you for the advice Ttelmah.
Downloaded the file and started learning it.
Best wishes
Joe |
|
|
|