Real Time I/O access

We set up a timer(2ms) in the program. In every time loop, the
program access
I/O port( real time communicate with another equipment). The result is the
timer
set up doesn’t work. The actual time loop is the communication time of I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop, the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1 ms, 2
ms
0r 3ms. If there is no I/O access in the loop, the timer works well. You can
set up 1ms
,2ms, 0r 3ms.

Best Regard

Tie Hu

If the IO to your hardware takes longer than the period of your timer, then
you won’t be able to execute your loop more often then the time it takes to
access your hardware port.

(Did that make any sense? It was kind of like saying if 5 is bigger then 3
than 5 is bigger than 3.)

However, if, as you say, you tried a period greater than the time required
by your hardware access and it still repeats as often as the hardware access
will allow, then I would guess that your not really waiting on the timer.
Is it possible that your setting the timer but not waiting for it?

Can you post a tiny snippet of code?

“tie” <tie@cbis.ece.drexel.edu> wrote in message
news:aeoap2$lp5$1@inn.qnx.com

We set up a timer(2ms) in the program. In every time loop, the
program access
I/O port( real time communicate with another equipment). The result is the
timer
set up doesn’t work. The actual time loop is the communication time of I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop, the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1 ms, 2
ms
0r 3ms. If there is no I/O access in the loop, the timer works well. You
can
set up 1ms
,2ms, 0r 3ms.

Best Regard

Tie Hu

Thanks,

The following is the source code.

SetData(‘C’,Joint_Status,Joint_Tolk);/I/O /Access /Function/ is a
function to access I/O and it will take about 1.35ms.


/
*************************************************************************
*****************************************************************/

timer_create(CLOCK_REALTIME, &event, &timer_id);

itime.it_value.tv_sec =0;

/* 1 million nsecs = .001 secs */

itime.it_value.tv_nsec =2000000;

itime.it_interval.tv_sec =0;

/* 1 million nsecs = .001 secs */

itime.it_interval.tv_nsec = 2000000;

timer_settime(timer_id, 0, &itime, NULL);



