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.

MULTICHANNEL SAMPLING

Hello,

I want to sample two channels one internal temperature sensor and an external POT on Tiva launchpad.I am able to sample both,but while watching in watch expression window both values are same(ADC0Value and result) and both change at same rate when i rub temp mcu or change POT..I don't Know where i am going wrong.Please help,i am posting my code and debug window image below

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/sysctl.h"
#include "driverlib/adc.h"
int main(void)
{
uint32_t ui32ADC0Value[4];
uint32_t result[0];

volatile uint32_t ui32TempAvg;
volatile uint32_t ui32TempValueC;
volatile uint32_t ui32TempValueF;
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);//enable clock to peripheral GPIOE
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 1);
ADCSequenceStepConfigure(ADC0_BASE,3,0,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
ADCSequenceEnable(ADC0_BASE, 3);
while(1)
{
ADCIntClear(ADC0_BASE, 1);//Clears sample sequence interrupt source.
ADCIntClear(ADC0_BASE, 3);

ADCProcessorTrigger(ADC0_BASE, 1);//CONFIGURES PROCESSOR TO TRIGGER THE SAMPLE SEQUENCER//This function triggers a processor-initiated sample sequence if the sample sequence trigger
ADCProcessorTrigger(ADC0_BASE, 3);//is configured to ADC_TRIGGER_PROCESSOR.
while(!ADCIntStatus(ADC0_BASE, 1|3, false))
{
}


ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
ADCSequenceDataGet(ADC0_BASE, 3, result);
ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;
ADCSequenceDataGet(ADC0_BASE, 3, result);

}
}

  • Sajad Rather4 said:
    uint32_t result[0];

    The variable result is defined as a zero length array. Given result has automatic storage (on the stack) any attempt to write to result will result in undefined behavior. My guess is that the compiler has placed result at the same address as ui32TempAvg. Try giving result a valid size.

    Also, which compiler are you using?

    I am surprised that defining an array of length zero with automatic storage didn't produce a compile error, or at least a warning.

  • Hello

    Thanks Chester Gillon

    ARM Compiler ( TI V5.2.7)

    I changed the value to 1 as the FIFO depth for the Sample sequencer 3 is 1,but still same result.

  • Sajad Rather4 said:
    I changed the value to 1 as the FIFO depth for the Sample sequencer 3 is 1,but still same result.

    Did you change the size of the result array to be greater than zero?

  • Hello
    Chester Gillon

    yup i changed it to 1
  • Hello

    Chester Gillon

    you can see the change ,if you suggest this only

  • Sajad Rather4 said:
    while(!ADCIntStatus(ADC0_BASE, 1|3, false))

    Hi,
    Your problem is mainly in this line - while you can do that, you may not, neither starting two successive conversions and then wait.
    My first assertion: 1|3 is evaluated at compile time (two constants) and you always wait for only one sequencer.
    The sequencer is a hardware bundle used to facilitate conversion of a number of channels with a single command. Two sequencers involved, then start the first one, wait for it to complete, grab the results, then start the second one, wait, grab.
    The reason is there is only one converter, you must wait to be shared between sequencers.
    One last suggestion:
    Since the temperature is slowly varying, you may use for it only sequencer 3 with hardware oversampling, and sequencer 1 for the pot, there you may apply averaging (although hardware oversampling works equally OK).