Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   Programming (http://www.chiefdelphi.com/forums/forumdisplay.php?f=51)
-   -   Tracking Elapsed Time (http://www.chiefdelphi.com/forums/showthread.php?t=61581)

7-11number1 13-01-2008 13:58

Tracking Elapsed Time
 
Our team is getting better at programming using MPLAB and I had a question:

1. What is the best way to track elapsed time?

For example, the the main loop running on the RC is fast enough to loop (3) times each time the IR board receives an input then sends out a pulse. We would like to create a timer and ignore any other pulses from the IR board for a 500ms window to prevent processing the same signal (3) times.

I wasn't sure if the RC had an internal clock which could be read and stored into a variable.

Good Luck!
TEAM #1711
Traverse City, MI

Kevin Sevcik 13-01-2008 14:13

Re: Tracking Elapsed Time
 
The PIC has several onboard hardware timers you could use for this, but I think just counting passes through the main loop would be much simpler for this application.

If you really want to use a hardware timer for this, look at this IFI whitepaper. A polled timer should be good enough for your purposes, so you'd setup the timer in your initialization, then you'd start it and pre-load the correct values when you saw a pulse. as long as the interrupt flag is 0, it hasn't timed out and you should ignore pulses.

kaszeta 13-01-2008 16:06

Re: Tracking Elapsed Time
 
Quote:

Originally Posted by Kevin Sevcik (Post 676949)
The PIC has several onboard hardware timers you could use for this, but I think just counting passes through the main loop would be much simpler for this application.

We've found using loop counters to be very inaccurate in the past. Writing a hardware timer isn't difficult. We've done it several ways, ranging from using someone else's pre-package code, to writing our own routines last year.

See http://www.chiefdelphi.com/forums/sh...ad.php?t=54948 for a previous discussion on the topic.

cobrawanabe1699 13-01-2008 16:09

Re: Tracking Elapsed Time
 
Use the same tpe of system the NHRA uses for ETs. they can handle a 26-foot car at 330 MPH right down to thousanths of a second

Joe Ross 13-01-2008 16:16

Re: Tracking Elapsed Time
 
Quote:

Originally Posted by kaszeta (Post 677054)
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.


All times are GMT -5. The time now is 13:47.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi