Time/timer function

Hello,

I am trying to include a time/timer function so that in a while loop I can keep track of how long it has been and still being able to run other code.

Also I would like to use it so that when I press a joystick button, the button is disable for say 1 second (so that it only registers 1 press and not registering from consistent pressing).

Could demonstrate how this function works?

Thanks,
Davis

The boolean expression

(button_is_pressed && button_was_not_pressed_in_previous_iteration)

does what you want.

It’s true only in the iteration immediately after the button is pressed, and doesn’t become true again until the button is released and pressed again.

Thanks, that helps a lot!

Although I am still interested in learning how to use the time/timer feature.

I’m not sure if there is a specific function that can be used as a timer, or if I have to get the time off the cRIO (if possible) and do my own math.

Thanks!

I use this macro.


#define GetMsecTime()           (GetFPGATime()/1000)

So i just add the #define up with the includes and use the function wherever I need to and do the math from there.

Thanks.

That’s right. Typically, it looks like this:


UINT32 startTime = GetMsecTime();
//
// Do something that you want to time.
//
printf("Elapsed time = %d msec
", GetMsecTime() - startTime);

There is also a Timer class, but I don’t like it much. Remember to call the Start() method if you use it.