7 years, 10 months ago.

Are there any potential problems using multiple Tickers that may fire at the same time?

Just curious about how exactly the Ticker interface behaves:

If I setup 2 tickers, say one at 2s and another at 1s, would the two interrupt routines ever fire simultaneously and collide or cause one ticker to be ignored?

What if I setup hundreds of tickers all firing at similar times? Is it impossible to cause problems with too many tickers firing?

I suppose all of this leads to a question about best practice: Suppose I have 3 peripheral devices that need polling at different rates. Am I better-off setting-up 3 specific tickers for each peripheral and it's polling rate? Or is it better to make one "master" ticker that would cause polling at different rates by keeping count of how many times it has been fired?

Any insightful responses welcome! :-)

1 Answer

7 years, 10 months ago.

Quote:

If I setup 2 tickers, say one at 2s and another at 1s, would the two interrupt routines ever fire simultaneously and collide or cause one ticker to be ignored?

Nop, one would fire directly after the other. Obviously if the order is important, don't set them for the same time ;).

Quote:

What if I setup hundreds of tickers all firing at similar times? Is it impossible to cause problems with too many tickers firing?

The only important part is that Tickers are interrupts. So during Tickers no other interupts can be handled, and also your main code is not being executed. It will work perfectly fine, but nothing else will happen during the time it takes to process those Tickers.

Quote:

I suppose all of this leads to a question about best practice: Suppose I have 3 peripheral devices that need polling at different rates. Am I better-off setting-up 3 specific tickers for each peripheral and it's polling rate? Or is it better to make one "master" ticker that would cause polling at different rates by keeping count of how many times it has been fired?

Option A: It is easier and more robust. Only if you have them firing at very high frequency it might make sense to not use several Tickers, but in principle just go for A.

Accepted Answer

Thanks for the input! Tickers galore it is then.

:-)

posted by CJ Shaw 01 Jul 2016

So unfortunately after having followed this multi-ticker approach I've hit an apparent snag with the nRF51822+mbed combo in particular.

It appears this device has always had problems with the Ticker function and these problems have only been squashed down to a point where they are v. unlikely to happen.

Unfortunately this has been happening for me. Somehow the Tickers are colliding/misfiring or interrupts are not getting caught when soft devices or other interrupt-driven code is present & you get a bit unlucky...

There is a github issue here which links to previous/related bugs: https://github.com/mbedmicro/mbed/issues/1533

I may make an mbed question soon too to see if more find it.

posted by CJ Shaw 12 Jul 2016

The NRF is indeed a completely different issue. I know of at least one race condition in its timer code, although I don't know if that is the reason for your issue.

posted by Erik - 13 Jul 2016