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.

TM4C1230C3PM: TM4C123 ADC sample code

Part Number: TM4C1230C3PM
Other Parts Discussed in Thread: EK-TM4C123GXL

Hi Team,

We would like to ask your help regarding our customer's inquiry below.

I am using the TM4C123 series controller.
I need ADC sample code

int main(void)
{
unsigned int array[4];

//Set clock to 16 MHz
SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_INT | SYSCTL_XTAL_16MHZ);

// Enable the GPIOE peripheral

SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);

// Enable the ADC0 module.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);

// Wait for the GPIOE module to be ready.


InitConsole();
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE))
{
}
// Wait for the ADC0 module to be ready.
//
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0))
{
}

//Configures ADC pins PE3 (AIN0) and PE2 (AIN1)
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2);

//Configure ADC functions
// Using Sequence 1 which has a 4 entry FIFO
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_CH0 );
ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_CH1 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE,1);
ADCIntClear(ADC0_BASE, 1);
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 1);

while(1)
{
ADCProcessorTrigger(ADC0_BASE, 1);
//wait for the conversion to be completed
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
//clear Interrupt flag
ADCIntClear(ADC0_BASE, 1);

//Read ADC input and store PE3 in array[0], PE2 in array[1]
ADCSequenceDataGet(ADC0_BASE, 1, array); //read the analog values
UARTprintf("\rADC_CTL_CH0 - > %d , ADC_CTL_CH1 - > %d", array[0],array[1]);
SysCtlDelay(SysCtlClockGet() / 10 / 3);
SysCtlDelay(SysCtlClockGet() / 10 / 3);
SysCtlDelay(SysCtlClockGet() / 10 / 3);
SysCtlDelay(SysCtlClockGet() / 10 / 3);
SysCtlDelay(SysCtlClockGet() / 10 / 3);

}
}

this is my code in that if i connect 3.3v to the channel 0 and channel 1 remain floating , in that i am getting the value of adc channel 0 as 4095, but for the channel 1 it is 2045
 
I am using the Tiva c series development board Tm4c123
 
if i remove the 3.3v applied to the channel 0 then reading of the channel 0 and channel changes , my query is why the one channel is affecting the another channel readings
Regards,
Danilo
  • Hi Team,

    I shared the TM4C123G Workshop below that shows the sample code for ADC to the customer.

    https://software-dl.ti.com/trainingTTO/trainingTTO_public_sw/GSW-TM4C123G-LaunchPad/TM4C123G_LaunchPad_Workshop_Workbook.pdf#page=111

    Here is his response.

    1. I have gone through your provided document it is very useful.
    2. In the provided document the temperature sensor reading program is provided that is working as expected
    3. In my application, I am using ADC channel 1 and ADC channel 0. I have configured the ADC sequencer 1 as per the provided setting in the user guide.
    Below issue, I am facing
    a. Without connecting any signal to ADC channel 1 and ADC channel 0, the ADC channel 1 count is 237 and the ADC channel count 0 is 253 approximate.
    b. When I connect 3.3v to ADC channel 1 the count showing is 4095 which correct one. But for the ADC channel 0 count increased from 253 to 2556 approximately. I am unable to understand why 3.3V connected to ADC channel 1 is impacting the readings of ADC channel 0.
    Could please guide me on How I can resolve this issue?
    Below is the code for your reference
    int main(void)
    {
    unsigned int array[4];

    //Set clock to 16 MHz
    SysCtlClockSet(SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSC

    I have referred the ADC Ping-Pong method using the DMA, in that only one channel is used . Could you please provide the solution without DMA or with multiple channel with DMA

    Regards,

    Danilo

  • Hello Danilo,

    This is a result of the floating pins picking up parasitic voltages from the adjacent pins. I see this sort of behavior when doing development myself, its not unheard of. The ADC will not read only 0 volts unless the ADC pin is properly grounded and not left floating. This is why recommendations for minimum power consumption etc. involve grounding all unused pins. Slight smile

    Best Regards,

    Ralph Jacobi

  • Hi Ralph,

    Thank you for your response. Please see the comment of our customer below.

    I am using the "EK-TM4C123GXL ARM® Cortex®-M4F Based MCU TM4C123G LaunchPadTm Evaluation Kit" board. Please let me know if my understanding is correct or wrong. if I connect the 3.3V to channel 1 then it will give the 4095 counts, and at the same time to the ADC channel 0 1.65V is connected, then it will show ADC channel 0 counts 2047. even though if is remove channel 1 3.3v it will not change the ADC channel 0 counts.

    Regards,

    Danilo

  • Hello Danilo,

    If I am understanding their comments correctly then they are understanding right. This is my understanding of the scenarios they are asking about:

    Channel 1 = 3.3V --> 4095 counts | Channel 0 = 1.65V --> 2047 counts

    Channel 1 = floating --> Unknown counts | Channel 0 = 1.65V --> 2047 counts

    If so then yes that is correct understanding.

    Best Regards,

    Ralph Jacobi

  • Hi Ralph,

    Please see the response of our customer below

    In my case
    Point-> 1. if both the channels are floating then
    Channel 1 = floating--> 324 counts
    Channel 0 = floating--> 324 counts

    Point-> 2. After 3.3V provided to
    Channel 1 = 3.3v--> 4095counts
    Channel 0 = floating --> 2047 counts (this is the issue I have Applied voltage it channel 1 but the count of channel 0 also changed)
    .......................................................................................................................................
    as per the provided solution for TI
    if we connect the proper ground to the unused pin, it will resolve the above issue in point->2.

    Please let me below listed my understanding correct or wrong
    3. if supposed I have connected all the unused to the ground then the below output should be expected
    Channel 1 = 3.3v -> 4095 counts
    Channel 1 = 1.65V --> 2047 counts

    Regards,

    Danilo

  • Hello Danilo,

    Yes the customers understanding is correct and if all unused pins are grounded then Channel 1 should have those results.

    Best Regards,

    Ralph Jacobi