Hi,
I am trying to use ADC0 peripheral in TM4C123GH6PM microcontroller. I had configured sample sequencer 1 for reading analog values from AIN0, AIN1, AIN2 and AIN3 channels. i am facing following issues while trying to read data across the channels.
- After configuring ADC for the first time read, only value 0 is read across all the 4 channels irrespective of their voltage levels.
- Data read from the SS1 is stored in an array g_adcSS1RawData[4] and i am expecting data to be stored in following sequence,
- g_adcSS1RawData[0] -> AIN3 data
- g_adcSS1RawData[1] -> AIN2 data
- g_adcSS1RawData[2] -> AIN1 data
- g_adcSS1RawData[3] -> AIN0 data
But data is not stored as expected and sometimes even data which is read is irrelevant.
Please help me in sorting out this issue and i had also attached the reference code.
#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"
#include "driverlib/gpio.h"
uint32_t g_adcSS1RawData[4];
void systemClock(void);
void adcInit(void);
void adcRead(void);
void main(void)
{
uint32_t indexCounter;
//Initialize system clock from external oscillator
systemClock();
//Initialize ADC
adcInit();
//Start Reading from ADC
for(indexCounter = 0; indexCounter < 100; indexCounter++)
{
adcRead();
}
//Re-initialize system clock
systemClock();
while(1)
{
}
}
void systemClock(void)
{
// Set the clock to run directly from the external crystal/oscillator at 16MHz.
SysCtlClockSet((uint32_t)SYSCTL_SYSDIV_1 | (uint32_t)SYSCTL_USE_OSC | \
(uint32_t)SYSCTL_OSC_MAIN | (uint32_t)SYSCTL_XTAL_16MHZ);
}
void adcInit(void)
{
//Use PLL for ADC
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
//Enable ADC0 module
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
//Configure clock for ADC0
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 24);
//Configure GPIO pins to be used as ADC inputs
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);
//Disable ADC sample sequencers before configuring
ADCSequenceDisable((uint32_t)ADC0_BASE, (uint32_t)ADC_SAMPLE_SEQUENCER1);
//Configure ADC sample sequencer1
ADCSequenceConfigure(ADC0_BASE, ADC_SAMPLE_SEQUENCER1, ADC_TRIGGER_PROCESSOR, 0U);
//Configure current sense values of 12V, 5V regulators as inputs of sample sequencer1
ADCSequenceStepConfigure(ADC0_BASE, 1, \
0, ADC_CTL_CH3);
ADCSequenceStepConfigure(ADC0_BASE, 1, \
1, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 1, \
2, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 1, \
3, ADC_CTL_CH1|ADC_CTL_IE|ADC_CTL_END);
//Enable sample sequencers
ADCSequenceEnable(ADC0_BASE, ADC_SAMPLE_SEQUENCER1);
}
void adcRead(void)
{
//Enable interrupt for sample sequencer 1 of ADC0
ADCIntEnable((uint32_t)ADC0_BASE, (uint32_t)ADC_SAMPLE_SEQUENCER1);
//clear interrupt source for sample sequencer 1 of ADC0
ADCIntClear((uint32_t)ADC0_BASE, (uint32_t)ADC_SAMPLE_SEQUENCER1);
//Configure processor to trigger ADC conversion
ADCProcessorTrigger((uint32_t)ADC0_BASE, (uint32_t)ADC_SAMPLE_SEQUENCER1);
//wait until ADC conversion completes
while (ADCIntStatus((uint32_t)ADC0_BASE, (uint32_t)ADC_SAMPLE_SEQUENCER1, false) != 0U)
{
}
//Captures the data from sample sequencer 1 of ADC0
if(ADCSequenceDataGet((uint32_t)ADC0_BASE, (uint32_t)ADC_SAMPLE_SEQUENCER1, g_adcSS1RawData) == 0)
{
}
}
Thanks and Regards,
Santhosh.