Hello everyone,
I was wondering how can I make a precise delay that is shorter then 1ms
on C++(I need it to drive a servo motor via PC)?

If I understand correctly the standart delay function has a resolution of 1ms,
so it won't do it...

Thank you,
A.

Recommended Answers

All 7 Replies

>>I was wondering how can I make a precise delay that is shorter then 1ms
depends on the operating system. Neither MS-Windows nor *nix will allow you to do that because neither operating systems are real-time os. There are a lot of other programs that have to be executed as well as yours and they all require cpu time. Its just not possible to devote that much time to just one process. You could give your program a higher priority but you risk the danger of halting the entire operating system when you do that.

Even though the delay functions have a resolution of 1 ms its very unlikely that will be achieved in real tests -- normally do not expect a better resolution than about 10 ms or so, depending on what other processes are doing.

On Windows, check out QueryPerformanceCounter() and QueryPerformanceFrequency().

On Windows, check out QueryPerformanceCounter() and QueryPerformanceFrequency().

those are not system delay functions.

No, but they can be used to roll your own by polling them in a loop.

Like AD said though, you are trying to do something a little unlikely...

Ok,
thanks.
(But I'll still try to find a way to do it,because using computer ports for
robotics expirements is realy comfortable :-) )

Thank you very much for the link,I will look into it.
I was also thinking of using the serial port (com ) to recieve a precise pulse
(the serial comunication rate(bps) should be fast enough for me to recieve the wanted
pulse lenght by playing with the amount of '1's ).


A.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.