ADC reading , Timer interrupt - dspic33ch128mp508

Status
Not open for further replies.

chaminda12001

New Member
Hi,

I am trying to read ADC channel 0 using Timer interrupt to trigger it. I am using dspic33ch128mp508 curiosity development board for anologue reading using potentiometer annologue channel 0. When I debug, I dont get any value on the Anlogue channel 0.
I am using MPLAB X IDE 5.10 for debugging. Here is my code. Any thoughts on this?

int main(void) {

TRISE = 0x0000;

adc_init();


PORTEbits.RE0 = 0;


T1CON =0;
TMR1 =0x0000;

T1CONbits.TCS = 0;
T1CONbits.TCKPS =0;
T1CONbits.TGATE = 0;
IFS0bits.T1IF = 0; //Timer interrupt flag
IFS5bits.ADCAN0IF =0;
IEC0bits.T1IE =0; //Interrupt enable
IPC22bits.ADCAN0IP =1;
IEC5bits.ADCAN0IE =1;
PR1 =0x0002;
ADCON1Lbits.ADON = 1;
T1CONbits.TON = 1; //Timer 1 T1CON enable


while(1);


}

void adc_init(){


TRISAbits.TRISA0=1;
ANSELAbits.ANSELA0=1;
ADCON3Hbits.CLKSEL0= 1; //FOSC clock selection
ADCON3Hbits.CLKSEL1 =0;
ADCON3Hbits.CLKDIV =0;
ADCON3Lbits.CNVCHSEL0 =1; // Channel selection 1
ADCON1Hbits.SHRRES =1; // 12 bit resolution
ADCON2Lbits.EIEN =0;
ADCON1Hbits.FORM =0; //Output format
ADMOD0Lbits.SIGN0 =0;


ADCON3Lbits.REFSEL =0; //ADC Reference voltage selection


ADCON3Hbits.SHREN =0;
ADCON5Hbits.WARMTIME = 0x2;


}

void __attribute__((interrupt, no_auto_psv)) _ADCAN0Interrupt(void)
{

i = ADCBUF0; // read conversion result
PORTEbits.RE0 = i;
_ADCAN0IF = 0; // clear interrupt flag

}
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…