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

PIC 16F684 and the A/D setup problems

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



Joined: 04 Feb 2005
Posts: 4

View user's profile Send private message

PIC 16F684 and the A/D setup problems
PostPosted: Sat Mar 18, 2006 7:18 am     Reply with quote

I have recently purchased the CCS compiler, but am having problems getting the A/D woking, the only result i get from the following setup is 0x3ff. i am using the latest compiler version 3.245

i have tried the examples in the user guide, and on the CCS web site to no avail as these get errors when compiled.

my system

PIC 16F684

AN0 = battery voltage resistor divider max voltage = 1.1volts = 4.5 battery voltage.

AN1 = VREF, using Zetex 1.22voltage reference chip
RC5 = VREF_ENABLE, this applies battery voltage to the VREF chip

my code

#device PIC16F684 ADC=10

setup_adc_ports(sAN0 | VSS_VREF) ;
setup_adc(ADC_CLOCK_INTERNAL) ;
set_adc_channel(sAN0) ;

OUTPUT_HIGH(VREF_EN) ; //enable vcc to vref chip via 1k resistor
delay_ms(2) ; //wait for voltages to stabilise

uiBatteryVoltage = read_adc() ;


voltage on AN0 pin is 0.6 volts (battery)
voltage on AN1 pin is 1.22volts (vref chip)

adc result (uiBatteryVoltage) will always be 0x3ff, should really be half this value...

SFR's are:

TRISA = 0x3f
ADCON0 = 0xc5
ADCON1 = 0x30
ANSEL = 0x01

ADRESL = 0xff
ADRESH = 0x03


i don't think i have missed anything out, any help with this would be appreciated.

thanks
theproff
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Mar 18, 2006 9:59 am     Reply with quote

Quote:
the only result i get from the following setup is 0x3ff
AN1 = VREF, using Zetex 1.22 voltage reference chip

Look in the 16F684 data sheet at this table on page 146 (in Acrobat reader):
Code:

TABLE 15-9: PIC16F684 A/D CONVERTER CHARACTERISTICS:

Param           Minimum
No.    Symbol   Value              Notes   

A20    Vref     2.2v

A20A   Vref     2.5v   Absolute minimum for 10-bit accuracy
theproff



Joined: 04 Feb 2005
Posts: 4

View user's profile Send private message

PostPosted: Sat Mar 18, 2006 5:49 pm     Reply with quote

PCM Programmer

Thanks for opening my eyes, how stupid am I
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