Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Absolute Delays in C/C++ under win 98/xp/nt

Status
Not open for further replies.

visweswara

Newbie level 3
Newbie level 3
Joined
Apr 13, 2005
Messages
3
Helped
1
Reputation
2
Reaction score
0
Trophy points
1,281
Activity points
1,296
How to program to generate real-time delay of microsecond or millisecond using c/c++ under windows 98/xp/nt ?
 

what you need is

void delaySeconds( float seconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );
QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

__int64 timeToWait = (double)timeDelta * (double)seconds;

timeEllapsed = timeStart;

while( ( timeEllapsed - timeStart ) < timeToWait )
{
QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) );

};
}

void delayMiliSeconds( float miliseconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );

__int64 timeToWait = (double)timeDelta * (double)miliseconds/1000.0f;

QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

timeEllapsed = timeStart;

while( ( timeEllapsed - timeStart ) < timeToWait )
{
QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) );

};
}

void delayMicroSeconds( float microseconds )
{
__int64 timeEllapsed;
__int64 timeStart;
__int64 timeDelta;

QueryPerformanceFrequency( (LARGE_INTEGER*)(&timeDelta ) );

__int64 timeToWait = (double)timeDelta * (double)microseconds / 1000000.0f;

QueryPerformanceCounter ( (LARGE_INTEGER*)(&timeStart ) );

timeEllapsed = timeStart;

while( ( timeEllapsed - timeStart ) < timeToWait )
{
QueryPerformanceCounter( (LARGE_INTEGER*)(&timeEllapsed ) );

};
}
 

    visweswara

    Points: 2
    Helpful Answer Positive Rating
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top