Thread: System Clock?
View Single Post
  #7   Spotlight this post!  
Unread 11-02-2005, 13:29
Greg Ross's Avatar
Greg Ross Greg Ross is offline
Grammar Curmudgeon
AKA: gwross
FRC #0330 (Beach 'Bots)
Team Role: Mentor
 
Join Date: Jun 2001
Rookie Year: 1998
Location: Hermosa Beach, CA
Posts: 2,245
Greg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond reputeGreg Ross has a reputation beyond repute
Send a message via AIM to Greg Ross Send a message via Yahoo to Greg Ross
Re: System Clock?

Quote:
Originally Posted by devicenull
It's not 26.2ms, unless my conversion was wrong..
I had
(counter*26.2)/1000 or..maybe it was 10000
Which should give me seconds.. but didn't. Not too sure what was going on there, but it didn't seem that accurate
If you're going to use the loop time to keep track of elapsed time, you'll need to check the packet number, and account for missed packets (loops).

What happens is that if your code is too slow, it might not make it back in time to read the very next data packet, and thus might miss a loop.

What you need to do is to keep track of the packet number of the last data packet you read, and multiply the difference between that number and the current packet number by 26.2 before adding to your match timer.

BTW, DON'T multiply by 26.2 (a float). DO multiply by 262, and simply consider your match timer to be in units of 10ths of milliseconds instead of milliseconds. The same goes for any other floating point operations.

You need to realize that the PIC processor does not natively support floating point operations, and any floating point calculations you request will be performed in software -- which takes up more code space, AND takes MUCH longer. IF you are currently using floats, this COULD be why you are missing data packets, and why your timer was not accurate.

Better yet than multiplying by 262 is to not multiply at all! Just leave your timer in units of 26.2ms clock ticks. (You still need to account for missed packets.)

OK. this post is getting too long. If you need more details, just ask. (Or search. I'm pretty sure this has all been discussed before. )
__________________
Greg Ross (The Grammar Curmudgeon formerly known as gwross)
S/W Engineer, Team 330, the Beach 'Bots
<--The Grammar Curmudgeon loves this cartoon.
“Life should not be a journey to the grave with the intention of arriving safely in a pretty and well preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming "Wow! What a Ride!" Hunter S. Thompson
"Playing a practical joke means doing something mean and calling it funny." Me

Last edited by Greg Ross : 11-02-2005 at 13:31.