Very accurate timing functions

I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.

My searches of QNX4 documentation did not reveal any such facility, unfortunely.
However, I noticed that QNX also uses Timer 0 for generating its timer pulses.
My question is whether reading the value of that timer, in combination with
the clock_gettime() function would be a reasonable way to obtain the accuracy
I would like. Would reading Timer 0 mess up anything in the kernel? It seemed
to me like Timer 0 is initially setup in Mode 3, which decrements by 2 at every clock
cycle. However, when I use clock_setres(), it seems to put it in Mode 2. Is this
always so?

Also, is there any way to get something like the “count of system ticks” since
the start of the system? In conjunction with the value of Timer 0, that would
give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.


Uluc SARANLI, Graduate Student Research Assistant

Advanced Technology Laboratory, The University of Michigan
Room 139, 1101 Beal Ave. Ann Arbor, MI 48109-2110
Tel : (734) 763-1572 Fax:(734) 763-1260
E-mail : ulucs@eecs.umich.edu
URL : http://www.eecs.umich.edu/~ulucs

I am not sure if this is 100% correct, but it seems to be operational.
What nice robot are you dealing with ?
Happy new year,
andy@microstep-mis.sk

// must be compiled with -T1 option, otherwise SIGSEGV follows after call

#include <stdio.h>
#include <i86.h>
#include <sys/osinfo.h>

struct ostime {
unsigned long sec;
unsigned long nsec;
};

static struct _timesel __far *ostimep;
static int ret = -1;

// call once on start
int ms_SetOSTime (void)
{
struct _osinfo osdata;

ret = qnx_osinfo( 0, &osdata);
if( ret == -1) return(-1);
ostimep = MK_FP( osdata.timesel, 0);

return(0);
}

// return time in seconds and nanoseconds
int ms_OSTime (
unsigned long *s, // sekundy
unsigned long *ns // nanosekundy
)
{
struct ostime tim;

if (ret != 0) return(-1);

_disable();
tim.sec = ostimep->seconds;
tim.nsec = ostimep->nsec;
_enable();

*s = tim.sec;
*ns = tim.nsec;

return(0);
}

Uluc Saranli <ulucs@poyraz.eecs.umich.edu> wrote:

I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.

My searches of QNX4 documentation did not reveal any such facility, unfortunely.
However, I noticed that QNX also uses Timer 0 for generating its timer pulses.
My question is whether reading the value of that timer, in combination with
the clock_gettime() function would be a reasonable way to obtain the accuracy
I would like. Would reading Timer 0 mess up anything in the kernel? It seemed
to me like Timer 0 is initially setup in Mode 3, which decrements by 2 at every clock
cycle. However, when I use clock_setres(), it seems to put it in Mode 2. Is this
always so?

Also, is there any way to get something like the “count of system ticks” since
the start of the system? In conjunction with the value of Timer 0, that would
give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.


Uluc SARANLI, Graduate Student Research Assistant

Advanced Technology Laboratory, The University of Michigan
Room 139, 1101 Beal Ave. Ann Arbor, MI 48109-2110
Tel : (734) 763-1572 Fax:(734) 763-1260
E-mail : > ulucs@eecs.umich.edu
URL : > http://www.eecs.umich.edu/~ulucs

Uluc Saranli wrote:

I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.
Why not just use DOS; it’s cheaper and it works sometimes.



My searches of QNX4 documentation did not reveal any such facility,
unfortunely. However, I noticed that QNX also uses Timer 0 for generating
its timer pulses. My question is whether reading the value of that timer,
in combination with the clock_gettime() function would be a reasonable way
to obtain the accuracy I would like. Would reading Timer 0 mess up
anything in the kernel? It seemed to me like Timer 0 is initially setup in
Mode 3, which decrements by 2 at every clock cycle. However, when I use
clock_setres(), it seems to put it in Mode 2. Is this always so?

Also, is there any way to get something like the “count of system ticks”
since the start of the system? In conjunction with the value of Timer 0,
that would give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.

