Hi,
I'am using TM4C1294XL launchpad. Basically i want to change the sampling Rate of the ADC to 1khz using Timers.
My system clock is set to 120Mhz using the below command
ui32SysClkFreq= SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
I'am trying to set the ADC clock configuration with the below API
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 24);
When i check the ADC clock configuration using
ui32Config = ADCClockConfigGet(ADC0_BASE, &ui32ClockDiv);
it shows me value of ui32Config is 112?? I don't understand why is it showing 112???
Also i'am using timer interrupt to trigger the ADC. How to calculate the value of Timerload set so that my sampling rate changes to 1khz.???
Below is my code
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_TIMER, 0);
}
int main(void)
{
uint32_t ui32Period;
uint32_t ui32Config, ui32ClockDiv;
inputF32 = &inputsamples[0];
outputF32 = &testOutput[0];
ui32SysClkFreq= SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
/******* ADC INITIALIZATION***********/
SysCtlPeripheralDisable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralReset(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_ADC0)));
ADCClockConfigSet(ADC0_BASE, ADC_CLOCK_SRC_PLL | ADC_CLOCK_RATE_FULL, 24);
ui32Config = ADCClockConfigGet(ADC0_BASE, &ui32ClockDiv);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
while(!(SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOE)));
GPIOPinTypeADC(GPIO_PORTE_BASE,GPIO_PIN_3|GPIO_PIN_2|GPIO_PIN_1|GPIO_PIN_0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
//GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0x00);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = 16000000/160000;
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period-1);
TimerControlTrigger(TIMER0_BASE, TIMER_A, true);
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_CH3|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
/*********************************************************************/
/******* UART6 & INTERRUPT INITIALIZATION***********/
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOP);
GPIOPinConfigure(GPIO_PP0_U6RX);
GPIOPinConfigure(GPIO_PP1_U6TX);
IntMasterEnable();
GPIOPinTypeUART(GPIO_PORTP_BASE, GPIO_PIN_0 | GPIO_PIN_1);
UARTConfigSetExpClk(UART6_BASE, ui32SysClkFreq, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
IntEnable(INT_UART6);
UARTIntEnable(UART6_BASE, UART_INT_RX | UART_INT_RT);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
TimerEnable(TIMER0_BASE, TIMER_A);
while(1)
{
ADCIntClear(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
CH1ADC = ui32ADC0Value[0];
CH2ADC = ui32ADC0Value[1];
CH3ADC = ui32ADC0Value[2];
CH4ADC = ui32ADC0Value[3];
}
}