Part Number: EK-TM4C1294XL
Other Parts Discussed in Thread: TM4C1294NCPDT
Hello everyone,
I'm new in MCU and I'm trying to run the timer every millisecond, but I can not find the setting or the calculation. I'm attaching the code I use now for testing just before I get it.
Any ideas how to set the timer to run every millisecond?
Thank you all. :)
#include <stdint.h>
#include <stdbool.h>
#include "inc/tm4c1294ncpdt.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/sysctl.h"
#include "driverlib/interrupt.h"
#include "driverlib/gpio.h"
#include "driverlib/timer.h"
uint32_t ui32Period, pom = 0;
uint32_t ui32SysClkFreq;
int main(void)
{
ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_1);
TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
ui32Period = (ui32SysClkFreq / 50);
TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period);
IntEnable(INT_TIMER0A);
TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
IntMasterEnable();
TimerEnable(TIMER0_BASE, TIMER_A);
while(1)
{
if (pom == 1000) {//if 1000ms == 1 sec
if(GPIOPinRead(GPIO_PORTN_BASE, GPIO_PIN_1))
{
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 0);
pom = 0;
}
else
{
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_1, 2);
pom = 0;
}
}
}
}
void Timer0IntHandler(void)
{
TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
pom++;
}