View Single Post
  #1   Spotlight this post!  
Unread 13-01-2008, 16:16
Joe Ross's Avatar Unsung FIRST Hero
Joe Ross Joe Ross is offline
Registered User
FRC #0330 (Beachbots)
Team Role: Engineer
 
Join Date: Jun 2001
Rookie Year: 1997
Location: Los Angeles, CA
Posts: 8,590
Joe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond reputeJoe Ross has a reputation beyond repute
Re: Tracking Elapsed Time

Quote:
Originally Posted by kaszeta View Post
We've found using loop counters to be very inaccurate in the past.
We've found that loop counters are accurate enough for almost all applications. One way to make them better is to account for lost radio packets.

Code:
unsigned int loop_counter;

void timer(void) {

	static unsigned char prev_packet;
	unsigned char packets;

	if (rxdata.packet_num > prev_packet)
	{
		packets = rxdata.packet_num - prev_packet;
	}
	else
	{
		packets = 256 - prev_packet + rxdata.packet_num;
	}
  loop_counter += packets;
}
note: code not guaranteed to compile, done off the top of my head.