delay in c microsecond
Hellom,
I used these to get microsecond delays
/***************************** delay.h *****************/
#ifndef __DELAY_H__
#define __DELAY_H__
class Delay
{
public:
Delay();
~Delay();
static void delaySeconds( float seconds );
static void delayMiliSeconds( float miliseconds );
static void delayMicroSeconds( float microseconds );
};
#endif
/***********************************************************/
/************************************ delay.cpp ****************/
#include "stdafx.h"
#include "delay.h"
Delay:
elay()
{
}
Delay::~Delay()
{
}
void Delay::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 Delay::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 Delay::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 ) );
};
}