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 CCS Technical Support

Need help about ADC reference voltage

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



Joined: 26 Jul 2013
Posts: 23

View user's profile Send private message

Need help about ADC reference voltage
PostPosted: Tue Dec 02, 2014 12:17 am     Reply with quote

Hello !

I need to know how can we use 10-bit ADC with internal voltage reference on a PIC18F26K22 controller assuming VDD=5V and VSS=GND ? The CCS built in function description and the device header files are very different from each other I cannot get to a conclusion. Please someone give me a simple code that would serve best with the following specs, I am also confused about TAD and TACQ. I know how to read and manage the converted data I just want the setup part especially the FVR BUF2 setting so that reference is 4.096 V.

So here are the hardware specs :
VDD : 5V
VSS : GND
Controller : PIC18F26K22
Crystal : 20 MHz
ADC : 10 bit
Channel being used : CH0, CH1, CH2
Maximum voltage to be sensed on any adc channel : 3 V

here's the datasheet :
http://ww1.microchip.com/downloads/en/DeviceDoc/41412F.pdf

Can anyone help me about this ?

Oh and one more thing, I also have with me the LP2950CZ-3.0 Voltage Regulator (from Texas Instruments) but one piece gives 2.998 V output and the other 2.985 V so do you guys think it would be accurate as a reference or would the internal reference be more accurate ? Here's the device datasheet : http://www.ti.com/lit/ds/symlink/lp2950-n.pdf
_________________
PCWHD Compiler v4.124
ICD U-64 Hardware Rev 2 & 3
CCSLOAD 4.053
temtronic



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

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 6:43 am     Reply with quote

re: the vreg... according to the datasheet they are within the design specs.
You have to remember that the DMM you're measuring them with is rdg+-1 digit..so... 2.998 could really be 2.997 AND 2.995 could be 2.996. a true difference of only .001. Also vregs need a minimum load and cap on them as well as proper input power(no EMI, resonaably regulated as well).
It is always better to use a discrete V reference device.The small cost and board space is far out weighed by the 'rock stable' reference and NO need to 'calibrate the system'.

You also need to be concerned about board layout, proper filtering,etc. when using ANY ADC over 8 bits. Noise WILL creep in unless proper analog layout is done.I've seen several PCbs where an 8bit ADC would outperform a 10 or 12 bit ADC as several bits got 'lost' in the noisey PCb.

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19491

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 8:15 am     Reply with quote

Tad, is the clock cycle of the ADC. Each reading takes a number of these cycles (11+2). Tacq, is the time it takes the internal capacitor to charge to be within half a bit of the actual incoming voltage.

You connect the voltage to the capacitor, when you select the ADC channel. The capacitor then starts to charge from wherever it may be, 'to' this voltage. Tacq, defines the 'worst case' time needed, for it to charge from (say) the low rail to the high rail, and get within the 'sample step' (half bit) of the right value.
The 'acquisition' time.
Then you trigger the ADC conversion, and the capacitor is disconnected from the external voltage and the conversion takes place on the voltage stored. Taking several Tad times to complete.

Now on older ADC's, the times were completely separate. So you selected the channel, delayed for some uSec (Tacq), then triggered the conversion. However on later ADC's like this you can program the ADC to automatically wait after trigger, for the acquisition to take place. You can program how many Tad cycles the ADC will wait after you set the 'GO' bit, before it disconnects the holding capacitor. 'Tacqt'. So if with your voltage source, you need an acquisition time of 7.5uSec, and you are running with Tad = 1uSec (1MHz ADC clock), you can program the ADC to wait for 8 clock cycles when started, before actually performing the conversion. So you include 'ADC_TAD_MUL_8' in your ADC setup, and can then just select a channel, and convert immediately. The ADC will pause for 8*Tad (so 8uSec), then perform the actual conversion (11uSec), then discharge for 2uSec, and finish.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 9:27 am     Reply with quote

Actually he said 2.985 not 2.995 Very Happy

I don't know if this is still the case (I reported it to CCS back in version 4.114 which is what I was using at the time). This was for the 18f14k22 which is part of the same family - CCS was not setting up the bits correctly to enable the internal reference. Here are the comments from my code at the time:

