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
scan/scan.c@40:53666b1a5848, 2018-12-04 (annotated)
- Committer:
- andrewboyson
- Date:
- Tue Dec 04 12:26:27 2018 +0000
- Revision:
- 40:53666b1a5848
- Parent:
- 39:5b594b1b6a0a
Renamed timer to hrtimer; added clktimer to handle utc based times.
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| andrewboyson | 36:6a8a8e1951d4 | 1 | #include <stdint.h> |
| andrewboyson | 40:53666b1a5848 | 2 | #include "hrtimer.h" |
| andrewboyson | 36:6a8a8e1951d4 | 3 | |
| andrewboyson | 36:6a8a8e1951d4 | 4 | uint32_t ScanAverage = 0; |
| andrewboyson | 36:6a8a8e1951d4 | 5 | uint32_t ScanMinimum = 10000; |
| andrewboyson | 36:6a8a8e1951d4 | 6 | uint32_t ScanMaximum = 0; |
| andrewboyson | 36:6a8a8e1951d4 | 7 | |
| andrewboyson | 36:6a8a8e1951d4 | 8 | void ScanMain() |
| andrewboyson | 36:6a8a8e1951d4 | 9 | { |
| andrewboyson | 36:6a8a8e1951d4 | 10 | //Establish this scan time |
| andrewboyson | 39:5b594b1b6a0a | 11 | static uint32_t scanTimer = 0; |
| andrewboyson | 36:6a8a8e1951d4 | 12 | |
| andrewboyson | 39:5b594b1b6a0a | 13 | bool firstScan = !scanTimer; |
| andrewboyson | 36:6a8a8e1951d4 | 14 | |
| andrewboyson | 40:53666b1a5848 | 15 | uint32_t elapsed = HrTimerSinceRepetitive(&scanTimer); |
| andrewboyson | 36:6a8a8e1951d4 | 16 | |
| andrewboyson | 36:6a8a8e1951d4 | 17 | if (firstScan) return; |
| andrewboyson | 36:6a8a8e1951d4 | 18 | |
| andrewboyson | 36:6a8a8e1951d4 | 19 | //Average the scan time |
| andrewboyson | 36:6a8a8e1951d4 | 20 | if (elapsed > ScanAverage) ScanAverage++; |
| andrewboyson | 36:6a8a8e1951d4 | 21 | if (elapsed < ScanAverage) ScanAverage--; |
| andrewboyson | 36:6a8a8e1951d4 | 22 | if (elapsed > ScanMaximum) ScanMaximum = elapsed; |
| andrewboyson | 36:6a8a8e1951d4 | 23 | if (elapsed < ScanMaximum) ScanMaximum--; |
| andrewboyson | 36:6a8a8e1951d4 | 24 | if (elapsed < ScanMinimum) ScanMinimum = elapsed; |
| andrewboyson | 36:6a8a8e1951d4 | 25 | } |