Cruz
20th February 2009, 12:17
Hello,
I would like to execute a function on a Windows machine as close to every 12 ms as somehow possible. Right now I'm using a QTimer and I'm not sure how well it does the job. The following test setup:
constructor
{
stepTimer = new QTimer(this);
connect(stepTimer,SIGNAL(timeout()), this, SLOT(tick()));
stepTimer->start(12);
time = new QTime();
time->start();
}
void tick()
{
qDebug() << time->restart();
}
shows that the tick() function is executed every 15 or 16 milliseconds. The output is like:
15,16,15,16,15,16,15,16,15,16,15,16,15,16....
When I start the timer with 10 ms instead of 12, I get:
0,16,15,0,16,15,0,16,15,0,16,15,0,16,15...
This is not exactly satisfactory.
First of all, how exact are the timings that QTime::restart() is showing me?
Of course it's very clear that tick() should execute in less than 12 ms and I believe qDebug() does so, but I better ask than be wrong?
I know that Windows is not a real time OS and my own experiments show that it delivers a precision somewhere around the 10 ms mark. Does anyone have more exact information?
And last but not least, what can I do to get the 12 ms rhythm as steady as possible?
I would like to execute a function on a Windows machine as close to every 12 ms as somehow possible. Right now I'm using a QTimer and I'm not sure how well it does the job. The following test setup:
constructor
{
stepTimer = new QTimer(this);
connect(stepTimer,SIGNAL(timeout()), this, SLOT(tick()));
stepTimer->start(12);
time = new QTime();
time->start();
}
void tick()
{
qDebug() << time->restart();
}
shows that the tick() function is executed every 15 or 16 milliseconds. The output is like:
15,16,15,16,15,16,15,16,15,16,15,16,15,16....
When I start the timer with 10 ms instead of 12, I get:
0,16,15,0,16,15,0,16,15,0,16,15,0,16,15...
This is not exactly satisfactory.
First of all, how exact are the timings that QTime::restart() is showing me?
Of course it's very clear that tick() should execute in less than 12 ms and I believe qDebug() does so, but I better ask than be wrong?
I know that Windows is not a real time OS and my own experiments show that it delivers a precision somewhere around the 10 ms mark. Does anyone have more exact information?
And last but not least, what can I do to get the 12 ms rhythm as steady as possible?