This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Trouble reading from two sensors through Stellaris Launchpad.

I have been working to read a pair of sensors, concurrently or not, and am trying to use different ADCs for each sensor.  However, right now, the first sensor read through ADC0 is reading correctly, as far as I can tell, but the second, read through ADC1, is effected by the output of the first sensor.  I've tried all channel and ADC combinations and found that some channels have less effect from the first sensor, but changing ADCs makes no difference.

I get the same results when using the code from this question: http://e2e.ti.com/support/microcontrollers/stellaris_arm/f/471/t/200521.aspx.

How does GPIOPinTypeADC() work?  How do I choose which ADC I want to connect the pin to, particularly if I want to use both ADCs at once?  Right now I use different sequencers, ADCs, and channels, but they signal from the first still appears to be in the second's ADC.  I've used an oscilloscope to verify that the sensor's outputs are not actually connected, so it appears to be a problem with how they connect to the ADCs in the microcontroller.

I'm confused about how I choose which ADC gets which AIN pin.  Any advice?

Here's my code:

void SampleLightCO(void)
{
//
// This array is used for storing the data read from the ADC FIFO. It
// must be as large as the FIFO for the sequencer in use. This example
// uses sequence 3 which has a FIFO depth of 1. If another sequence
// was used with a deeper FIFO, then the array size must be changed.
//
unsigned long ulADC0_Value[1];
unsigned long ulADC1_Value[1];
//ADCSequenceDisable(ADC0_BASE,3);
//ADCSequenceDisable(ADC1_BASE,2);
//
// Set the clocking to run at 20 MHz (200 MHz / 10) using the PLL. When
// using the ADC, you must either use the PLL or supply a 16 MHz clock
// source.
// TODO: The SYSCTL_XTAL_ value must be changed to match the value of the
// crystal on your board.
//
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);


//
// Display the setup on the console.
//
Log("ADC ->\n");
Log(" Type: Single Ended\n");
Log(" Samples: One\n");
Log(" Update Rate: 250ms\n");
Log(" Input Pin: AIN0/PE3\n\n");

//
// The ADC0 peripheral must be enabled for use.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);

//
// For this example ADC0 is used with AIN0 on port E7.
// The actual port and pins used may be different on your part, consult
// the data sheet for more information. GPIO port E needs to be enabled
// so these pins can be used.
// TODO: change this to whichever GPIO port you are using.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);

//
// Select the analog ADC function for these pins.
// Consult the data sheet to see which functions are allocated per pin.
// TODO: change this to select the port/pin you are using.
//
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_2);

//
// Enable sample sequence 3 with a processor signal trigger. Sequence 3
// will do a single sample when the processor sends a signal to start the
// conversion. Each ADC module has 4 programmable sequences, sequence 0
// to sequence 3. This example is arbitrarily using sequence 3.
//
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC1_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);

//
// Configure step 0 on sequence 3. Sample channel 0 (ADC_CTL_CH0) in
// single-ended mode (default) and configure the interrupt flag
// (ADC_CTL_IE) to be set when the sample is done. Tell the ADC logic
// that this is the last conversion on sequence 3 (ADC_CTL_END). Sequence
// 3 has only one programmable step. Sequence 1 and 2 have 4 steps, and
// sequence 0 has 8 programmable steps. Since we are only doing a single
// conversion using sequence 3 we will only configure step 0. For more
// information on the ADC sequences and steps, reference the datasheet.
//
ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE |
ADC_CTL_END);

//Seven the best channel for data isolation
ADCSequenceStepConfigure(ADC1_BASE, 2, 0, ADC_CTL_CH7 | ADC_CTL_IE |
ADC_CTL_END);

//
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 3);
ADCSequenceEnable(ADC1_BASE, 2);

//
// Clear the interrupt status flag. This is done to make sure the
// interrupt flag is cleared before we sample.
//
ADCIntClear(ADC0_BASE, 3);
ADCIntClear(ADC1_BASE, 2);

//
// Sample AIN0 forever. Display the value on the console.
//
while(1)
{
//
// Trigger the ADC conversion.
//
ADCProcessorTrigger(ADC0_BASE, 3);
ADCProcessorTrigger(ADC1_BASE, 2);

//
// Wait for conversion to be completed.
//
while(!ADCIntStatus(ADC0_BASE, 3, false))
{
}
ADCIntClear(ADC0_BASE, 3);
ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);

ADCProcessorTrigger(ADC1_BASE, 2);
while(!ADCIntStatus(ADC1_BASE, 2, false))
{
}
//
// Clear the ADC interrupt flag.
//
//ADCIntClear(ADC0_BASE, 3);
ADCIntClear(ADC1_BASE, 2);

//
// Read ADC Value.
//
//ADCSequenceDataGet(ADC0_BASE, 3, ulADC0_Value);
ADCSequenceDataGet(ADC1_BASE, 2, ulADC1_Value);

//
// Display the AIN0 (PE7) digital value on the console.
//
Log("Light Level = ");
LogD(ulADC0_Value[0]);
Log("\r");
Log("CO Level = ");
LogD(ulADC1_Value[0]);
Log("\r");

//
// This function provides a means of generating a constant length
// delay. The function delay (in cycles) = 3 * parameter. Delay
// 250ms arbitrarily.
//
SysCtlDelay(SysCtlClockGet() / 12);
}
}