WDT and System.getTimer() Behavior on Hardware

Would anyone be curious about trying the example below on hardware using CIQ_LOG.txt? Running SDK 1.1.0 on my laptop, it fails with a WDT timeout for values of SPIN_MILLIS > 7, but I'm wondering how it fares on a real device. I'm curious when the WDT would trip and also whether getTimer() will really provide updates every millisecond.

function onShow() {
var currentTimer = Sys.getTimer();
var lastTimerMillis = currentTimer;
var SPIN_MILLIS = 10;

for(var i = 1; i <= SPIN_MILLIS; i++) {
while(currentTimer == lastTimerMillis) {
currentTimer = Sys.getTimer();
}
lastTimerMillis = currentTimer;
Sys.println(i);
}
}
  • I'll test it, but I'm fairly certain that we'll find that getTimer() returns a virtual timer. i.e., you can call it many times in a loop and the value won't change.
  • I'm wrong... Big surprise.

    Code runs fine on my 920XT. I modified your code slightly to display the timer value in addition to the outer loop count. This code

    var currentTimer = Sys.getTimer();
    var lastTimerMillis = currentTimer;
    var SPIN_MILLIS = 10;

    for(var i = 1; i <= SPIN_MILLIS; i++) {
    while(currentTimer == lastTimerMillis) {
    currentTimer = Sys.getTimer();
    }
    lastTimerMillis = currentTimer;
    Sys.println(i + ": " + currentTimer);
    }


    Produces this output in Garmin/APPS/LOGS/Test.txt...

    1: 380355846
    2: 380356231
    3: 380356496
    4: 380356715
    5: 380356934
    6: 380357152
    7: 380357365
    8: 380357586
    9: 380357806
    10: 380358031
  • That is interesting; thanks for trying. Now I'm wondering what would happen if we moved Sys.println() out of the loop and stored the values in an array instead since the I/O may be expensive: I was surprised to see 200-300 mS between each timer change. Still, it looks like the real HW will run for at least a couple of seconds without a WDT trip.
  • I hacked this together for you:

    for( var i = 0; i < SPIN_MILLIS; i++ ) {
    while(currentTimer == lastTimerMillis) {
    currentTimer = Sys.getTimer();
    }
    lastTimerMillis = currentTimer;
    millisArray= currentTimer;
    }

    for( var i = 0; i < SPIN_MILLIS; i++ ) {
    Sys.println( i + ": " + millisArray);
    }
    [/CODE]

    Looks like the timing is much tighter without the i/o:

    0: 2164097
    1: 2164098
    2: 2164100
    3: 2164102
    4: 2164103
    5: 2164105
    6: 2164108
    7: 2164109
    8: 2164111
    9: 2164113

    0: 2166253
    1: 2166255
    2: 2166257
    3: 2166259
    4: 2166260
    5: 2166262
    6: 2166264
    7: 2166265
    8: 2166267
    9: 2166269

    0: 2168404
    1: 2168406
    2: 2168408
    3: 2168410
    4: 2168411
    5: 2168414
    6: 2168416
    7: 2168417
    8: 2168419
    9: 2168421
  • Thanks, Brandon. I was going to try this now that I have hardware to work with, but you beat me to it.