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.

Multi-channel ADC



Hi I am using (http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/335532.aspx) as a guideline to setup my 5 channels ADC using pin E0 ,E1,E2,E3 and E5. 

I am using Kentec for Tiva™ C Series LaunchPad to display the ADC values on pin E0 and E1 and below is my coding. Compilation shows no error, however the display on my LCD shows no ADC values.

uint32_t adc0buffer[8],adc1buffer[8];
volatile uint32_t ch0data, ch1data;
int i,Average0,ch0data0,ch0data1,ch0data2,ch0data3,Average1,ch1data0,ch1data1,ch1data2,ch1data3;

SysCtlClockSet(SYSCTL_SYSDIV_10|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);//20Mhz clock
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC1);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
ADCReferenceSet(ADC0_BASE, ADC_REF_INT); //Set reference to the internal reference ,You can set it to 1V or 3 V
ADCReferenceSet(ADC1_BASE, ADC_REF_INT);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); //Configure GPIO as ADC
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_2);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_5);

ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC1_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);

ADCSequenceStepConfigure(ADC0_BASE, 2, 0, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH3);
ADCSequenceStepConfigure(ADC0_BASE, 2, 2, ADC_CTL_CH8 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceStepConfigure(ADC1_BASE, 0, 0, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 2, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 3, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 4, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 5, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 6, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC1_BASE, 0, 7, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);

ADCSequenceEnable(ADC0_BASE, 2);
ADCSequenceEnable(ADC0_BASE, 0);
ADCSequenceEnable(ADC1_BASE, 0);

ADCIntClear(ADC0_BASE, 2);
ADCIntClear(ADC0_BASE, 0);
ADCIntClear(ADC1_BASE, 0);

Kentec320x240x16_SSD2119Init();
GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);
ClrScreen();
GrContextForegroundSet(&sContext, ClrBlue);
GrContextFontSet(&sContext, &g_sFontCmsc20);
GrStringDraw(&sContext, "ADC Value:" , -1, 5, 22, 0);
GrStringDraw(&sContext, "ADC Value:" , -1, 5, 52, 0);
GrFlush(&sContext);

        while(1)
        {
            ADCIntClear(ADC0_BASE, 2);
            ADCProcessorTrigger(ADC0_BASE, 2);                // Trigger the ADC conversion.
            while(!ADCIntStatus(ADC0_BASE, 2, false)){}        // Wait for conversion to be completed.
            ADCIntClear(ADC0_BASE, 2);                        // Clear the ADC interrupt flag.
            //ADCSequenceDataGet(ADC0_BASE, 3, adcbuffer);    // Read ADC Value.
            //ch2data = adcbuffer[0];
            //ch3data = adcbuffer[1];
            //ch8data = adcbuffer[2];

            for (i=0;i<16;i++)
            {
                ADCIntClear(ADC0_BASE, 0);
                ADCIntClear(ADC1_BASE, 0);
                ADCProcessorTrigger(ADC1_BASE, 0|ADC_TRIGGER_WAIT);                
                ADCProcessorTrigger(ADC0_BASE, 0|ADC_TRIGGER_SIGNAL);                
                while(!ADCIntStatus(ADC0_BASE, 0, false)){}            // Wait for conversion to be completed.
                ADCIntClear(ADC0_BASE, 0);                    // Clear the ADC interrupt flag.
                ADCIntClear(ADC1_BASE, 0);                    // Clear the ADC interrupt flag.
                ADCSequenceDataGet(ADC0_BASE, 0, adc0buffer);            // Read ADC Value.
                ADCSequenceDataGet(ADC0_BASE, 0, adc1buffer);            // Read ADC Value.
                ch0data = (adc0buffer[0] + adc0buffer[1] + adc0buffer[2] + adc0buffer[3] + adc0buffer[4] + adc0buffer[5] + adc0buffer[6] + adc0buffer[7])/8;
                ch1data = (adc1buffer[0] + adc1buffer[1] + adc1buffer[2] + adc1buffer[3] + adc1buffer[4] + adc1buffer[5] + adc1buffer[6] + adc1buffer[7])/8;
                Average0 = ch0data;
                Average1 = ch1data;
                ch0data0 = Average0/1000;
                ch0data1 = Average0%1000/100;
                ch0data2 = Average0%1000%100/10;
                ch0data3 = Average0%1000%100%10/1;
                ch1data0 = Average1/1000;
                ch1data1 = Average1%1000/100;
                ch1data2 = Average1%1000%100/10;
                ch1data3 = Average1%1000%100%10/1;
                char buffer0[10],buffer1[10],buffer2[10],buffer3[10];
                char buffer4[10],buffer5[10],buffer6[10],buffer7[10];
                sprintf(buffer0,"%d",ch0data0);
                sprintf(buffer1,"%d",ch0data1);
                sprintf(buffer2,"%d",ch0data2);
                sprintf(buffer3,"%d",ch0data3);
                sprintf(buffer4,"%d",ch1data0);
                sprintf(buffer5,"%d",ch1data1);
                sprintf(buffer6,"%d",ch1data2);
                sprintf(buffer7,"%d",ch1data3);
                SysCtlDelay(SysCtlClockGet()/3);
                ClrScreen2();
                ClrScreen3();
                GrContextForegroundSet(&sContext, ClrRed);
                GrContextFontSet(&sContext, &g_sFontCmsc20);
                GrStringDraw(&sContext, buffer0 , -1, 130, 22, 0);
                GrStringDraw(&sContext, buffer1 , -1, 140, 22, 0);
                GrStringDraw(&sContext, buffer2 , -1, 150, 22, 0);
                GrStringDraw(&sContext, buffer3 , -1, 160, 22, 0);
                GrStringDraw(&sContext, buffer4 , -1, 130, 52, 0);
                GrStringDraw(&sContext, buffer5 , -1, 140, 52, 0);
                GrStringDraw(&sContext, buffer6 , -1, 150, 52, 0);
                GrStringDraw(&sContext, buffer7 , -1, 160, 52, 0);
                GrFlush(&sContext);
        		}
            }

  • Hello Teng,

    The first thing to check is if the conversion is happening correctly and the data is at least getting printed on the UART console. This would help eliminate any problem with ADC Conversion or the software for the same. Can you check that?

    Regards

    Amit