Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Time in Milliseconds (http://www.chiefdelphi.com/forums/showthread.php?t=82592)

frenchie4111 02-13-2010 03:03 PM

Time in Milliseconds
 
We are trying to program our robots kicker and we are having a problem with inacurate time delays because we can not get the time in milliseconds.

bronxbomber92 02-13-2010 03:24 PM

Re: Time in Milliseconds
 
What are you using currently to get the time?

GetTime() has nanosecond resolution, Timer::GetFPGATimestamp() has microsecond resolution, and the Timer class has microsecond resolution.

taichichuan 02-13-2010 03:28 PM

Re: Time in Milliseconds
 
Hmm... Well, I'm sure that there's something buried in the WPILib that can do it for you like using the time() function. But, from a VxWorks perspective, you can issue a:

-> sysClkRateGet()

This will tell you the interrupt rate of the system clock. And, sysClkRateSet(100) would set the interrupt rate to 100 Hz (10 ms clock resolution).

With that, tickGet() will return the current clock tick count with subsequent calls allowing you to measure elapsed time to the resolution of the system clock.

And, taskDelay(1) is a delay of 1 clock tick (10 ms at 100 Hz). You can also create watchdog timers that will attach your code to the system clock interrupt service routine and run it at a specified delay. Again, I'm sure that there's something buried in the WPILib that can provide what you're looking for, but I know VxWorks a lot better than I know the WPILib.

HTH,

Mike

frenchie4111 02-13-2010 03:30 PM

Re: Time in Milliseconds
 
Quote:

Originally Posted by bronxbomber92 (Post 919406)
What are you using currently to get the time?

GetTime() has nanosecond resolution, Timer::GetFPGATimestamp() has microsecond resolution, and the Timer class has microsecond resolution.

Oh we were using the time class (time.h). We did not notice the timer class.

Greg McKaskle 02-13-2010 06:47 PM

Re: Time in Milliseconds
 
By the way, changing the resolution of the clock using low level VxWorks routines may wreak havoc on the timing of the rest of the system. Obviously you can do so, but do it carefully and test well.

Greg McKaskle

byteit101 02-13-2010 07:02 PM

Re: Time in Milliseconds
 
use Wait(double seconds);
or a Timer

mikets 02-22-2010 05:56 AM

Re: Time in Milliseconds
 
BTW, in case you haven't found an optimal solution, I just implemented a GetMsecTime() macro today. The timer object seems a bit heavy to me. This is simple yet functional.
Code:

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

slavik262 02-22-2010 08:47 AM

Re: Time in Milliseconds
 
If you want something simple and fast, use the standard C library's ctime (also known as time.h).

the function clock() returns the amount of ticks that have passed since your program started running as a clock_t value. The amount of ticks per second is defined in the macro CLOCKS_PER_SEC. Using this and some simple dimensional analysis, you can easily get how many miliseconds have passed between two clock() calls.


All times are GMT -5. The time now is 10:23 AM.

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