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

What is more efficient use nrf_delay_us or TIMER HFCLK for 1 us

Hi there,

How in the question title, what could be more efficient? use a nrf_delay_us or Timer with HFCLK source.

I am creating a custom protocol to transfer data between the nRF52 and AVR microcontroller, but the sequences times requires 1us

I understand using the nrf_delay_us the CPU to create the delay for X time.

but, using the Timer with HFCLK source could use between  5 - 70 uA. if I use it I will require turn off the timer because the protocol will run only when the nRF52 wakes up

which one is better?

  • Hello,

    As you found out, yes, it should work with app timer as long as they do not use the same timer instance. The example above uses TIMER2 and TIMER3.

    The EGU can be used if you need a timeout handler in the application layer. Everything that you see in the PPI runs independently of the rest of your application, as soon as it is initialized, and the timer is started.

    So if you need to run a function, e.g. called "my_timeout_handler", you can run this inside SWI0_EGU0_IRQHandler();

    If you do not need this, you can disable the EGU.

    As I mentioned, you can change this to work only with one timer, by setting the correct prescaler and time out after an amount of ticks, but I thought it would be better to illustrate the 1µs ticks this way (and it is easier to strip down this code, than to add to it, since it is a bit hard to find in the documentation).

    As you say, yes, the PPI is independent of the CPU. You can use it for bitbanging, but you would have to play around with the different CCs (capture/compare registers) Note that TIMER3 and 4 has the most capture compare registers, as described here,

    You can use the GPIOs as events/tasks for the ppi as well. You can see that they are both set up as GPIOTE_CONFIG_MODE_Task, but set them to GPIOTE_CONFIG_MODE_Event to use them as "inputs", and you can use them as TEP(task) instead of EEP(events).

    BR,

    Edvin

  • Wow it is very interesting I would like to use the SWI1_EGU1_IRQHandler instead of SWI0_EGU0_IRQHandler because it is used for the app_timer(RTC1). But the documentation is veey poor regarding it.

  • I could agree to you at some level here. It is only described what registers to use, so it is a bit hard to read a "how to" for this subject.
    The EGUs registers are listed here. I have not used this too much myself, but you can see that each EGU has several tasks trigger registers, and several event triggers, so you may be able to use the same EGU as app_timer, if you use a free task and trigger.

Related