ADC block sets configures all pins to the ADC
Posted: Thu Jun 09, 2011 12:44 am
If I have the ADC block within my model and build it I see the following configuration bits:
The first 3 lines configure the AN pins to be used by the ADC or to by used as GPIO pins or be used for other peripherals. Why are these all being set to 0? Especially why is AD2 being configured as ADC inputs? Looking at the AD1CSSL only pin AN0 is actually being read, so why are the other pins being configured? Really I would expect only expect AD1PCFGH and AD1PCFGL set to 0xFFFF and 0xFFFE respectively in order to enable just AN0.
I'm using the Explorer 16 board with the dsPIC33fJ256GP710 onboard and was trying to diagnose why most of my AN* pins were sitting at 3.7V (at least pins AN0-AN4, AN8-10) which is when I ran into this. I know that RB15 is at least one of the pins causing this increased voltage as it's connected to the LCD on the e16 board. But this isn't the real issue as none of this should be a problem if the pins are correctly configured.
Code: Select all
AD1PCFGL = (0U);
AD2PCFGL = (0U);
AD1PCFGH = ((0U) & 65535);
/* S-Function "dsPIC_ADC" initialization Block: <Root>/ADC Input */
/* Initialise ADC converter */
/* 0 mean each 1 conversion */
#define NoSamplesADC 0
#define ADCSval 12
#define SAMCval (1 << 8)
#define OutFormatBitsval (0 << 8)
#define VoltRef (0 << 13)
/* Use internal counter Trigger, continuous simulatenous sampling */
AD1CON1 = 0x0004 | (7 << 5) | (0 << 10)| OutFormatBitsval;
AD1CON2 = 0x0400 | (NoSamplesADC << 2) | VoltRef;
AD1CSSL = (1 & 65535);
AD1CON3 = (ADCSval | SAMCval) & 0xff7f;
AD1CHS0 = 0x0000;
IPC2 = (IPC2 | (6 << 12)); /*Interrupt Priority : 6*/
_AD1IF = 0;
/* We set _ADIE = 1 in the main file if necessary*/
/* Clear Off Any Interrupt Due To Configuration */
/* Turn on ADC Module */
AD1CON1bits.ADON= 1;
I'm using the Explorer 16 board with the dsPIC33fJ256GP710 onboard and was trying to diagnose why most of my AN* pins were sitting at 3.7V (at least pins AN0-AN4, AN8-10) which is when I ran into this. I know that RB15 is at least one of the pins causing this increased voltage as it's connected to the LCD on the e16 board. But this isn't the real issue as none of this should be a problem if the pins are correctly configured.