for(;:wink: {

rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);

if (rcvid == 0) { /* we got a pulse */
if (msg.pulse.code == MY_PULSE_CODE) {



SetData(‘C’,Joint_Status,Joint_Tolk);/*I/O /Access /Function/


//nanosleep();


} /
else other pulses … /
} /
else other messages … */

}
/***************************************************************************


***/


We set up a timer(2ms) in the program. In every time loop, the program
access
I/O port( real time communicate with another equipment). The result is the
timer
set up doesn’t work. The actual time loop is the communication time of I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop, the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1 ms, 2
ms
0r 3ms.
Yesterday, I try to put nanosleep() funtion in the loop. According to the
help file,
nanosleep() is used to suspend the thread until the signal comes. I set the
suspend
time as 0.1ms.

Tie Hu

“Bill Caroselli (Q-TPS)” <QTPS@EarthLink.net> wrote in message
news:aeoc9t$mh1$1@inn.qnx.com

If the IO to your hardware takes longer than the period of your timer,
then
you won’t be able to execute your loop more often then the time it takes
to
access your hardware port.

(Did that make any sense? It was kind of like saying if 5 is bigger then
3
than 5 is bigger than 3.)

However, if, as you say, you tried a period greater than the time required
by your hardware access and it still repeats as often as the hardware
access
will allow, then I would guess that your not really waiting on the timer.
Is it possible that your setting the timer but not waiting for it?

Can you post a tiny snippet of code?

“tie” <> tie@cbis.ece.drexel.edu> > wrote in message
news:aeoap2$lp5$> 1@inn.qnx.com> …
We set up a timer(2ms) in the program. In every time loop,
the
program access
I/O port( real time communicate with another equipment). The result is
the
timer
set up doesn’t work. The actual time loop is the communication time of
I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop, the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1 ms,
2
ms
0r 3ms. If there is no I/O access in the loop, the timer works well. You
can
set up 1ms
,2ms, 0r 3ms.

Best Regard

Tie Hu

\

“tie” <tie@cbis.ece.drexel.edu> wrote in message
news:aestbq$7ik$1@inn.qnx.com

Thanks,

The following is the source code.

SetData(‘C’,Joint_Status,Joint_Tolk);/*I/O */Access /Function/ is a
function to access I/O and it will take about 1.35ms.

How did you measure it is taking 1.3ms?

By default tick size is 10ms. That means any timer you create only has a
resolution of 10ms.

nanosleep() will supend untils a signal is generated, but a pulse is not a
signal.
If you were to setup nanosleep to .1 ms it would sleep for 10ms because of
timer precision (assuming it’s not getting a signal before)

/***************************************************************************
*****************************************************************/

timer_create(CLOCK_REALTIME, &event, &timer_id);

itime.it_value.tv_sec =0;

/* 1 million nsecs = .001 secs */

itime.it_value.tv_nsec =2000000;

itime.it_interval.tv_sec =0;

/* 1 million nsecs = .001 secs */

itime.it_interval.tv_nsec = 2000000;

timer_settime(timer_id, 0, &itime, NULL);



for(;:wink: {

rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);

if (rcvid == 0) { /* we got a pulse */
if (msg.pulse.code == MY_PULSE_CODE)
{



SetData(‘C’,Joint_Status,Joint_Tolk);/*I/O /Access /Function/


//nanosleep();


} /
else other pulses … /
} /
else other messages … */

}

/***************************************************************************


***/


We set up a timer(2ms) in the program. In every time loop, the program
access
I/O port( real time communicate with another equipment). The result is the
timer
set up doesn’t work. The actual time loop is the communication time of I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop, the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1 ms, 2
ms
0r 3ms.
Yesterday, I try to put nanosleep() funtion in the loop. According to the
help file,
nanosleep() is used to suspend the thread until the signal comes. I set
the
suspend
time as 0.1ms.

Tie Hu

“Bill Caroselli (Q-TPS)” <> QTPS@EarthLink.net> > wrote in message
news:aeoc9t$mh1$> 1@inn.qnx.com> …
If the IO to your hardware takes longer than the period of your timer,
then
you won’t be able to execute your loop more often then the time it takes
to
access your hardware port.

(Did that make any sense? It was kind of like saying if 5 is bigger
then
3
than 5 is bigger than 3.)

However, if, as you say, you tried a period greater than the time
required
by your hardware access and it still repeats as often as the hardware
access
will allow, then I would guess that your not really waiting on the
timer.
Is it possible that your setting the timer but not waiting for it?

Can you post a tiny snippet of code?

“tie” <> tie@cbis.ece.drexel.edu> > wrote in message
news:aeoap2$lp5$> 1@inn.qnx.com> …
We set up a timer(2ms) in the program. In every time loop,
the
program access
I/O port( real time communicate with another equipment). The result is
the
timer
set up doesn’t work. The actual time loop is the communication time of
I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop,
the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1
ms,
2
ms
0r 3ms. If there is no I/O access in the loop, the timer works well.
You
can
set up 1ms
,2ms, 0r 3ms.

Best Regard

Tie Hu



\

I use clock_gettime( CLOCK_REALTIME, &stop) to measue the time.
Clockperiod() is used to set up the resolution. I set up 10000ns.
/*/
new.nsec=10000;
new.fract=0;
result=ClockPeriod(CLOCK_REALTIME, &new, NULL,0);
/
/

Tie




“Mario Charest” postmaster@l127.0.0.1 wrote in message
news:aesvqs$9ff$1@inn.qnx.com

“tie” <> tie@cbis.ece.drexel.edu> > wrote in message
news:aestbq$7ik$> 1@inn.qnx.com> …
Thanks,

The following is the source code.

SetData(‘C’,Joint_Status,Joint_Tolk);/*I/O */Access /Function/ is
a
function to access I/O and it will take about 1.35ms.

How did you measure it is taking 1.3ms?

By default tick size is 10ms. That means any timer you create only has a
resolution of 10ms.

nanosleep() will supend untils a signal is generated, but a pulse is not
a
signal.
If you were to setup nanosleep to .1 ms it would sleep for 10ms because of
timer precision (assuming it’s not getting a signal before)





/***************************************************************************
*****************************************************************/

timer_create(CLOCK_REALTIME, &event, &timer_id);

itime.it_value.tv_sec =0;

/* 1 million nsecs = .001 secs */

itime.it_value.tv_nsec =2000000;

itime.it_interval.tv_sec =0;

/* 1 million nsecs = .001 secs */

itime.it_interval.tv_nsec = 2000000;

timer_settime(timer_id, 0, &itime, NULL);



for(;:wink: {

rcvid = MsgReceive(chid, &msg, sizeof(msg), NULL);

if (rcvid == 0) { /* we got a pulse */
if (msg.pulse.code ==
MY_PULSE_CODE)
{



SetData(‘C’,Joint_Status,Joint_Tolk);/*I/O /Access /Function/


//nanosleep();


} /
else other pulses … /
} /
else other messages … */

}


/***************************************************************************

\


***/


We set up a timer(2ms) in the program. In every time loop, the program
access
I/O port( real time communicate with another equipment). The result is
the
timer
set up doesn’t work. The actual time loop is the communication time of
I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop, the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1 ms,
2
ms
0r 3ms.
Yesterday, I try to put nanosleep() funtion in the loop. According to
the
help file,
nanosleep() is used to suspend the thread until the signal comes. I set
the
suspend
time as 0.1ms.

Tie Hu

“Bill Caroselli (Q-TPS)” <> QTPS@EarthLink.net> > wrote in message
news:aeoc9t$mh1$> 1@inn.qnx.com> …
If the IO to your hardware takes longer than the period of your timer,
then
you won’t be able to execute your loop more often then the time it
takes
to
access your hardware port.

(Did that make any sense? It was kind of like saying if 5 is bigger
then
3
than 5 is bigger than 3.)

However, if, as you say, you tried a period greater than the time
required
by your hardware access and it still repeats as often as the hardware
access
will allow, then I would guess that your not really waiting on the
timer.
Is it possible that your setting the timer but not waiting for it?

Can you post a tiny snippet of code?

“tie” <> tie@cbis.ece.drexel.edu> > wrote in message
news:aeoap2$lp5$> 1@inn.qnx.com> …
We set up a timer(2ms) in the program. In every time
loop,
the
program access
I/O port( real time communicate with another equipment). The result
is
the
timer
set up doesn’t work. The actual time loop is the communication time
of
I/O
port.
For example, if the time to access I/O port takes 1.3 ms every loop,
the
elapsed
time of the timer loop become 1.3 ms no matter you set up timer as 1
ms,
2
ms
0r 3ms. If there is no I/O access in the loop, the timer works well.
You
can
set up 1ms
,2ms, 0r 3ms.

Best Regard

Tie Hu





\

“tie” <tie@cbis.ece.drexel.edu> wrote in message
news:aet2eh$bka$1@inn.qnx.com

I use clock_gettime( CLOCK_REALTIME, &stop) to measue the time.
Clockperiod() is used to set up the resolution. I set up 10000ns.

That’s 10us. I hope you have a fast processor cause that’s 100000
interrupts
per seconds, that’s a LOT!!!


What is quite possible is that although the SetData function takes 1.3ms
something else in your main loop takes more time.

You have been posting only bits and pieces of your code. I would help if
you post more. Unless there is a serious bug in the OS what you are seeing
is not possible. I see two possiblities; either the way you measure time
is wrong or your program isn’t doing what you thing it’s doing.

Any of these two possibilities I can’t help you with unless I see real code.

  • Mario