Hi, On Thursday 19 April 2007 05:53, Muhammad Azhar wrote: > Hi all, > I apologise if this is a rather basic question, but to set a timer to > fire exactly 1s periodically (using Timer<TMilli>), do I input > startPeriodic(1000) or startPeriodic(1024)? 'Coz all the while, I've > always used the former, but I realised that it's never 1 sec, always faster > than that. A colleague told me that using 1024 would make the timer fire > every 1 sec, but didn't explain why. Thus, I'd like to clarify with you > guys. How exactly does the 1024 convert to 1s? What if I'd like a timer > of 1min then? Many thanks for your help.
On the msp430 platforms, the millisecond virtual timer servicing Timer<TMilli> components uses Timer A. Timer A is configured to use SMCLK, which is set to DCO/4. The DCO is calibrated to 4*2^20 Hz, so Timer A's "1MHz" timer is in fact 2^20 Hz. Because the conversion from microseconds to milliseconds in the timer code effectively uses a 10-bit shift, 1 second is 2^10 ticks, or 1024. So, 1024 ticks/sec * 60 secs/min = 61440 ticks/min. 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. Cheers, Steve _______________________________________________ Tinyos-help mailing list [email protected] https://mail.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
