PDA

View Full Version : ADC values above 4095 for 12 bit ADC



longpole001
- 31st January 2015, 09:27
seeing some readings when doing ADC on a channel giving a dec value 5534, 5144, ect when using ADCIN

have defines set to 12 bit

the adc channel is grounded via 26k resistor for testing


problem is i cant see why the reading is there at such a high value , and the value should not exceed 4095

any thoughts on why this may be happening ?????????




cheers


sheldon



DEFINE OSC 32 ' Timing referance for pause , pauseus commands
DEFINE ADC_BITS 12 ' Number of bits in ADCIN result - Required for adcin command



ADCON1 = %00100000 ' bit 7-6 = TRIGSEL 11= triger from RTCC, 10 = trigger from timer1 ,01 = trigger from CTMU, 00= trigger from ECCP2
' Bit 5-4 - VCFG+ 11= Internal VREF+(4.096v) ,10= Internal VREF+ (2.048v) 01=External VREF+ ,00= AVDD
' Bit3 - VNCFG- 1= External Vref- , 0= AVSS Vref/A ,
' Bit 2-0 = Analoge Neg Ch Select ( Differential measurement )
' 111 = AN6, 110 = AN5, 101 = AN4,100 = AN3,011 = AN2, 010 = AN1, 001 = AN0,000 = AVSS,

ADCON2 = %10010010 ' bit 7 = 1 ADFM ( ADRESH, ADRESL - right justify ) , Bit6 n/a ,
' Bits 5-3 ACQT ( acquision time ) 111 = 20TAD ,110=16TAD,101-12TAD,100=8TAD,011=6TAD,010=4TAD,001=2TAD,000=0TAD
' Bit 2-0 ADCS ( AD clock sel) x11 =FRC , 110=Fosc/64,101= FOSC/16 ,100=FOSC/4 ,010=FOSC/32 ,001=FOSC/8, 000=FOSC/2
' Note: define ADCIN clock and define ADcin sample overide this setting





ANCON2.1 = 1 ' Set PortG.3 = 1 - Select portG.3 to Analog - AN17 - AD touch switch input 1R-TX mode
TRISG.3 = 1 ' Set TRISG.3 = 1 - Select portG.3 to Input - AN17 - AD touch switch input 1R-TX mode
ADCON0 = %01000111 ' Select the A/D channel - AN17 turn on a/d


adcin 17,value1 ' do ADC reading on AN17 - touch switch input
HSEROUT2 ["value1 = ",dec4 value1,13,10]

ADCON0 = %01000100 ' Select the A/D channel - AN17 and turn off A/D module











value1 = 0003
value1 = 0004
value1 = 0002
value1 = 0011
value1 = 0005
value1 = 0003
value1 = 0004
value1 = 0004
value1 = 0005
value1 = 0006
value1 = 0004
value1 = 0003
value1 = 0005
value1 = 0004
value1 = 0004
value1 = 0004
value1 = 0003
value1 = 0005
value1 = 0002
value1 = 0002
value1 = 0005
value1 = 0005
value1 = 5535
value1 = 5525
value1 = 0004
value1 = 0008
value1 = 0002
value1 = 0001
value1 = 0004
value1 = 0002
value1 = 5534
value1 = 5532
value1 = 0005
value1 = 0077
value1 = 5529
value1 = 0004
value1 = 0008
value1 = 0020
value1 = 5524
value1 = 5229
value1 = 0025
value1 = 0057
value1 = 0002
value1 = 5283

longpole001
- 31st January 2015, 10:08
I think it may be a hardware problem with that ad channel , as testing other channels i dont have the problem

pedja089
- 31st January 2015, 10:17
You didn't tell what PIC you use. It can make big difference...
For example PIC18F87K22 have differential inputs, and negative results are two’s complement of result. So for -1 = $FFFF, -2 = $FFFE etc.
You can use SDEC to get correct result.
Or you can use this:


ADCIN 17,value1 'I'm not sure how ADCIN in handles negative numbers... So maybe manual reading of ADRES registers are better solution
IF value1.1 = 1 THEN
Sign="-"
ELSE
Sign=" "
ENDIF
value1=ABS(value1)
HSEROUT2 ["value1 = ",Sign, dec4 value1,13,10]

longpole001
- 31st January 2015, 21:56
thats a good thought about a negative input , and clearly the value for negative flag is being set

the 18f67k22 , which i am using, Has AN0-AN6 as negative inputs , for differential input , selected by ADCON1- BITS 2-0 , where 00 = AVSS. and they are not being set

AN4 is used for is used for ad input every 20 secs , but at no time is it set to a negative ref , by adcon1

AD17 is part of comparitor 3 input , which is set to 0 so that should not be affecting it

its got be stumped what setting maybe forcing the neg value ,

and it feel like i have a setting wrong some where for an17

i have moved to an7 to continue sorting out the CTMU for touch switch service , which has helped get a more consistent reading to sort out the touch function

the CTMU is nice bit of the PIC chip "IF" you can work your way around all the possible settings including the interrupts ,

i also note that the DT'S INts_18_k22.bas does not support the CTMU intrerupt for external pin triggering , and will need to be added or do it via a manual clearing of interupts , but thats for later

pedja089
- 31st January 2015, 22:04
Offset can be from internal differential amp or multiplexers. Inverting input is tied to GND when used in single input mode. You connect non inverting input also to GND. So any input offset or positive offset in inverting input multiplexer can produce small negative result, which look as large positive number.

longpole001
- 1st February 2015, 03:06
yep i cant see where it coming from , but it was not hard to use another a/d channel , but its something that i need to look at closer

Acetronics2
- 1st February 2015, 12:23
010=4TAD

may be too short a time to get full conversion ???

and especially @ 32 Mhz !!! ( have a look to datasheet ... )

Alain

longpole001
- 1st February 2015, 22:24
looking at table 23.1 4 tad should be ok at 32 mhz, using the setting of Fosc/32 for ADCS ???


7700
7701
7702