I'm looking for a software timer library for embedded systems, especially PIC32, free or commercial. I'm NOT looking for a full-blown RTOS with threads, I/O, etc. - just for the software timer functionality.

The library should use one dedicated hardware timer, live in the interrupt domain and allow the scheduling of deferred and recurring call-backs.

Is anybody aware of such a library?

  • \$\begingroup\$ What is your application? \$\endgroup\$ – geometrikal Jan 15 '14 at 12:08

The Microchip’s TCP/IP stack has an implementation of such a timer library called the Tick Module. It's written for portability and supports the PIC18, PIC24, dsPIC & PIC32 devices.

From the Microchip TCP/IP Stack Help:

The Tick module provides accurate time-keeping capabilities based on the hardware clock. By default, it uses Timer 0 on 8-bit parts and Timer 1 on 16- and 32-bit families. The module is interrupt driven, which makes the timing stable and accurate. As such, it is also suitable for a real-time clock.

The Tick module exists to assist with the implementation of non-blocking delays and timeouts. Rather than using a loop to count to a specific number, use the Tick module and compare a previous time with the current time. In this fashion applications can return its unused cycles to the stack during long delays, which increases the overall efficiency of the system.

You'll just need to find the Tick.h and Tick.c files in the TCP/IP stack (download link, it's free) and modify them a bit to make them work independent of the stack.

  • \$\begingroup\$ It solves only a part of the problem. With this you can check whether a certain amount of time has passed. If the program is event driven this allow you to return to the main loop instead of busy waiting. But it does not give you deferred callbacks. \$\endgroup\$ – edgar.holleis Jan 15 '14 at 19:11
  • \$\begingroup\$ @edgar I agree, but it's the best I could think of.. \$\endgroup\$ – m.Alin Jan 15 '14 at 20:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.