This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TM4C129 - incorrect period

Hello Guys,

I am using the TM4C1294NCPDT part of the launchpad (EK-TM4C1294XL).

I am trying to run a timer at 1 microsecond interrupts. I am getting 0.55usec however. I am not sure what is wrong with my calculations. I toggle a GPIO pin, in the interrupt. I have used the timer interrupt code in the  workbook (page 118)  provided by T1 called: Creating IoT Solutions with the Tiva® C Series Connected LaunchPad Workshop.

I am using the following period calculations.

if we relate the clock rate by the time: 120,000,000 cycles/sec= 1 second

and 1 second = 1usec*1,000,000

then 120,000,000=1*1,000,000

or 1usec=120,000,000/1,000,000 = ui32SysClkFreq/1,000,000.

the output can be viewed here, or http://imgur.com/ULJiZOb :

 

The code: http://pastebin.com/AWWzn77W


The project file:proj.zip

Thanks Guys

  • Hello Daniel,

    If you review the example, you can note that the clock is acutally divided by 2 to generate an interrupt on both the low to high transition and the high to low transitions to get to the desired period for the generated output with 50% duty cycle. Given this information, the period should actually be 2usec not 1 as you have coded. So, I believe you would need a period = (SysClk/1000000)/2 to achieve the 1usec pulse width on the output which would equate to a 1us timer interrupt.
  • thanks chuck, however the problem was with my code, I forgot to clear the timer register in the interrupt. the working code.

    #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"
    
    
    int main(void)
    {
    	uint32_t ui32Period;
    	uint32_t ui32SysClkFreq;
    
    	ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN |
    	SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
    	//clock init
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
    	//GPIO init
    	GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
    	//timer init
    	TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
    
    	ui32Period = ui32SysClkFreq/1000000;
    
    	TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
    
    	IntEnable(INT_TIMER0A);
    	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    	IntMasterEnable();
    
    	TimerEnable(TIMER0_BASE, TIMER_A);
    
    
    
    
    
    while(1)
    	{
    	}
    }
    
    volatile int x = 2;
    void Timer0IntHandler(void)
    {
    	 TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    
    	x^=0xF;
    	GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, x);
    
    
    }