Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Resolution of Allegro timers?

This thread is locked; no one can reply to it. rss feed Print
Resolution of Allegro timers?
nonnus29
Member #2,606
August 2002
avatar

If a setup a timer to tick 1000 times a second, does it actually tick at this rate? Is it guaranteed to give 1000 ticks per second? Will the timer update more than one time per tick? Like in the code below, will tick_counter++ be 1000 before an update and 1020 afterward?

void updateTickCounter()  {
    tick_counter++;
}

Sirocco
Member #88
April 2000
avatar

IIRC Windows forces the timers to around 120 ticks a second, so that's the maximum resolution you'll get from an Allegro timer under that platform. Anything above that results in multiple scans per tick (so at 240Hz you'd get two scans per tick).

I haven't done any serious testing because I've never run into a reason to set a timer above 120Hz.

-->
Graphic file formats used to fascinate me, but now I find them rather satanic.

Kris Asick
Member #1,424
July 2001

Under Windows, on both really old and new systems, I've had Allegro timers going at rates of 10,000 BPS with no problems. Allegro uses the Windows high-performance timers when possible, (which is practically true for all systems), however, Allegro's timers update at their own rate, so if they fall behind they have to catch up, which means the accuracy of the timer will be at the mercy of how often Allegro updates.

IE: If you have a 10,000 BPS timer, but Allegro is only updating its timers once every hundredth second, your timer will update 100 times every hundredth second. Like this:

// TimerTick runs at 10,000 BPS
void TimerTick (void)
{
    timer_count++;
}

// Time 0.000, Timer Count = 0  , Should Be = 0
// Time 0.005, Timer Count = 0  , Should Be = 50
// Time 0.010, Timer Count = 100, Should Be = 100
// Time 0.015, Timer Count = 100, Should Be = 150
// Time 0.020, Timer Count = 200, Should Be = 200

If you want extreme precision, you'll need to access the Windows high-performance timers yourself. In the interim though, using an Allegro timer set to something high works well enough though and I've never encountered problems as such. You'll never be able to perceive this accuracy error unless you're trying to vsync to a 120 Hz CRT monitor signal or something.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

ImLeftFooted
Member #3,935
October 2003
avatar

Quote:

Resolution of Allegro timers?

Bad.

Try
http://www.allegro.cc/forums/search?keywords=collection+of+timer+code
or something.

nonnus29
Member #2,606
August 2002
avatar

I'm consistantly getting resolution of about 4 milliseconds ie a timer set to 1000 BPS ticks a minmum of 4 times so I guess that means it updates 250 beats a second.

Kris Asick
Member #1,424
July 2001

Don't quote me on this, but I think that number is not only dependent on the specific computer, but also on how much stuff is running at a time and the priority of every thread that currently exists.

--- Kris Asick (Gemini)
--- http://www.pixelships.com

--- Kris Asick (Gemini)
--- http://www.pixelships.com

Tobias Dammers
Member #2,604
August 2002
avatar

Last time I checked, the allegro timer maxed at about 100 bps. I made a wrapper back then which uses QPC if available, and allegro timers otherwise. It's not hard.

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Go to: