CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Vref selection

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

Vref selection
PostPosted: Tue Apr 18, 2017 8:53 pm     Reply with quote

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: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 19, 2017 5:13 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 19, 2017 6:56 am     Reply with quote

Thanks Jay for the quick reply Smile
I was thinking that the internal Vref is more accurate that the power suppy 5V.

Best wishes
Joe
temtronic



Joined: 01 Jul 2010
Posts: 9097
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Apr 19, 2017 7:32 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 19, 2017 3:32 pm     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Thu Apr 20, 2017 11:01 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Thu Apr 20, 2017 3:58 pm     Reply with quote

Thanks Ttelmah.

Will implement it and compare the results.

Best wishes
Joe
gjs_rsdi



Joined: 06 Feb 2006
Posts: 468
Location: Bali

View user's profile Send private message Send e-mail

PostPosted: Tue May 09, 2017 3:31 am     Reply with quote

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: 19215

View user's profile Send private message

PostPosted: Tue May 09, 2017 3:58 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Tue May 09, 2017 11:05 am     Reply with quote

Thank you for the advice Ttelmah.

Downloaded the file and started learning it.

Best wishes
Joe
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group