High Speed Tickless timers?

This forum is dedicated to feedback, discussions about ongoing or future developments, ideas and suggestions regarding the ChibiOS projects are welcome.
steved
Posts: 600
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 74 times

High Speed Tickless timers?

Postby steved » Sat Nov 10, 2018 9:32 am

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)

User avatar
Giovanni
Site Admin
Posts: 12026
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 455 times
Contact:

Re: High Speed Tickless timers?

Postby Giovanni » Mon Nov 12, 2018 1:27 pm

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

steved
Posts: 600
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 74 times

Re: High Speed Tickless timers?

Postby steved » Mon Nov 12, 2018 2:51 pm

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.

User avatar
Giovanni
Site Admin
Posts: 12026
Joined: Wed May 27, 2009 8:48 am
Location: Salerno, Italy
Has thanked: 543 times
Been thanked: 455 times
Contact:

Re: High Speed Tickless timers?

Postby Giovanni » Mon Nov 12, 2018 3:37 pm

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

steved
Posts: 600
Joined: Fri Nov 09, 2012 2:22 pm
Has thanked: 4 times
Been thanked: 74 times

Re: High Speed Tickless timers?

Postby steved » Fri Dec 14, 2018 6:59 pm

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.
Attachments
Chibi_Fast_Timers.7z
(18.13 KiB) Downloaded 24 times


Return to “Development and Feedback”

Who is online

Users browsing this forum: mattf and 1 guest