Code:
     // setup AD converter
     // AN2 (RA2) = ambient temp, AN10 (RA10)=htr temp
     // NOTE: the setup_adc_ports clears my selection of the Vref source
     //       so it needs to be done before I write to ADCON1.
     // => If we define VSS_VFVR using the same format as the rest of the ref
     //    config info in the .h file (0x800) then setup_adc_ports() does select
     //    the internal reference correctly and we only have to write to the
     //    VREFCON0 register to enable the FVR and select the 1x multiplier.
setup_adc_ports(AIR_PORT | HTR_PORT,VSS_VFVR); 
setup_adc(ADC_CLOCK_DIV_16);
         
     // Have to enable the internal FVR and set to 1x
VREFCON0 = 0x90; // FVR enabled, 1x (1.024v)  (pg 245)
         
     //  VREFCON1 = 0x00; // DAC is disabled  (pg 246)
     //  VREFCON2 = 0x00; // DAC output disabled (pg 246)
     //  ADCON1   = 0x08; // pos vref from FVR, neg vref from Vss (pg 214,207)
     //  ADCON2   = 0x95; // Rt. justify, TAD4,Fosc/16   (pg 215)
 
     // setup_adc_ports(AIR_PORT | HTR_PORT); 
     // AN2 (RA2) = ambient temp, AN10 (RA10)=htr temp

     // check for current settings in eeprom - if first byte of eeprom is not
     // CHK_BYTE then copy defaults to eeprom else read settings from eeprom
     // into the settings structure (over write defaults).


Note that the page numbers referenced are from the pdf version of the 18f14k22 datasheet I was using.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
temtronic



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

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 9:36 am     Reply with quote

sigh...guess I gotta get trifocals.....
still a precision vref is best.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19491

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 12:33 pm     Reply with quote

Very much so.
Thing is that the supply, even if it is a 1% quoted supply, will have the ripple from the processor operations at the chip.
gpsmikey



Joined: 16 Nov 2010
Posts: 588
Location: Kirkland, WA

View user's profile Send private message

PostPosted: Tue Dec 02, 2014 12:53 pm     Reply with quote

You also need to make sure that GND=GND=GND - make sure the chip (both the processor and vref if using external vref) have good grounds not a thin trace that snakes around before going to the chip or you will not get accurate readings (and make sure you bypass the processor etc. with a ceramic cap close to the power connections to the chip). In many applications, a precise measurement (repeatable) is more important than an accurate measurement (has the analog voltage changed from previous readings). That is something to consider as well.

mikey
_________________
mikey
-- you can't have too many gadgets or too much disk space !
old engineering saying: 1+1 = 3 for sufficiently large values of 1 or small values of 3
muhibraza1



Joined: 26 Jul 2013
Posts: 23

View user's profile Send private message

PostPosted: Thu Dec 04, 2014 12:10 am     Reply with quote

brother temtronic what do you mean by vreg and discrete V reference device ?

Texas instruments have said that LP2950CZ-3.0 can be used as regulator or reference both.

see : http://j.mp/1zTgmKP
_________________
PCWHD Compiler v4.124
ICD U-64 Hardware Rev 2 & 3
CCSLOAD 4.053
muhibraza1



Joined: 26 Jul 2013
Posts: 23

View user's profile Send private message

PostPosted: Thu Dec 04, 2014 12:13 am     Reply with quote

@temtronic

Quote:
It is always better to use a discrete V reference device.The small cost and board space is far out weighed by the 'rock stable' reference and NO need to 'calibrate the system'.


can you name a few part numbers as such ?
_________________
PCWHD Compiler v4.124
ICD U-64 Hardware Rev 2 & 3
CCSLOAD 4.053
temtronic



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

View user's profile Send private message

PostPosted: Thu Dec 04, 2014 6:37 am     Reply with quote

Vreg/Vref .. the voltage reference device used for the ADC 'vref' input. That TI device can be used to either power the PIC or used as a 'reference' but has a 0.5% accuracy. To get the best ADC readings a 'voltage reference' device should be used. They will NOT supply enough current to power the PIC. NOT designed for 'power supply' use but will be very,very accurate, say 0.01 or 0.001%. NOT cheap but if you need accurate ADC readings you MUST use a super accurate vref.

Just google 'precision voltage reference', you'll get a lot of hits. First hit for me was MAX6126, good for .02% ! Cost is just over $7 USD !!

As others have said , it's always best to use an external vref NOT the PIC's Vdd 'ref' as it's NOT stable or accurate. OK for 8 bit mode in non critical systems....consider it 'hobbiest' quality.

Jay
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