I can offer you ideas only.
If you're comfortable with interrupts, get a timer to ring every 1mS and keep tracking a variable that increments every ring and then use that variable that throughout your program. Use this as the reference timer for everything on your system.
Other way, you use a hardware timer and poll it for overflow every fractional time. Then count a number of fractions equal to the 2 seconds you require. This does not need interrupts, but will block till the timer overflows
Bookmarks