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.

Reg: ADC in TM4C123 LAunch pad

Other Parts Discussed in Thread: TM4C123GH6PM

Hi

     I am using Tm4C123 launch pad, now i want to use ADC with four channels. I done some code related for this, but it not working fine.

Please anybody help to solve this issue. Any body post Sample program means better

I am posted my code in this i used only two ports


#include <stdbool.h>
#include <stdint.h>
#include "inc/tm4c123gh6pm.h"

#include "inc/hw_memmap.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/timer.h"
#include "driverlib/uart.h"
#include "driverlib/adc.h"
#include "utils/uartstdio.h"


volatile unsigned long delay;
unsigned long test_time1;

//*****************************************************************************
//
// Configure Timer0B as a 16-bit periodic counter with an interrupt every 1ms.
//
//*****************************************************************************


unsigned int adc_value[4];

int main(void)
{
adc_value[0] = 0;
adc_value[1] = 0;
adc_value[2] = 0;
adc_value[3] = 0;

SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

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

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_1);

ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 1);


ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
// Since sample sequence 3 is now configured, it must be enabled.
//
ADCSequenceEnable(ADC0_BASE, 3);
ADCSequenceEnable(ADC0_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(ADC0_BASE, 2);


while(1)
{
// Trigger the ADC conversion.
ADCProcessorTrigger(ADC0_BASE, 3);

// Wait for conversion to be completed.
while(!ADCIntStatus(ADC0_BASE, 3, 0))
{
}

ADCSequenceDataGet(ADC0_BASE, 3, &adc_value[3]);

ADCProcessorTrigger(ADC0_BASE, 2);
// Wait for conversion to be completed.
while(!ADCIntStatus(ADC0_BASE, 3, 0))
{
}

ADCSequenceDataGet(ADC0_BASE, 2, &adc_value[2]);


test_time1 = 100;
while(test_time1 > 1)
{
test_time1--;
delay = 100;

while(delay > 1)
delay--;
}

}
}

 with regards

Yuvaraj

  • define "not working fine"

    Robert
  • Dear Robert

    I connected four different analog input to port PE1, PE2,PE3 like that, but PE3 input data repeat to channel other buffer. whenever i read data from all buffer, i get  PE3 channel data  in all buffers. Plz find the below image for clarity adc_value[3] is assigned to PE3 and it connected to +3.3V, adc_value[2] is assigned to PE2 and it connected to 0V. But Both the buffer have equivalent count of +3.3V i.e 4095.

    My code is 


    #include <stdbool.h>
    #include <stdint.h>
    #include "inc/tm4c123gh6pm.h"

    #include "inc/hw_memmap.h"
    #include "driverlib/gpio.h"
    #include "driverlib/interrupt.h"
    #include "driverlib/pin_map.h"
    #include "driverlib/sysctl.h"
    #include "driverlib/timer.h"
    #include "driverlib/uart.h"
    #include "driverlib/adc.h"
    #include "utils/uartstdio.h"


    volatile unsigned long delay;
    unsigned long test_time1;

    unsigned int adc_value[4];

    int main(void)
    {
    adc_value[0] = 0;
    adc_value[1] = 0;
    adc_value[2] = 0;
    adc_value[3] = 0;

    SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

    ADCSequenceConfigure(ADC0_BASE, 3, ADC_TRIGGER_PROCESSOR, 0);
    ADCSequenceConfigure(ADC0_BASE, 2, ADC_TRIGGER_PROCESSOR, 1);

    ADCSequenceStepConfigure(ADC0_BASE, 3, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
    ADCSequenceStepConfigure(ADC0_BASE, 2, 1, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);

    ADCSequenceEnable(ADC0_BASE, 3);
    ADCSequenceEnable(ADC0_BASE, 2);
    ADCIntClear(ADC0_BASE, 3);
    ADCIntClear(ADC0_BASE, 2);

    while(1)
    {
    ADCProcessorTrigger(ADC0_BASE, 3);

    while(!ADCIntStatus(ADC0_BASE, 3, 0))
    {
    }
    ADCSequenceDataGet(ADC0_BASE, 3, &adc_value[3]);
    ADCProcessorTrigger(ADC0_BASE, 2);
    while(!ADCIntStatus(ADC0_BASE, 2, 0))
    {
    }
    ADCSequenceDataGet(ADC0_BASE, 2, &adc_value[2]);

    test_time1 = 500;
    while(test_time1 > 1)
    {
    test_time1--;
    delay = 500;

    while(delay > 1)
    delay--;
    }

    }
    }

    With Regards

    Yuvaraj

  • No need to paste your code twice (although using past code would be better than just putting it into your post with no formatting).

    First question, you only attempt to convert 2 channels, why expect 4?

    Second how did you make your connections?

    Search on the bookshelf tag. You will find TI seminars on the care and feeding of A/Ds

    Finally you have an undefined step in sequence 1, you configure step 1 but not step 0. I expect that behaviour is undefined.

    Robert