This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Task delay faster that expected

Hi, 

I am using nRF52832, SDK 15. My code is based on the freeRTOS code examples.

I am trying to Run my Task Every 10 ms. I tried to test this by using a counter to print every minute. And every minute ,the notification appears after 58.6 seconds. 

To Run my Task i am using this function vTaskDelayUntil(&LastWakeTime, pdMS_TO_TICKS(10)); the variable LastWakeTime is been initialized with LastWakeTime = xTaskGetTickCount();

It seemed that the Delay for 10.24 (10) ticks (10 ms) could it cause system clock to be faster ? 

If i will change the configTICK_RATE_HZ to a round number (2000 for example) would it have any performance downside? (not being a power of 2)  and would it solve this?

Thanks A lot 

ibrahim

Parents Reply Children
  • This is a very simplified example written in a couple of minutes. But it shows the necessary basic functions.

    /*--------------------------------------------------------------------------------------*/
    bool TimerCreate (void)
    { 
      NRF_TIMER1->MODE       = TIMER_MODE_MODE_Timer<<TIMER_MODE_MODE_Pos;
      NRF_TIMER1->BITMODE    = TIMER_BITMODE_BITMODE_32Bit;
      NRF_TIMER1->PRESCALER  = 0x09;		// 16 MHz / 2^9 = 31.25 kHz
      NRF_TIMER1->CC[0]      = 60*31250;    // 60 sec = 1 min
      NRF_TIMER1->INTENSET   = TIMER_INTENSET_COMPARE0_Enabled<<TIMER_INTENSET_COMPARE0_Pos;  
      // Enable timer interupt
      NVIC_ClearPendingIRQ(TIMER1_IRQn);
      NVIC_EnableIRQ(TIMER1_IRQn);
      
      return NRF_SUCCESS;
    }
    /*--------------------------------------------------------------------------------------*/  
    xTaskHandle hSomeTask;
    bool CreateSomeTask (uint8_t StackSize, uint8_t Priority)
    {
    	return xTaskCreate(tSomeTask, "SomeTask", StackSize, NULL, Priority, &hSomeTask);
    }
    /*--------------------------------------------------------------------------------------*/
    void tSomeTask  (void *pvConext)
    {
    	// Init all what you need
    	TimerCreate();	// Create 1min timer
    	
    	// Task Body
    	for(;;)
    	{
    		// Wait notification
    		xTaskNotifyWait(0x00, 0xffff, NULL, portMAX_DELAY);	
    		
    		/* do something*/
    	}
    }
    /*--------------------------------------------------------------------------------------*/
    /* Timer interupt handler */
    void TIMER1_IRQHandler(void)
    {
      if(NRF_TIMER1->EVENTS_COMPARE[0])
      { // Clear IRQ event flag
        NRF_TIMER1->EVENTS_COMPARE[0] = 0x0UL;
        volatile uint32_t dummy = NRF_TIMER1->EVENTS_COMPARE[0];
        (void)dummy;
    	
    	// Give Notification
    	xTaskNotifyFromISR(hSomeTask);
      }
    }
    /*--------------------------------------------------------------------------------------*/

    Best regards,

    Max

  • Hi,

    Thanks a lot for you answer 

    i Have another question why do i need this part in the code : 

    volatile uint32_t dummy = NRF_TIMER1->EVENTS_COMPARE[0];
    (void)dummy;

    Thanks you CheMax 

  • I think you can found answer in this topic: about (volatile)dummy

    Good luck in your codding.

Related