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

how to implement accurate milisecond function

I am new to nrf51822. I am trying to convert my Arduino code into NRF51822

I need something like this

currentMillis = micros(); //microseconds since the Arduino board began running if(currentMillis-past_time>=1000) { do something }

What is the best way to do this in NRF51822? Should I use RTC or go with simple timer? Can anyone share their function if they have already implemented?

Thanks

Parents
  • Here's another solution using Nordic's app_timer API to RTC1.

    uint32_t watchdog_timer;
    uint32_t app_timer_cur;
    uint32_t app_timer_diff;
    
    /* Set watchdog timer */
    app_timer_cnt_get(&watchdog_timer);
    
    /* Other processing occurs... */
    
    /* Check for a watchdog timeout */
    app_timer_cnt_get(&app_timer_cur);
    app_timer_cnt_diff_compute(app_timer_cur, watchdog_timer, &app_timer_diff);
    if (app_timer_diff > APP_TIMER_TICKS(WATCHDOG_TMOUT,APP_TIMER_PRESCALER))
    {
        /* Watchdog timeout */
    }
    

    WATCHDOG_TIMOUT is in milliseconds, here it is a constant but it could be a variable.

    The cnt_diff_compute function handles timer range and rollover. This of course has the same constraint that RTC1 is running when you are tracking elapsed time.

  • My problem was the 24 bit counter with a 32khz clock rolls over every 512s. I needed to keep track of time for the power on life of the device. You divide the 32khz down but it depends on how much resolution you need.

Reply Children
No Data
Related