Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: oldheating gps motorhome heating
Diff: timer.c
- Revision:
- 31:f6ff7fdb9c67
- Parent:
- 30:212ca42b8779
- Child:
- 33:b9e3c06e7dab
diff -r 212ca42b8779 -r f6ff7fdb9c67 timer.c
--- a/timer.c Fri Feb 16 17:30:46 2018 +0000
+++ b/timer.c Thu Nov 29 16:51:19 2018 +0000
@@ -47,13 +47,25 @@
return (value * fraction) >> 32;
}
-bool TimerTicked = false;
+bool TimerHadSecond = false;
+
+//Counts from zero to 2^32 and wraps around after:
+// 13.7 years if 10 per second - scan time must be less than 100mS
+// 1.37 years if 100 per second - scan time must be less than 10mS
+uint32_t TimerTicks = 0;
void TimerMain()
{
- TimerTicked = TimerCountSinceLastSecond() > TIMER_COUNT_PER_SECOND;
+ TimerHadSecond = TimerCountSinceLastSecond() > TIMER_COUNT_PER_SECOND;
+ if (TimerHadSecond) secondsBaseCount += TIMER_COUNT_PER_SECOND;
+
+ static uint32_t tickBaseCount = 0;
- if (TimerTicked) secondsBaseCount += TIMER_COUNT_PER_SECOND;
+ if (TC - tickBaseCount > TIMER_COUNT_PER_SECOND / TIMER_TICKS_PER_SECOND)
+ {
+ TimerTicks++;
+ tickBaseCount += TIMER_COUNT_PER_SECOND / TIMER_TICKS_PER_SECOND;
+ }
}
void TimerInit()
{