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.

What does the period in the timer exactly specify?

Hello,

Now for 16-bit timer I know that it counts up to 0xFFFF then what is the use of period in configuring the timer ?

Also when I configure System clock to 120MHz and add its variable to expressions it shows another value "96000000" so, why is that?

Regards,

Badr 

  • Hello Badr

    A code post to what you are doing and when you see the variable in watch window would be useful

    Regards

    Amit

  • Hello Amit,

    The next code should test running two timers (T0A & T0B) in parallel in split mode.

    each timer blink a led with a ratio (1:5) of frequency.

    #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 counta = 0;
    int countb = 0;
    int clock = 0;
    int compa = clock * 5
    int main(void)
    {
    	uint32_t ui32Period;
    	uint32_t ui32SysClkFreq;
    
    	//SET SYSTEM CLK
    	ui32SysClkFreq = SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ | SYSCTL_OSC_MAIN | SYSCTL_USE_PLL | SYSCTL_CFG_VCO_480), 120000000);
    	clock = SysCtlClockGet();
    	//ENABLE PERIPHERALS
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
    	SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
    
    	//CONFIGURE PERIPHERALS
    	GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE,GPIO_PIN_1 | GPIO_PIN_0);
    	TimerConfigure(TIMER0_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC | TIMER_CFG_B_PERIODIC);
    	//TimerConfigure(TIMER1_BASE, TIMER_CFG_SPLIT_PAIR | TIMER_CFG_A_PERIODIC);
    
    	//SET THE PERIOD OF THE TIMER
    	ui32Period = clock;
    	TimerLoadSet(TIMER0_BASE, TIMER_B, ui32Period -1);
    	TimerLoadSet(TIMER0_BASE, TIMER_A, clock -1);
    
    	//ENABLE INTERRUPTS
    	IntEnable(INT_TIMER0A);
    	TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    	IntEnable(INT_TIMER0B);
    	TimerIntEnable(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
    	IntMasterEnable();
    
    	//ENABLE TIMERS
    	TimerEnable(TIMER0_BASE, TIMER_A);
    	TimerEnable(TIMER0_BASE, TIMER_B);
    	
    
    	while(1)
    	{
    	}
    
    }
    //ISR
    void Timer0AIntHandler(void)
    {
    	// Clear the timer interrupt flag
    	TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
    	counta++;
    
    	if (counta==9155)
    	{
    		if(GPIOPinRead(GPIO_PORTN_BASE,GPIO_PIN_1))
    			GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_1,0x0);
    		else
    			GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_1,0x2);
    		counta = 0;
    	}
    }
    void Timer0BIntHandler(void)
    {
    	// Clear the timer interrupt flag
    	TimerIntClear(TIMER0_BASE, TIMER_TIMB_TIMEOUT);
    	countb++;
    
    	if (countb==45776)
    	{
    		if(GPIOPinRead(GPIO_PORTN_BASE,GPIO_PIN_0))
    			GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0,0x0);
    		else
    			GPIOPinWrite(GPIO_PORTN_BASE,GPIO_PIN_0,0x1);
    		countb = 0;
    	}
    }
    

    So, from configuration, I calculated from the clock freq (=120MHz) the time of full count for the timers and counted the appropriate time to make it count 5:1 seconds.

    Now when I try to add clock variable to expressions tab to watch its value, it shows to me another value than expected.

    Further more, I cant understand what is the function of "period" in TimerLoadSet() function ?

    Regards,

    Badr.

  • Hello Badrm

    The API SysCtlClockGet is meant for TM4C123 devices only. In TM4C129 devices the return value of the SysCtkClockFreqSet is the acutal system clock value. So you should be using uo32SysClkFreq.

    Also for a 16-bit counter the value cannot be more than 65536. So either you use the Timer in 32-bit mode or use the Prescalar to extend the timer for 24-bit. For the value of 120MHz even 24-bit will be insufficient.

    Regards

    Amit

  • Thanks Amit,

    I know it's possible to do it with 32-bit timer Iam doing it on 16-bit on purpose that I want to try the both of timers A & B in the same time in the split mode , even so, it's similar to using any width of timers because Iam counting the overflows or the time-outs of the timer so, the no, of (time-outs * the single time-out in sec) gives me either 1sec or 5 seconds as I wish.

    Any way I figured out what's wrong which is that I firstly didn't understand what period is but, as soon as I put the right value in it (2^16-1), It worked thanks to God .

     

    Regards,

    Badr.