chaminda12001
Newbie level 5
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?
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?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 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 }