On Apr 19, 2007, at 7:37 AM, Steve McKown wrote:

H

In case you're wondering why it's set up this way: converting between powers of 2 needs only fast bit shifts. Far more efficient than, say, dividing by
1000.


Actually, the reason has more to do with error and the effort/cost it would take to handle it. If you want 1kHz rather than 1.024kHz units, then you need to convert. Here's a modified version of a post I sent to the EmStar list a while back, when someone suggested just doing this ((timer * 1024) / 1000):

The issue is whether you want precise 1024Hz timers or imprecise 1000Hz timers. You can get reasonably precise 1000Hz timers, but only if you are willing to do a bit of bookkeeping to keep track of partial ticks.

E.g., imagine a user specifies a 999ms timer. The closest thing in 1024Hz (the underlying clock) is 1023 ticks. So your timer starts firing every 1023/1024 ticks. Now imagine another component asks for a 111ms timer. The closest thing is 114 ticks. But 114 * 9 = 1026; the two timers will slowly move out of phase, although 999 mod 111 = 0.

Now imagine a frequency hopping scheme that (for some reason...) has a period of 999ms and breaks it up into 9 slots of 111ms. A node that is active for all slots and so fires a periodic timer every 111 ms will have time progress differently than a node which is wake for one slot and fires a timer every 999ms. Even if you could calibrate the crystals and figure out the temperature-to-skew function (poster on this at SenSys this year), you still have timer shifts that are *dependent on the values you pass to the timer* rather than the nodes themselves.

You can get rid of these imprecisions by tabulating the fact that 111ms is actually 123.64 ticks, and so keep track of partial ticks. But for the complex cases, I would expect that this is enough cycles that it slows down your maximum timer firing rate. And any tiny errors will creep over time.

Besides interoperability with devices that operate with true millisecond granularity, it's not clear to me what the benefit of having a interval-1000 timer is, besides the comfort of thinking in decimal rather than binary.

Phil

_______________________________________________
Tinyos-help mailing list
[email protected]
https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help

Reply via email to