Deferred callback manager / software timer library for PIC32

embeddedtimer

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?

Best Answer

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.