Part Number:EK-TM4C123GXL
EDIT: Removed Sleep(), as it is irrelevant to the question.
I am trying to do the following:
(1) Collect data via the ADC at 240 kHz.
(2) Run some processing code for each sample acquired.
I am not sure if I am setting up the clock and timer up correctly... I've been inputting a 10kHz sine wave, and getting data that looks like it's much higher frequency (about 100 kHz). Can someone either verify my config code below, or explain precisely how SysCtlClockSet() and TimerLoadSet() work (as in, how the numbers input to them convert to clock and timer frequency)?
When I run SysCtlClockGet(), I get 80 MHz, the maximum clock frequency. In order to look at the input, I have been putting the samples into a global uint32_t data buffer (not depicted in the code below) and graphing it.
//**********************************************************************************************************************************
voidInitTiming()
{
// Initialize clock.
SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
// Configure and enable timer.
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_TIMER0));
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet()/SAMPLE_RATE);
TimerEnable(TIMER0_BASE, TIMER_A);
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
}
voidInitGPIO()
{
// Configure analog input pin.
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE));
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3); // Pin 3 corresponds to channel 0.
voidInitADC()
{
// Configure ADC sequencer.
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
while(!SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0));
ADCSequenceConfigure(ADC0_BASE, ADC_SEQUENCER, ADC_TRIGGER_TIMER, 0);
ADCSequenceStepConfigure(ADC0_BASE, ADC_SEQUENCER, 0, ADC_CTL_CH0 | ADC_CTL_IE | ADC_CTL_END);
// Enable ADC interrupt.
IntEnable(INT_ADC0SS3);
ADCIntEnable(ADC0_BASE, ADC_SEQUENCER);
IntMasterEnable();
// Enable ADC sequencer.
ADCSequenceEnable(ADC0_BASE, ADC_SEQUENCER);
}
//*****************************************************************************
//
// Interrupt Handlers
//
//*****************************************************************************
// Handle an ADC interrupt. //
voidADC0Seq3IntHandler()
{
// Clear interrupt and get sample
ADCIntClear(ADC0_BASE, ADC_SEQUENCER);
uint32_t sample;
ADCSequenceDataGet(ADC0_BASE, ADC_SEQUENCER, &sample);
// Perform some data processing
}
//*****************************************************************************
//
// The main function.
//
//*****************************************************************************
intmain(void)
{
// Initialize everything.
InitTiming();
InitGPIO();
InitADC();
while(1);
}