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

18f4458 adc

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



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

18f4458 adc
PostPosted: Wed Jun 18, 2008 3:04 am     Reply with quote

hi is it possible to measure accurately 1.098 vdc +/- 1mv i have been trying
to read this voltage but when i display it on the lcd the last 2 digits are changing by as much as +/- 30mv. do i need to use an adc with 16bit resolution. i am injecting the dc voltage from a calibrated dc soure straight in to the pic and have decoupled it using 1uf.do i read the adc to quickly cap
Code:


#device ADC=12
#fuses HS, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 20000000)
#include <flex_lcd420.c>


void main()
{
float volts;
int16 adc_value;
setup_adc_ports(AN0_TO_AN4|VSS_VREF);         //VREF = 5.00
setup_adc(ADC_CLOCK_DIV_32|ADC_TAD_MUL_20);
do{
adc_value = read_adc();                   
 volts = (float)(adc_value * 5)/4095;
 printf(lcd_putc, "%3.3f\n", volts);               
 printf(LCD_PUTC,"adc %Ld",adc_value);
 }while(1);
}


many thanks Andrew
Ttelmah
Guest







PostPosted: Wed Jun 18, 2008 4:25 am     Reply with quote

First thing, get rid of 'VSS_VREF'. The supply voltage on the chip, _will_ be varying all the time, by a significant number of mV, as internal processing occurs. You will be 'lucky' to get 1% accuracy using the supply as a Vref.
Add an external 'bandgap' voltage reference, warranted to at least 0.02% accuracy, smooth it well, and ensure the grounding round it and the PIC is good (ground plane). Use a 4.096V ref by choice. The ADC will then read 1mV/step (read up on the design of the PIC ADC, and why the divisor _is_ 4096, not 4095).
Add a small amount of damping anyway, or put the chip to sleep for the actual ADC conversion (otherwise you _will_ pick up noise from the processor).
You then have a good chance of getting a believable 1mV resolution.

Best Wishes
morebudwiser



Joined: 17 Oct 2005
Posts: 26

View user's profile Send private message

PostPosted: Wed Jun 18, 2008 4:34 am     Reply with quote

thanks
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