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

events (interrupts) from timer

Dear sirs!

I need that timer (for example timer 3 or 4) will generate interrupt each 5 ms very precisely with precision of crystal (20 ppm). In 10 hours I cannot allow deviation more than 1 second.

I cannot reload timer registers in interrupt routine because it will cause unpredictable delays. I need that timer will reset to 0 automatically when arrive compare register value. Or may be there is another way to do it

 

What is the best way to do it with lower power consumption? Do you have any example?

Unfortunately, I cannot find how to do it.

Parents
  • Hi,

    The TIMER peripheral have SHORTS from each COMPAREx event to the CLEAR task, which means that the TIMER will be cleared when the event is generated, if the corresponding short is enabled. This happens in HW, which means there is no delay from handling it in interrupt handler. 

    You can enable the short using the timer driver API nrf_drv_timer_extended_compare()/nrfx_timer_extended_compare(), where you pass NRF_TIMER_SHORT_COMPAREx_CLEAR_MASK to the 4th argument (timer_short_mask).

    Note that the TIMER peripheral is not particularly low power, as it requires the 16 MHz HFCLK to be running. The current consumption will typically be in the 3-500 uA range.

    To achieve low power, you need to use the RTC peripheral, which runs off the 32.768 kHz LFCLK. This will give you much lower resolution (~30.5 us), which may not be enough for your requirements. You can set the PRESCALER to 163, which will give you a period of 164/32768=0.00500488281s, or ~4.88us off your desired period for each event. For a 10 hour period, this will accumulate to ~35s (10h*60min*60sec*200periods/s*4.88us=35.14s). This is without accounting for the accuracy of the crystal/clock source.

    Best regards,
    Jørgen

  • 1. I need clock 1MHz. As I wrote, deviation shall be less than 1 second in 10 hours. It shall be absolutely precise  value. 

    Yes, that is not possible with the RTC. If you run the TIMER with 1 MHz frequency, the current is reduced a bit, but the current would still not be low power (See TIMER running for nRF52840 numbers).

    2. My product is about 6 years old and based on SDL 12.2 beta. Functions that you mentioned are not available in this SDK.

    nrf_drv_timer_extended_compare() is present in both nRF5 SDK v12.1.0 and v12.2.0, so I'm sure it is available in your SDK version as well (components\drivers_nrf\timer\nrf_drv_timer.h)

    3. I am not sure about compare value. If I use clock 1MHz and need interrupt  each 5000 uS, shall I set in compare register 5000 or 4999? It is not clear if one clock system need to reset timer to 0? It is critically important, because this mistake can cause more than 7 seconds deviation in 10 hours

    5000 should be correct. The TIMER is not stopped, the counter is just cleared to 0 and it will increase to 1 on the next tick.

Reply
  • 1. I need clock 1MHz. As I wrote, deviation shall be less than 1 second in 10 hours. It shall be absolutely precise  value. 

    Yes, that is not possible with the RTC. If you run the TIMER with 1 MHz frequency, the current is reduced a bit, but the current would still not be low power (See TIMER running for nRF52840 numbers).

    2. My product is about 6 years old and based on SDL 12.2 beta. Functions that you mentioned are not available in this SDK.

    nrf_drv_timer_extended_compare() is present in both nRF5 SDK v12.1.0 and v12.2.0, so I'm sure it is available in your SDK version as well (components\drivers_nrf\timer\nrf_drv_timer.h)

    3. I am not sure about compare value. If I use clock 1MHz and need interrupt  each 5000 uS, shall I set in compare register 5000 or 4999? It is not clear if one clock system need to reset timer to 0? It is critically important, because this mistake can cause more than 7 seconds deviation in 10 hours

    5000 should be correct. The TIMER is not stopped, the counter is just cleared to 0 and it will increase to 1 on the next tick.

Children
No Data
Related