hi guys , in the process of porting code to 18F67K22 and need some input on the ADC setup for AN4 input ,
The code worked prior to porting to the chip so its goto be a register / setting not quite right , so if anyone can advise
The adc setup of AN4 is shown , for what i think is correct for all the other registers that may effect the input pin.
at the moment i get no reading at all
the osc is set to 32mhz internal
a Voltage divider resistor is on AN4 input
AVDD = 3.3v
AVSS = GND
Regards
Sheldon
The code worked prior to porting to the chip so its goto be a register / setting not quite right , so if anyone can advise
The adc setup of AN4 is shown , for what i think is correct for all the other registers that may effect the input pin.
at the moment i get no reading at all
the osc is set to 32mhz internal
a Voltage divider resistor is on AN4 input
AVDD = 3.3v
AVSS = GND
Regards
Sheldon
Code:
HLVDCON = $00 'Turn off HIGH /LOW Voltage Detect Module
T1CON = %01110100 ' Timer 1 ,bit7-6 = TMR1 CLK source 00 = Instuction Clk(Fosc/4),01 =sys clk,10=ext clk,11=cap sense osc
' bit5-4 = TMR1 prescale 11= 1:8 ,bit3=0 LP off,bit2=1 no sync ext CLK ,bit1= 0 n/a,Bit0=0 Timer 1 on/off
T1GCON = %00000000 ' Timer 1 Gate Control bit7 0= counts regardless of gate 1 = gates in use , bit6 gate active when 1= High ,0=low
' bit5 0= toggle mode diabled 1= enabled bit4 single pulse mode 1- en 0= dis, bit 2 -status bit,1-0 - gate source sel
T3GCON = $00 ' Timer 3 Gate disable
DEFINE OSC 32 ' Timing referance for pause , pauseus commands
DEFINE ADC_BITS 12 ' Number of bits in ADCIN result - Required for adcin command
DEFINE ADC_CLOCK 5 ' fosc/32 0.8uS @ 32Mhz
DEFINE ADC_SAMPLEUS 20 ' ADC sampling time in microseconds - Required for adcin command
' ------- Setup port A Variables & directions ----------
ANCON0.0 = 0 ' Set PortA:0 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL0
ANCON0.1 = 0 ' Set PortA:1 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL1
ANCON0.2 = 0 ' Set PortA:2 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL2
ANCON0.3 = 0 ' Set PortA:3 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL3
ANCON0.4 = 1 ' Set PortA:5 Analog / Digital allocation - 0 = digital ,1 analog - ANSEL4 Set RA5 (AN4/ ANSEL4) to be analog input for V-Mon
TRISA = %00100000 ' setup Port A input=1,output=0 for I/O pins , set input for RA5
PORTA = %00100000 ' Clear Outputs
' ------------ADC Settings , routines and Varaiables ----------------
' note: ADCON0 - channel selection done in routines using the required channel
ADCON1 = %00000000 ' 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 = %10101010 ' 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,101=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
Value Var Word ' ADC varable for result
'-------------------------------------------------------
Get_volts :
ADCON0 = %00010001 ' bit 7 -N/A , Bit 6-2 = ADC chan Sel /Tempature output /FVR output = AN4 sel = 00100 ,
' Bit 1 - Go/_done status flag - 1 = Go do ADC / 0 = Done ADC , Bit 0 = Enable ADC = 1 / 0 = Disable ADC
ADCIN 4 ,Value ' Leave out for Rev 2 of 16F1947 - Read PortA.5 value into variable , this applies the fixed voltage ref (via ADCON0,ADCON1,FVRCON)
write $10, Value.HighByte ' debug
write$11, Value.LowByte ' debug
return