Hi,
I would like to sample ADC triggering Timer for every 10 ms in Tiva DK-TM4C1294 board. Here is my code. function are written for configure ADC and reading from ADC. it is not working. Please help me in fix the issue or post sample code if you have any.
void
ConfigureADC(void)
{
SysCtlPeripheralReset(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlDelay(10);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0 );
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PIOSC | ADC_CLOCK_RATE_FULL, 64);
ADCSequenceDisable(ADC0_BASE, 0);
ADCSequenceDisable(ADC0_BASE, 1);
ADCSequenceDisable(ADC0_BASE, 2);
ADCSequenceDisable(ADC0_BASE, 3);
//ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE,0,0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE,0,1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE,0,2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE,0,3, ADC_CTL_CH3 | ADC_CTL_IE | ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 0);
ADCSequenceEnable(ADC0_BASE, 1);
ADCSequenceEnable(ADC0_BASE, 2);
ADCSequenceEnable(ADC0_BASE, 3);
// Clear the interrupt status flag.
ADCIntClear(ADC0_BASE, 0);
ADCIntClear(ADC0_BASE, 1);
ADCIntClear(ADC0_BASE, 2);
ADCIntClear(ADC0_BASE, 3);
// Enable the Timer peripheral
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
// Timer should run periodically
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
// Set the value that is loaded into the timer everytime it finishes
// it's the number of clock cycles it takes till the timer triggers the ADC
#define F_SAMPLE 10
TimerLoadSet(TIMER0_BASE, TIMER_A, g_ui32SysClock /F_SAMPLE);
// Setup the interrupts for the timer timeouts.
//
ROM_IntEnable(INT_TIMER0A);
//ROM_IntEnable(INT_TIMER1A);
ROM_TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
//ROM_TimerIntEnable(TIMER1_BASE, TIMER_TIMA_TIMEOUT);
// Enable the timers.
//
ROM_TimerEnable(TIMER0_BASE, TIMER_A);
//ROM_TimerEnable(TIMER1_BASE, TIMER_A);
}
uint32_t
WaitAndReadADC(uint32_t *adcValue)
{
//ADCProcessorTrigger(ADC0_BASE,0);
// Wait until the sample sequence has completed.
// Enable triggering
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
while(!ADCIntStatus(ADC0_BASE, 0, false)) { }
// Read the value from the ADC.
return(ADCSequenceDataGet(ADC0_BASE, 0, adcValue));
}
int
main(void)
{
// Run from the PLL at 120 MHz.
//
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
// Enable interrupts to the processor.
ROM_IntMasterEnable();
ConfigureADC();
ui32Count = WaitAndReadADC(&ui32adcValue);
ROM_IntMasterDisable();
}