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

NRF52832 nrfx_timer can not reach the accuracy of microsecond?

Hi gays,

               Now, I want to collect a pulse waveform(example : 1s, 50% duty cycle ) which accuracy requires milliseconds resolution and I use PPI to read a capture value from timer,but  I see the accuracy drifting. The problem is that i can not reach the accuracy of microsecond resolution.

      Timer Setup:                  

                                nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;  //  16MHZ 
                                timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
                                timer_cfg.mode = NRF_TIMER_MODE_TIMER;

                               err_code = nrf_drv_timer_init(&timer, &timer_cfg, my_timer_handler);                   

     GPIOTE Setup :

                            err_code = nrf_drv_gpiote_in_init(GPIOTE_CHECK_PIN, &in_config, gpio_intterup1t_handler);   //  capture time value in gpio handler                                              

         PPI Setup:                  

                            gpiote_event_addr = nrf_drv_gpiote_in_event_addr_get(GPIOTE_CHECK_PIN);
                            timer_capture_task_addr = nrf_drv_timer_capture_task_address_get(&timer, (nrf_timer_cc_channel_t)0);

                            err_code = nrf_drv_ppi_channel_assign(ppi_channel, gpiote_event_addr, timer_capture_task_addr);
                            APP_ERROR_CHECK(err_code);

              So, how to improve  the accuracy of nrf_drv_timer?

  • It's not clear to us what your problem is. You talk about accuracy, resolution, and drift, without giving us any numbers.

    What did you expect to observe and what did you actually observe? 


  • i am sorry for not do that. I use a timer(16 MHZ) to collect  a pulse waveform( 1s, 50% duty cycle )  through PPI.

    My collected data (capture value)  are shown below. 

    10646513  18682896 26718977 34756745  

    the first interval=(18682896-10646513)* 0.0625 *0.000001=0.5022739 s 

    the second =(26718977 - 18682896 ) * 0.0625 *0.000001= 0.50225063 s

    the  third =(34756745 - 26718977 ) * 0.0625 *0.000001= 0.5023605 s

     

    I suppose that the result of interval time  should be 0.5000000 s ,because the accuracy of timer is 0.0625 μs.

  • This makes things a bit clearer, but there's still some information that is lacking. 

    As I understand it you are using an external source to trigger either an EVENTS_IN or a EVENTS_PORT on a GPIO, but I do not know which. Have you configured the GPIOTE driver to use "high" or "low" accruacy? 

    And what source are you using to trigger the gpio pin? Is it a signal generator that operates at 1Hz? If so what's the frequency accuracy of that signal generator, in that mode, at that frequency?

    Another way to check the accuracy of the TIMER is to use it to trigger the toggling of a GPIOTE pin and analyze the period of the resulting waveform with an oscilloscope or digital analyzer. 

    You are also confusing the term accuracy with resolution. Accuracy or Tolerance, in regards to a clock source, is the deviation in frequency from its intended target, often measured in Parts Per Million. The nRF52832's 64 MHz internal oscillator (HFINT) has a tolerance of <+/-6% maximum, whereas the 64 MHz crystal oscillator (HFXO) has a tolerance given by the external crystal, most often +/- 40ppm. 

    If you're not using the HFXO as the clock source then you should expect a pulse width of 500ms +/- 30ms. 

    If you are using the HFXO as the clock source on the dev kit then you should expect a pulse width of 500ms +/- 30ppm = 500ms +/- 17ns

    The resolution is the frequency of the timer. The maximum frequency of the TIMER is 16MHz, or 62.5ns period.  

    The drift is the change in accuracy/tolerance over time or temperature( or any other operational parameter). 

    There's also jitter/phase noise, which is the variation in frequency from period to period, though this parameter is not really that important unless you're doing som really high-frequency stuff, like our 2.4GHz radio does.

  • Thanks for your reply .I have learned a lot  and I would show your more details about my configuration.

    Gpiote configuration:

       nrf_drv_gpiote_in_config_t in_config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(true);  // high accruacy
       in_config.pull = NRF_GPIO_PIN_PULLUP;

    Signal source of pulse waveform:

       using another DK borad with timer (16MHz ), toggle the level of pin in the  interrupt handler 

    Clock   configuration :   

            clock_start() 

               {   NRF_CLOCK->EVENTS_HFCLKSTATED = 0;    

                   NRF_CLOCK->TASKS_HFCLKSTART = 1;          // using HFXO

                  while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) ;  } 

    i am developing a project with  electricity meter which need high resolution  (several  ms ).

    Now ,i already   configured the GPIOTE driver to use "high"  accruacy and use  HFXO.

    After several repetitions there still remains an error. 

    There are other ways to improve the accruacy?

  • What is the period of the signal coming from the 2. DK if you measure it with an oscilloscope or digital analyzer?

    Something is definitely wrong, even the RTC should do < µs accuracy with the LFXO enabled.

Related