Quote:
Originally Posted by kaszeta
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.