This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Timer 1ms with SD enabled

Hi

I'm trying to set up a 1ms tick timer using TIMER_1. In other words: every 1ms, I have to increment a tick counter, and to perform several operations. When SD is not enabled, the tick timer is working perfectly. The problems appear when the SD is enabled.

In my current example, I'm using a GPIO to measure the frequency of the interrupt. Here below is my code, maybe you could indicate me where is my issue:

Initialization:

	TIMER_BASE_Tick = 0;

	TIMER_BASE_TIMER->PRESCALER = 5;

	TIMER_BASE_TIMER->TASKS_STOP = 1;	/* Stop timer */
	TIMER_BASE_TIMER->MODE = TIMER_MODE_MODE_Timer;  /* taken from Nordic dev zone */
	TIMER_BASE_TIMER->BITMODE = TIMER_BITMODE_BITMODE_16Bit;
	TIMER_BASE_TIMER->CC[0] = 500;
	TIMER_BASE_TIMER->TASKS_CLEAR = 1; /* Clear timer */
	TIMER_BASE_TIMER->INTENSET = TIMER_INTENSET_COMPARE0_Enabled << TIMER_INTENSET_COMPARE0_Pos;
	TIMER_BASE_TIMER->SHORTS = (TIMER_SHORTS_COMPARE0_CLEAR_Enabled << TIMER_SHORTS_COMPARE0_CLEAR_Pos);

    sd_nvic_SetPriority(TIMER_BASE_TIMER_IRQ, 3);
    sd_nvic_EnableIRQ(TIMER_BASE_TIMER_IRQ);

    TIMER_BASE_TIMER->TASKS_START = 1;

Where TIMER_BASE_TIMER is TIMER_1, and TIMER_BASE_TIMER_IRQ is TIMER1_IRQn

On the other hand, in the IRQ, I have set up the followint code:

void TIMER_BASE_IRQHandler(void)
{
    if (TIMER_BASE_TIMER->EVENTS_COMPARE[0] != 0)
    {
    	TIMER_BASE_TIMER->EVENTS_COMPARE[0] = 0;

    	/* Increment tick */
    	TIMER_BASE_Tick++;
    	TIMER_BASE_ElapsedTicks++;

    	/* Your functions here  *********** */
    	PINS_Toggle(APP_LED_OF_LIFE);
    	/* End of your functions ********** */

    	TIMER_BASE_TIMER->SHORTS = TIMER_SHORTS_COMPARE0_CLEAR_Msk;
    }
}

Measuring frequency of toggling pin, I've verified the frequency is perfectly 1ms when the SD is not enabled. But when enabling it, considerable jitters appears.

What am I doing wrong?

Parents Reply Children
No Data
Related