View previous topic :: View next topic |
Author |
Message |
theproff
Joined: 04 Feb 2005 Posts: 4
|
PIC 16F684 and the A/D setup problems |
Posted: Sat Mar 18, 2006 7:18 am |
|
|
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
|
|
Posted: Sat Mar 18, 2006 9:59 am |
|
|
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
|
|
Posted: Sat Mar 18, 2006 5:49 pm |
|
|
PCM Programmer
Thanks for opening my eyes, how stupid am I |
|
|
|