What I want to do is have the timer trigger an ADC converstion every 3 usecs and then use DMA to pick upt conversion results. I have tried to do some preliminary tests and the best I see 6 usecs. If I set the timer to run at 30usecs its seems to work fine but when I set it to 3usecs it looks like the best it can do is 6usecs. I am using the DK-TM4C123G Tiva C launchpad and I run my clock at 80 Mhz.
void
hwiInit()
{
uint32_t ui32Period;
uint32_t testNum =55;
GPIO_setupCallbacks(&Board_gpioCallbacks0);
/* Enable interrupts */
GPIO_enableInt(Board_BUTTON0, GPIO_INT_RISING);
//Set CPU Clock to 40MHz. 400MHz PLL/2 = 200 DIV 5 = 40MHz
//SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);
// Timer 2 setup code
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER2); // enable Timer 2 periph clks
TimerConfigure(TIMER2_BASE, TIMER_CFG_PERIODIC); // cfg Timer 2 mode - periodic
ui32Period = (
SysCtlClockGet() * 3)/1000000;
// set to 3 microseconds
TimerLoadSet(TIMER2_BASE, TIMER_A, ui32Period); // set Timer 2 period
TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // must clear timer flag FROM timer
TimerIntEnable(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // enables Timer 2 to interrupt CPU
TimerDisable(TIMER2_BASE, TIMER_A); // disable Timer 2 until ready to start taking ADC data
/*Enable output */
GPIOPinTypeGPIOOutput(GPIO_PORTJ_BASE, GPIO_PIN_2);
GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_2, 0x00);
}
void
timerInterrupt()
{
TimerIntClear(TIMER2_BASE, TIMER_TIMA_TIMEOUT); // must clear timer flag FROM timer
if(GPIOPinRead(GPIO_PORTJ_BASE, GPIO_PIN_2))
{
GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_2,0);
}
else
{
GPIOPinWrite(GPIO_PORTJ_BASE, GPIO_PIN_2, 4);
}
}
/*
* ======== main ========
*/
Int
main(Void)
{
/* Call board init functions. */
Board_initGeneral();
Board_initGPIO();
hwiInit();
/* Start BIOS */
BIOS_start();
return (0);
}
Void gpioButtonFxn0(Void)
{
GPIO_clearInt(Board_BUTTON0);
TimerEnable(TIMER2_BASE, TIMER_A); // disable Timer 2 until ready to start taking ADC data
TimerIntEnable(TIMER2_BASE, TIMER_A);
}