[Tinyos-help] Problems with Time Sync
Jose L. Ponce
martinez at tkn.tu-berlin.de
Tue May 2 12:38:58 PDT 2006
Hello,
I am trying to program a simple LTS Protocol to use with my TelosB
motes. The basic idea is to run this protocol from a computer and have
the computer process the results to keep track of the offsets of the
different motes. This is what happens:
- We get the computer time and send it to the mote. To do this we use
System.nanoTime(). Since we get a 64-bit long number with ns precision,
we trim it like this t1 = ((System.nanoTime()/1000)%10000000000) to give
it the same lenght as the numbers generated in the mote and microseconds
precision.
- The mote receives the message and timestamps it using the LocalTime
interface; we divide the LocalTime value through 0.032 to give it
microseconds precision, keeping into account that we are using a 32kHz
clock. This message is send back to the computer, where it is
timestamped again and the offset is calculated.
To test this Time Sync, I have a little program which will send messages
to the motes saying "turn your led on niw and turn it off in X seconds".
The idea is that all nodes should do it at the same time.
To do this, the message is sent and the time is calculated as turnOff =
System.nanoTime()/1000%10000000000 + offset(mote) + time interval (unit
is microseconds)
On the mote side, we make interval = turnOff-LocalTime/0.32 and we use
this interval to program a one shot timer, converting to miliseconds.
The problem is that this doesn't seem to work very well. The lights turn
on and off at shorter intervals every time and if I try to keep them on
for longer periods of time, say, 5 seconds, they will stay on and never
come off.
I suspect I might be using the wrong timers... Could anyone give me some
tips on how to make this work properly? I'd really appreciate it.
Thanks,
- Jose.
More information about the Tinyos-help
mailing list