[Panda] Accurate time keeping

I know that alot has been written on this subject already, but I want to make sure I understand it and I want to ask you all if you’ve got another solution.

I want to use a panda for accurate time keeping using a Stopwatch kind of implementation. I’ve got an application where time keeping is critical but for short amounts of times. So it does not have to be precise over 24 hours but just for 3 minutes. The minimum accurary i require is about 10 ms) So i need to know two things:

1.Accurate time keeping over a period of time. (This can be done with the onboard RTC)
2.Allowing for a periodical update of the display with the time.

For step two there are a couple of different solutions as far as i’ve found out:

1.Using an expanded timer/Timer
I don’t what the base is that the Timer Expanded Timer class have so i cannot make a statement how precise these are. But because of what I read on other topics/online i think that because FEZ is not real time this method of timing isn’t very precise.

I’ve read that it CAN be done this way, but i’ve got a device that has to do a lot of things in a short period of time. So it would be nice if the generation of the tick event isn’t a responibility (and cannot be influenced by) the FEZ CPU.

2.Using a while(true) loop
It would work because it would continually check the Datetime.Now (or system time) but the same problem arise as with the first solution.

3.Using an external component as a timer (arduino/555) in combination with an interrupt port.
This would be an ideal solution for my problem but only if the handling of the interupts wouldn’t be affected (in a large way) by a busy CPU. Also i dont know the mimimum time required for a port to be switched from high to low.

4.Using an external component as a timer (arduino/555) in combination with a port in a while(true) loop.
The problem with this is that though the timing pulse is accurate it would be influenced by GC etc when reading it. And as far as i remember from school (i’ve got some experience using PIC/ATMEL) an interupt is always better than doing some ‘busy waiting’.

So my question to you all is: Is the above true and also are there any other solutions I didn’t think of? Also my understanding of programming is a lot better than electronics but I think i will manage. I’ve been working as a .Net developer for about three years and this is my first MF experience.

You can go the external route, but there is simpler ways.

The system timer should give you enough accuracy. Just store the start time and get the end time and subtract. Look at Ticks, I think it is in 100ns(?).

It shouldn’t matter how accurate your screen update interval is, as long as your counter in the back isn’t tied to the refresh rate, which it woun’t be if you use the system timer.

Also, one of the parameters on the button interrupt is the system time at which the interrupt occurred…

the “timer” functions are more for functions like… set- do nothing for a pre-defined time - come back. A stop watch type function (time between two “events”) is easy with just using basic time ticks as Errol mentions.

The real trick to getting accuracy here is how you trigger your events. If you can do that with interrupts, those events are timestamped and you can handle them as needed - and the GC shouldn’t interfere.

Here’s a good sample app (although a little old now) that is a stopwatch. [url]IAmRaf - Not Found

The real time “issues” with NetMF are more about needing to do precise timing control for things like signal waves; for low level human interaction things you’ll not find this to be a challenge.

Good luck

Thanks for the information Brett can you explain what you mean by:

With evens do you mean button events? Because the current implementation used interrupts already so that shouldn’t be a problem. I’ll keep using the timer class as a timer instead of the other solution.

To accurately determine a time between ‘events’ do I use the feature of the interrupt routine which the exact time (100ns) give at interrupt.

I use this to determine the distance of the SRF05 sensor.
The interrupt routine is simple.

       static void srfi_OnInterrupt(uint port, uint state, DateTime time)
            if (ticks == 0)
                ticks = time.Ticks;
                ticks = time.Ticks - ticks;

Upon request I can post here the complete test program

I purely mean your particular project or use-case will have some concept of start and stop events, whether that is from external buttons or some other human or electrical interaction; you haven’t really explained what that might be.

If the scenario you have is creating a stopwatch for human use, then using interrupts on a pushbutton, like the swim timer I mention, is probably a good way to go (the same as Hinnie uses). If it’s a stopwatch for mechanical or electrical events then again interrupts might work; but there may be other ways specific to what you are doing that might mean that is not the case.

The other thing is all about accuracy. If you’re timing needs only require 100ms accuracy then that is more simple than if you need to be accurate to 1ms or better. If you give us more background then we might be able to more effectively help guide you where needed

Look at RLP in new SDK http://www.tinyclr.com/forum/12/2491/

Thanks for the answers, RLP isn’t something I thought about.But i read the article mentioned in the post before.

The timers will be stopped and started by humans using buttons so using interrupts would be a wise idea for that. For generating a stable ms timer i’m using the normal Timer class.

It will be used for displaying a score in a Judo match. As far as i know there aren’t any specs saying that it should be ms accurate but I want to make sure that it’s as accurate a possible (in a reasonable amount of development time). The maxmimum length of a match is 3 minutes. I’m currently developing this code as a hobby so it’s a learning thing for me and because i program for a living i want it to be as good as i can make it.

The system time is very accurate for what you need

yep as Gus says, the system clock will be fine for this. You won’t see any drift worth talking about in 180 secs.

Thanks for the help all.