Page 1 of 1

High Speed Tickless timers?

Posted: Sat Nov 10, 2018 9:32 am
by steved
Thoughts triggered by some work on a 32L071, with systick 1000usec, which is fine for 99% of use.
I need to generate one-shot time intervals in the range of 100-5000usec, with a resolution of, say, 10usec. Potentially I could have several timers running in parallel (although that would be unusual). Obviously out of the range of polledDelay() function.
Essentially what it needs is to clone the virtual timer code, but running off a faster hardware timer.
Any thoughts on the practicalities of this?
(I can see the obvious - that these timers would need to be used sparingly, otherwise the overhead would become very significant)

Re: High Speed Tickless timers?

Posted: Mon Nov 12, 2018 1:27 pm
by Giovanni
Hi,

Non sure about your requirements but 10uS is a bit extreme for an M0, probably you cannot do that using virtual timers.

What you could do is to enable the unused 3 comparators in the ST driver and use those like 3 extra timers working with the same resolution of ST.

Giovanni

Re: High Speed Tickless timers?

Posted: Mon Nov 12, 2018 2:51 pm
by steved
I could manage with a slightly higher minimum resolution - up to about 100 usec, maybe.

Unless I've missed something, systick of 1000usec sets the minimum timing resolution - I don't want to speed up systick, and I could do with better resolution.

I can code a dedicated solution; but a generic solution would be cleaner.

Re: High Speed Tickless timers?

Posted: Mon Nov 12, 2018 3:37 pm
by Giovanni
I think 50..100uS would be viable, it depends on time spent in callbacks/ISRs.

You could have significant jitter anyway, even using an HW solution.

Giovanni

Re: High Speed Tickless timers?

Posted: Fri Dec 14, 2018 6:59 pm
by steved
Had a go at this, with very satisfactory-looking results. I've settled on a 1usec resolution and minimum time of 100usec for now. Running 3 timers on a 32MHz 32L031 the jitter is 1usec - very stable. (Although that is with just a 'blinky' thread running as well).
Code attached in case anyone wants a play - its basically a mangled version of the Chibi virtual timers.

A more efficient approach would undoubtedly be to limit myself to four comparators off a fast counter (which is ample for my application), but I thought I would try the general solution first.