Baal <baal@qnxvictim.net> wrote:

Uluc Saranli wrote:

I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.
Why not just use DOS; it’s cheaper and it works sometimes.

It seems to me that this not is your first invention about QNX suitability,
therefore more general answer for you:

Only crazy could built robots (and many other application) using DOS (and
many other OS) today. QNX offers you scaleability, real-time, unique
interprocess communication and synchronization. This newsgroup should
be used by programmers who have understood this aquisition.
Take it easy, Andy

My searches of QNX4 documentation did not reveal any such facility,
unfortunely. However, I noticed that QNX also uses Timer 0 for generating
its timer pulses. My question is whether reading the value of that timer,
in combination with the clock_gettime() function would be a reasonable way
to obtain the accuracy I would like. Would reading Timer 0 mess up
anything in the kernel? It seemed to me like Timer 0 is initially setup in
Mode 3, which decrements by 2 at every clock cycle. However, when I use
clock_setres(), it seems to put it in Mode 2. Is this always so?

Also, is there any way to get something like the “count of system ticks”
since the start of the system? In conjunction with the value of Timer 0,
that would give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.

There is a file on QUICS (I think it’s called micro*.tgz). If you have a
Pentium or higher it contains a function that does the same thing
as ClockCycles.


“Uluc Saranli” <ulucs@poyraz.eecs.umich.edu> wrote in message
news:92bjtg$beo$1@inn.qnx.com

I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.

My searches of QNX4 documentation did not reveal any such facility,
unfortunely.
However, I noticed that QNX also uses Timer 0 for generating its timer
pulses.
My question is whether reading the value of that timer, in combination
with
the clock_gettime() function would be a reasonable way to obtain the
accuracy
I would like. Would reading Timer 0 mess up anything in the kernel? It
seemed
to me like Timer 0 is initially setup in Mode 3, which decrements by 2 at
every clock
cycle. However, when I use clock_setres(), it seems to put it in Mode 2.
Is this
always so?

Also, is there any way to get something like the “count of system ticks”
since
the start of the system? In conjunction with the value of Timer 0, that
would
give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.


Uluc SARANLI, Graduate Student Research Assistant

Advanced Technology Laboratory, The University of Michigan
Room 139, 1101 Beal Ave. Ann Arbor, MI 48109-2110
Tel : (734) 763-1572 Fax:(734) 763-1260
E-mail : > ulucs@eecs.umich.edu
URL : > http://www.eecs.umich.edu/~ulucs

Check out a posting I made on November 6, 2000 in this newgroup. The two
attachments implement a class that may help.

Mario Charest wrote:

There is a file on QUICS (I think it’s called micro*.tgz). If you have a
Pentium or higher it contains a function that does the same thing
as ClockCycles.

“Uluc Saranli” <> ulucs@poyraz.eecs.umich.edu> > wrote in message
news:92bjtg$beo$> 1@inn.qnx.com> …
I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.

My searches of QNX4 documentation did not reveal any such facility,
unfortunely.
However, I noticed that QNX also uses Timer 0 for generating its timer
pulses.
My question is whether reading the value of that timer, in combination
with
the clock_gettime() function would be a reasonable way to obtain the
accuracy
I would like. Would reading Timer 0 mess up anything in the kernel? It
seemed
to me like Timer 0 is initially setup in Mode 3, which decrements by 2 at
every clock
cycle. However, when I use clock_setres(), it seems to put it in Mode 2.
Is this
always so?

Also, is there any way to get something like the “count of system ticks”
since
the start of the system? In conjunction with the value of Timer 0, that
would
give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.


Uluc SARANLI, Graduate Student Research Assistant

Advanced Technology Laboratory, The University of Michigan
Room 139, 1101 Beal Ave. Ann Arbor, MI 48109-2110
Tel : (734) 763-1572 Fax:(734) 763-1260
E-mail : > ulucs@eecs.umich.edu
URL : > http://www.eecs.umich.edu/~ulucs

Oops, sorry, that posting was in qnx4.devtools titled Re: Does QNX4 support
int64? - 2 Attachments

