I have a problem with my code; My aim is to create a code that should take 8000 - 10000 value per second from ADC. Now i wrote a test code to configure the ADC, but according to my calculation ADC Time for Conversion shoul be :
* Tad=Tcy*(adcs+1)=(1/40)*4 = 1.6us
* Tc = 14 * 1.6 = 22.4 us
, but in MPLAB when i use StopWatch i see that 1 conversion take nearly 5 ms.
Configuration :
DSPIC33FJ128MC802
FRC + PLL -> ~ 80 MHz
FCY 40 MHz
Function for ADC Configuration
void adc_init(){
AD1CON1bits.ADON=0;
AD1CON1bits.AD12B = 1;
AD1CON1bits.FORM = 0;
AD1CON1bits.SSRC = 0; //
AD1CON1bits.ASAM = 0;
AD1CON2bits.CSCNA = 1;
AD1CON2bits.CHPS = 0;
AD1CON2bits.SMPI = 0;
AD1CON3bits.ADRC = 0;
AD1CON3bits.ADCS = 63;
AD1CSSLbits.CSS3 = 1;
AD1PCFGL=0xFFFF;
AD1PCFGLbits.PCFG3 = 0;
IPC3bits.AD1IP = 6;
AD1CON1bits.ADON = 1; }
Function for Read ADC Value
unsigned int read_adc_value(void){
AD1CON1bits.SAMP = 1; // start
//while(!AD1CON1bits.SAMP);
__delay_us(10);
AD1CON1bits.SAMP = 0; // stop
while(!AD1CON1bits.DONE);
return ADCBUF0;}