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.

TM4C123GH6PGE: ADC Data reading

Part Number: TM4C123GH6PGE

Hello everyone,

                  Thanks to all for helped in my previous posts.

Today i am developing a new project.In this I am getting problem with ADC input data reading. I am  using ADC0 base and sample sequence 1 (SS1) for data reading purpose.whats i am getting the problem is if i apply input to any of the one channel, actually i want to get output particular channel but i am getting the sample output all four channels. Here i am using processor trigger for triggering the ADC.

Please find the below code and suggest me if any wrong in the code.

#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
#include "utils/uartstdio.h"
#include "inc/hw_gpio.h"
#include "inc/hw_ints.h"
#include "inc/hw_adc.h"
#include "inc/hw_types.h"
#include "DriverLib/adc.h"
#include "DriverLib/interrupt.h"
#include "DriverLib/pwm.h"
#include "DriverLib/timer.h"

unsigned int pui32ADC0Value[4];

extern int keypad_rot;

uint32_t ch0,ch1;

void ADC0IntHandler(void);

#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif




void
Timer1IntHandler(void)
{
TimerIntClear(TIMER1_BASE, TIMER_TIMA_TIMEOUT);


data_disp();

}


void
ADC0IntHandler(void)
{

ADCIntClear(ADC0_BASE, 1);

ADCSequenceDataGet(ADC0_BASE, 1, pui32ADC0Value);


ch0= pui32ADC0Value[0];
ch1=pui32ADC0Value[1];

}

int
main(void)
{

SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);


SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);

SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER1);

SysCtlDelay(5000);

SysCtlPeripheralClockGating(true);


IntMasterEnable();

IntPrioritySet(INT_ADC0SS1_TM4C123, 0x00);

IntPrioritySet(INT_TIMER1A, 0x20);


lcd_pripheral_config();

lcdinit();

TimerConfigure(TIMER1_BASE, TIMER_CFG_A_PERIODIC);
TimerLoadSet(TIMER1_BASE, TIMER_A, (4*SysCtlClockGet()));
IntEnable(INT_TIMER1A);
TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);

TimerEnable(TIMER1_BASE, TIMER_A);

ADCSequenceDisable(ADC0_BASE, 1);

ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);


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



ADCSequenceEnable(ADC0_BASE, 1);

 ADCProcessorTrigger(ADC0_BASE, 1);


ADCIntEnable(ADC0_BASE, 1);

IntEnable(INT_ADC0SS1);

}

I am developing this code by the reference of tiva examples.

Please suggest me why i am getting outputs in two channel outputs ch0 and ch1 , if i apply the input to any one channel.

Thanks,

Regards,

Srinu.V

  • Are each & every of your ADC inputs properly "impedance matched" to your external voltage sources?

    Should your ADC inputs be "floating" (disconnected) then the ADC's "sample & hold" input capacitor - will likely "retain its charge" - and the effect you observe - is likely to be noted. Small value, ceramic bypass caps - placed very close to each ADC input pin - should greatly assist in your correction.

    It would also aid your understanding if you would provide (proper) voltage inputs to 2 (or more) different ADC inputs. My belief is that you will (then) likely see each individual channel read correctly...
  • Thank you sir for giving this valuable suggestion,

    In my board already i have capacitors at each ADC input pin. I found my mistake is "some delay required " after ADCProcessorTrigger(ADC0_BASE, 1);
    and it is required to continuously trigger to the ADC in while loop.

    Finally i finished my task.

    Thanks,
    Srinu.V
  • Thank you - and it MUST be noted that you (unlike many here) were good & kind enough - to reward the forum w/your CORRECTIVE METHODS!
    That's the Full Forum Spirit - and "best insures" that (myself/others here) respond quickly to most "any/all" of your future postings.

    Well done, my friend...