Status
Not open for further replies.

#### 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.

Code:
#include<p18f4620.h>
#pragma config OSC=HSPLL,WDT=OFF,DEBUG=ON,LVP=OFF,IESO=OFF
void main(void)
TRISD=0;
CMCON=0x07;
,			0x0C
);
while(1)
{
_asm NOP _endasm
_asm NOP _endasm
asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
_asm NOP _endasm
asm NOP _endasm
_asm NOP _endasm
}
}

Last edited:

#### Wond3rboy

##### Member
Atleast someone can reply with something!

#### Pommie

##### Well-Known Member
You may have a 4MHz crystal but you have the PLL selected and so your pic is running at 16MHz. You are also setting ADCON1 to 0x0c which makes AN11 a digital pin. To use AN11 all the other analogue pins cannot be used as digital (except AN12). I would switch to a different pin and just setup the registers as needed (there's only 3!). I never know what the libraries do and so don't use them.

Mike.

#### Wond3rboy

##### Member
I changed the code and used every thing that i could think of.I was first using AN0 and Vref and it didnt work out so i changed it to AN11.I just edited the program i had posted here and did not cop paste it.The problem is that in C18 the pins AN3,AN2 dont respond even as digital inputs.I tried assembly and they work fine.I think now i will write code in C18 using manual bit operations rather than using the library.I used the library so that i could import it to my 4620 form my 18f1320 since both use the same set of library functions...I have been going at it like crazy for the past two days.I have checked all my code on proteus and it works like a charm.I think there is something wrong with my compiler.Will reinstall it and wish it works then but it doesnt cause any problems with other programs.

About the acquisition time ..the TAD is set from FOSC and not from the divider so i have chosen it by considering 4MHZ.Am i supposed to consider the TAD after PLL?

#### Pommie

##### Well-Known Member
This is just of the top of my head so may be wrong but should work for AN0 to AN4.

Code:
int ReadADC(unsigned char chan){
}

Edit, just noticed you're using the LF and so tad should be osc/32. I changed the code.

Mike.

Last edited:
Status
Not open for further replies.