Imp.wakeup on imp004m breakout


#1

Is the imp004m imp.wakeup() inaccurate on the muRata breakout board? It seems to be a couple of seconds off over a 60 second timer. This board does have a 32kHz crystal, correct? For example, this code:

prev <-0;
prev_us <-0;


function loop() {
    local now = time();
    local now_us = hardware.micros();
    local delta = now - prev;
    local delta_us = now_us - prev_us;
    prev = now;
    prev_us = now_us;
    imp.wakeup(60,loop);
    server.log(delta+" "+delta_us/1.0e6);
    
}

loop();

Gives this log:

2017-11-08 15:59:08 +11:00	[Device]	58 60.0126
2017-11-08 16:00:07 +11:00	[Device]	59 60.0026
2017-11-08 16:01:05 +11:00	[Device]	59 60.0126
2017-11-08 16:02:04 +11:00	[Device]	59 60.0122
2017-11-08 16:03:03 +11:00	[Device]	59 60.0125
2017-11-08 16:04:02 +11:00	[Device]	58 60.0026

On the imp002, it’s bang on 60 seconds. Is the imp.wakeup() running off the micros timer instead of the 32kHz clock on the imp004m, which is what the timing info above seems to suggest.


#2

imp.wakeup (and hardware.micros) both come from the 26MHz clock; time() comes from the 32kHz RTC.

You’d expect a little over 60s 26MHz time (ie your microsecond time) due to the imp.wakeup() happening at the end of the function - this will drift by the execution time (putting it at the start would minimize this).

I’d still expect time() to report 59 or 60 ticks in this period though, not 58. Even if both xtals were 30ppm out in different directions (ie 60ppm differential) this is only tens of milliseconds 32kHz slip vs 26MHz.

@peter any ideas?