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

Timer value not accurate using app_timer.c in nRF51822?

Hi All

I am facing one issue using app_timer.c, When I put the PRESCALER value as 327 and started timer as app_timer_start(timer_ID, 100, NULL);, It was giving only 920ms instead of 1s? why is this so?

Here is my code

#include <stdint.h>
#include "nrf.h"
#include "app_timer.h"
#include "app_error.h"
#include "nrf_gpio.h"

//	Timer settings
#define APP_TIMER_PRESCALER             327		
#define APP_TIMER_MAX_TIMERS            1     	
#define APP_TIMER_OP_QUEUE_SIZE         1     

static app_timer_id_t         timer_ID;


void app_error_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name)
{
}


void timeOut(void * p_context)
{
	nrf_gpio_pin_toggle(4);
	
}


int main(void)
{  
  	 nrf_gpio_cfg_output(4);


	//	TIMER init	
	APP_TIMER_INIT(APP_TIMER_PRESCALER, APP_TIMER_MAX_TIMERS, APP_TIMER_OP_QUEUE_SIZE, false);
	NRF_CLOCK->TASKS_LFCLKSTART = 1;
	
	while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0);

	app_timer_create(&timer_ID, APP_TIMER_MODE_REPEATED, timeOut);

	app_timer_start(timer_ID, 100, NULL);
	
  while(true)
  {
		
  }

}

Please help me on this, Mo

Parents Reply
  • FormerMember
    0 FormerMember in reply to FormerMember

    I guess you are using the RC oscillator for the LF clock, this will result in inaccuracy. Could you use a crystal? Either a 32.768 kHz one for LFCLK or 16MHz one for HFCLK so that you can synthesize the LFCLK. If you have a 16 MHz crystal, you could also calibrate the RC oscillator of LFCLK. Even if you are using RC oscillator for LF CLK, 920 ms is way off. How are you measuring this?

Children
No Data
Related