Dean Douthat wrote:

Check out a posting I made on November 6, 2000 in this newgroup. The two
attachments implement a class that may help.

Mario Charest wrote:

There is a file on QUICS (I think it’s called micro*.tgz). If you have a
Pentium or higher it contains a function that does the same thing
as ClockCycles.

“Uluc Saranli” <> ulucs@poyraz.eecs.umich.edu> > wrote in message
news:92bjtg$beo$> 1@inn.qnx.com> …
I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.

My searches of QNX4 documentation did not reveal any such facility,
unfortunely.
However, I noticed that QNX also uses Timer 0 for generating its timer
pulses.
My question is whether reading the value of that timer, in combination
with
the clock_gettime() function would be a reasonable way to obtain the
accuracy
I would like. Would reading Timer 0 mess up anything in the kernel? It
seemed
to me like Timer 0 is initially setup in Mode 3, which decrements by 2 at
every clock
cycle. However, when I use clock_setres(), it seems to put it in Mode 2.
Is this
always so?

Also, is there any way to get something like the “count of system ticks”
since
the start of the system? In conjunction with the value of Timer 0, that
would
give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.


Uluc SARANLI, Graduate Student Research Assistant

Advanced Technology Laboratory, The University of Michigan
Room 139, 1101 Beal Ave. Ann Arbor, MI 48109-2110
Tel : (734) 763-1572 Fax:(734) 763-1260
E-mail : > ulucs@eecs.umich.edu
URL : > http://www.eecs.umich.edu/~ulucs

If anyone is still looking for an answer, you could probably try
clock_setres() (and clock_getres()) which sets the resolution of the hardware
clock (the only one present on PCs). You could then use clock_gettime() to
query upto the resolution you set.
That’s what we used and it seems to work.

-Santosh

In article <3A4BABD7.1155C3E4@faac.com>, Dean Douthat <ddouthat@faac.com>
wrote:

Oops, sorry, that posting was in qnx4.devtools titled Re: Does QNX4 support
int64? - 2 Attachments

Dean Douthat wrote:

Check out a posting I made on November 6, 2000 in this newgroup. The two
attachments implement a class that may help.

Mario Charest wrote:

There is a file on QUICS (I think it’s called micro*.tgz). If you have a
Pentium or higher it contains a function that does the same thing
as ClockCycles.

“Uluc Saranli” <> ulucs@poyraz.eecs.umich.edu> > wrote in message
news:92bjtg$beo$> 1@inn.qnx.com> …
I have recently started using QNX4.25 for controlling a robot
platform. In certain places, I would like to have access to a very
accurate (microsecond accuracy) real time clock.

On QNXRTP, for example, there is the ClockCycles() function, which
does what I want. In DJGPP, which is a DOS based gcc development
environment, there is a uclock() function call, which reads the main
board timer chips for accurate timing.

My searches of QNX4 documentation did not reveal any such facility,
unfortunely.
However, I noticed that QNX also uses Timer 0 for generating its timer
pulses.
My question is whether reading the value of that timer, in combination
with
the clock_gettime() function would be a reasonable way to obtain the
accuracy
I would like. Would reading Timer 0 mess up anything in the kernel? It
seemed
to me like Timer 0 is initially setup in Mode 3, which decrements by 2 at
every clock
cycle. However, when I use clock_setres(), it seems to put it in Mode 2.
Is this
always so?

Also, is there any way to get something like the “count of system ticks”
since
the start of the system? In conjunction with the value of Timer 0, that
would
give me an accurate relative clock without much hassles.

Thanks for any ideas/suggestions on this.


Uluc SARANLI, Graduate Student Research Assistant

Advanced Technology Laboratory, The University of Michigan
Room 139, 1101 Beal Ave. Ann Arbor, MI 48109-2110
Tel : (734) 763-1572 Fax:(734) 763-1260
E-mail : > ulucs@eecs.umich.edu
URL : > http://www.eecs.umich.edu/~ulucs