Andrew Boyson / clock

Dependents:   oldheating gps motorhome heating

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?

UserRevisionLine numberNew 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 }