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

Start 2 timers in 1 instructions? (nRF52)

Hi all!

TL;DR

Is there a way to start 2 timers in 1 instructions? (or to synchronize them afterward?)

- - -

Background

I need to take 8 timestamps of GPIO edges using PPI events/tasks (more explanations here).

This needs 2 timers as they don't have more than 4 (or 6) capture registers each.

To have coherent timestamps, the timers should start simultaneously, and I'm looking for a good way to do it.

- - -

1st idea

It seems unlikely that a simultaneous start is possible as they have different register addresses, ex:

TIMER1: 0x40009000 

TIMER2: 0x4000A000

But as they are running at 16MHz and the core runs at 64MHz, it might not be impossible that the 2 start request happen simultaneously:

nrf_timer_task_trigger(NRF_TIMER1, NRF_TIMER_TASK_START);
nrf_timer_task_trigger(NRF_TIMER2, NRF_TIMER_TASK_START);

Should I use a PPI event to reset both timers in the same time? (it seems complicated but maybe the most appropriate)

- - -

2nd idea

Maybe there's a reliable way to check that the 2 timers are synchronized, and if not, copy the value of one in the other?

- - -

Does anyone have any suggestion?

Thanks a lot!

Cedric ;)

Parents
  • Hi,

    The first idea using PPI seems like the best way to do this. PPI supports a feature called "FORK" which enable you to cause a single event to start two timers. This will allow you to start both of the timers at the same time and not end up with a one CPU clock cycle offset.

    While PPI may seem a bit complicated it often turns out to be the far simplest solution when you need precise concurrency. (It's also very low power compared to using the CPU)

    Best regards,
    Rune Holmgren

Reply
  • Hi,

    The first idea using PPI seems like the best way to do this. PPI supports a feature called "FORK" which enable you to cause a single event to start two timers. This will allow you to start both of the timers at the same time and not end up with a one CPU clock cycle offset.

    While PPI may seem a bit complicated it often turns out to be the far simplest solution when you need precise concurrency. (It's also very low power compared to using the CPU)

    Best regards,
    Rune Holmgren

Children
Related