Santosh,

You are welcome to write a wrapper to map decimal milliseconds to
binary milliseconds for your uses in the way that you describe.
Binary milliseconds is the currently established convention in TinyOS
timer components, and there are no plans for this to change.  Though,
a network time library could choose to expose decimal milliseconds.

By the way, you can change the 32-bit multiply to bit shifts in your
sample code by writing this, which should be a little more efficient:

 (milli <<  5) + (((milli << 1) + milli) >> 2)

Cory

On 5/22/06, Santosh Godbole <[EMAIL PROTECTED]> wrote:
If that is the case, can we rewrite the code in the following manner?

command result_t Timer.start[uint8_t num]( char type, uint32_t milli )
{
        switch( type )
        {
                case TIMER_REPEAT:
                return setTimer( num, (milli <<  5) + ((milli * 768) >>
10) , TRUE );

                case TIMER_ONE_SHOT:
                return setTimer( num, (milli <<  5) + ((milli * 768) >>
10), FALSE );
        }
        return FAIL;
}

This will work for milli < 2^22. This will introduce some error (we are
dividing the second part of the expression by 1024 rather than 1000) but
the result will be closer to the desired value!!

Regards,
Santosh

-----Original Message-----
Message: 6
Date: Mon, 22 May 2006 11:16:14 -0700
From: "Cory Sharp" <[EMAIL PROTECTED]>
Subject: [Tinyos-help] Re: Timer accuracy.
To: Mala <[EMAIL PROTECTED]>
Cc: [EMAIL PROTECTED], [email protected]
Message-ID:
        <[EMAIL PROTECTED]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi Mala,

It is (poorly) documented that the millisecond timer is in "binary
milliseconds" -- or 1024 ticks every second.  This is the designed and
expected behavior, not a bug, and will not change in the future.  Most
embedded devices do not have floating point support in hardware, so any
floating point operation is slow, and the floating point library takes a
lot of program space.

Look up TinyOS 2.x TEP 102 Timers for more details.

Best,
Cory

On 5/22/06, Mala <[EMAIL PROTECTED]> wrote:
> I was writing a simple program to send a periodic message and ran them

> on tmotes.  That time, I noticed that the messages were appearing at
> an interval of 5.85 seconds instead of the 6 seconds that I had
> programmed.  On further debugging I noticed that the following code in
Timer library
>   command result_t Timer.start[uint8_t num]( char type, uint32_t milli
)
>   {
>     switch( type )
>     {
>       case TIMER_REPEAT:
>         return setTimer( num, milli*32, TRUE );
>
>       case TIMER_ONE_SHOT:
>         return setTimer( num, milli*32, FALSE );
>     }
>
>     return FAIL;
>   }
>
> Here per millisecond is considered to be 32 ticks, while it actually
> is 32.768 ticks.  This error led to the difference that I noticed in
> the timing of my messages.
>
> Why is this done?  Is there any particular reason for doing an integer

> operation where we should be doing a floating point operation?  Is
> there any plan to fix the same?
>
>
> Regards,
> Mala
>



------------------------------

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


End of Tinyos-help Digest, Vol 37, Issue 92
*******************************************


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

Reply via email to