Wond3rboy
Member
Hi i was trying to work out the ADC of the 18LF4620.I am currently using it with a supply voltage of 5V.So i have been treating it like a regular PIC.I am getting problems in getting its ADC working.Here is the code:
The Acquisition comes to about 2.4us since i am using a 10k pot but since that is less than 2 TAD so i am using NOP's to produce the required acquisition time(Is it correct?).I went through the data sheet and found that the 18(L)F4620 has got comparators..which i think are causing the problem.Or are they automatically turned off when i open the ADC?.The external oscillator is 4MHz.
The Acquisition comes to about 2.4us since i am using a 10k pot but since that is less than 2 TAD so i am using NOP's to produce the required acquisition time(Is it correct?).I went through the data sheet and found that the 18(L)F4620 has got comparators..which i think are causing the problem.Or are they automatically turned off when i open the ADC?.The external oscillator is 4MHz.
Code:
#include<p18f4620.h>
#pragma config OSC=HSPLL,WDT=OFF,DEBUG=ON,LVP=OFF,IESO=OFF
#include<adc.h>
void main(void)
{ unsigned int adcdata;
TRISD=0;
CMCON=0x07;
ADCON1=0x0C;
OpenADC(ADC_FOSC_8 &
ADC_RIGHT_JUST &
ADC_0_TAD ,
ADC_CH11 &
ADC_INT_OFF &
ADC_VREFPLUS_VDD
, 0x0C
);
while(1)
{
SetChanADC( ADC_CH11 );
_asm NOP _endasm
_asm NOP _endasm
asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
asm NOP _endasm
_asm NOP _endasm
ConvertADC();
while(BusyADC());
adcdata=ReadADC();
LATD=(adcdata>>2);
}
}
Last edited: