PIC24FV16KM204 ADC is not working
I am planning some projects at home. After some research I have chosen the PIC family micros for my projects.
In my first project I want to read 8 AD signals. The signals are connected on AN0, AN1, AN4, AN5, AN6, AN7, AN11 and AN18. I have chosen the PIC24FV16KM204 for this project, because I need many PWM channels. The controller runs with the internal RC oscillator at 32MHz. The clock runs fine, because timer1 ISR is configured to generate a 1ms tick, which drives a little time slice system. My idea is to initialize the ADC as free running ADC with auto scan mode, so that the 8 AD channels are scanned consecutively. When I need an AD value I want to read the last converted value in the ADC1BUFx register. In the cyclic function I read the ADC1BUF0 register and activate a LED to check if the ADC is working. But for some reason, the LED does not change its state.
I checked the datasheet and the register initialization (which I think fits my requirements) is shown below. Does anyone have a hint, why the ADC is not working here?
ANSA = PORT_ANSA_INIT; /* #define PORT_ANSA_INIT 0x0003 */
ANSB = PORT_ANSB_INIT; /* #define PORT_ANSB_INIT 0x204C */
ANSC = PORT_ANSC_INIT; /* #define PORT_ANSC_INIT 0x0003 */
AD1CON1 = ADC_AD1CON1_INIT; /* #define ADC_AD1CON1_INIT 0x2474 */
AD1CON2 = ADC_AD1CON2_INIT; /* #define ADC_AD1CON2_INIT 0x0C00 */
AD1CON3 = ADC_AD1CON3_INIT; /* #define ADC_AD1CON3_INIT 0x1602 */
AD1CON5 = ADC_AD1CON5_INIT; /* #define ADC_AD1CON5_INIT 0x9000 */
AD1CSSH = ADC_AD1CSSH_INIT; /* #define ADC_AD1CSSH_INIT 0x0004 */
AD1CSSL = ADC_AD1CSSL_INIT; /* #define ADC_AD1CSSL_INIT 0x08F3 */
AD1CON1bits.ADON = 1; /* turn ADC ON */
TRISCbits.TRISC5 = 0; /* Set debug port as output */
if (ADC1BUF0 < 1000) /* If AD value is < 1000 */
LATCbits.LATC5 = RESET; /* Deactivate the LED */
LATCbits.LATC5 = SET; /* else activate the LED */
post edited by PICStarter - 2020/01/22 12:07:39