Can anyone guide me in attaining micro seconds delay in WinCE.
I am able to find out some routines like "QueryPerformanceCounter()"
and "QueryPerformanceFrequency()" which work at the "BSP level".
But I require a Timer at the "Application level" which can provide me
delay/wait in Microseconds. Currently i am using EVC++ for my
application development. Any suggestion will be a great help to me.
Hope my query is clear to you.
with regards,
Chandra.
Hi Andrew,
Thanks for quick reply. I am able to configure the Performance
Counter, but my application is hanging when i try to use it. The code
which i am using is as below.
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
LARGE_INTEGER liDelay;
// Query number of ticks per second
if (QueryPerformanceFrequency(&liDelay))
{
// 1ms delay
liDelay.QuadPart /= 1000;
LARGE_INTEGER liTimeOut;
// Get current ticks
if (QueryPerformanceCounter(&liTimeOut))
{
// Create timeout value
liTimeOut.QuadPart += liDelay.QuadPart;
LARGE_INTEGER liCurrent;
do
{
// Get current ticks
QueryPerformanceCounter(&liCurrent);
// Delay until timeout
} while (liCurrent.QuadPart<liTimeOut.QuadPart);
}
}
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
liDelay.QuadPart /= 1000; // for milli seconds divide by 1000
liDelay.QuadPart /= 1000; // for second divide by 1
The statement i am varying according to my requirement. But only thig
is when i am trying to get microseconds delay with this code, my
application is getting hanged and it is terminating itself. Any
suggestion from you will be a great help to me. Hope you understand my
problem.
With warm regards,
Chandra.
> On Nov 20, 2:26 pm, "Andrew at Plextek (www.plextek.co.uk)"
><a...@plextek.com> wrote:
>> I've successfully used the performance counter at application
>> level. Andrew.
>>
>
> Hi Andrew,
>
> Thanks for quick reply. I am able to configure the Performance
> Counter, but my application is hanging when i try to use it. The
> code which i am using is as below.
[...]
> The statement i am varying according to my requirement. But only
> thig is when i am trying to get microseconds delay with this code,
> my application is getting hanged and it is terminating itself. Any
> suggestion from you will be a great help to me. Hope you
> understand my problem.
>
> With warm regards,
If you wait in this way you are doing a so called "busy loop", not
letting other threads wiht lower priorities to run and using your
whole CPU "slice" (100ms by default). This will slow down the device,
consume more power (because your CPU can't get in idle mode etc.).
For waits of some milliseconds you should use Sleep, increasing your
thread priority if you need an exact delay and using SleepTillTick to
syncronize with the system tick.
A busy loop is not a good idea for waits that you do rarely and lasts
for more than a few microseconds. If you need to do this sort of
delays often or they should last for hundred of microseconds you
should use one of the microprocessor internal timers and its ability
to be programmed to generate an interrupt after a specific time.
--
Valter Minute
www.fortechembeddedlabs.it
Training, support and development for Windows CE
(the reply address of this message is invalid)
for( int i=0; i<10; i++ )
{
LARGE_INTEGER perfCntVal;
QueryPerformanceCounter( &perfCntVal );
printf("perfCntVal = 0x%08X%08X\n", perfCntVal.HighPart,
perfCntVal.LowPart);
Sleep(100);
}
Andrew.
On Nov 20, 10:25 am, Chandra <forquer...@gmail.com> wrote:
> On Nov 20, 2:26 pm, "Andrew at Plextek (www.plextek.co.uk)"
>
> <a...@plextek.com> wrote:
> > I've successfully used the performance counter at application level.
> > Andrew.
>
> Hi Andrew,
>
> Thanks for quick reply. I am able to configure the Performance
> Counter, but my application is hanging when i try to use it. The code
> which i am using is as below.
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
> LARGE_INTEGER liDelay;
> // Query number of ticks per second
> if (QueryPerformanceFrequency(&liDelay))
> {
> // 1ms delay
> liDelay.QuadPart /= 1000;
>
> LARGE_INTEGER liTimeOut;
> // Get current ticks
> if (QueryPerformanceCounter(&liTimeOut))
> {
> // Create timeout value
> liTimeOut.QuadPart += liDelay.QuadPart;
> LARGE_INTEGER liCurrent;
> do
> {
> // Get current ticks
> QueryPerformanceCounter(&liCurrent);
> // Delay until timeout
> } while (liCurrent.QuadPart<liTimeOut.QuadPart);
> }
> }
>
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
> -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
liTimeOut.QuadPart += liDelay.QuadPart
can result in small value, when the addition overflows. The better way is to
calculate the difference between current time and start time and compare it
with the timeout.
I must admit that the probability for the overflow is small, but it's
different from zero.
> LARGE_INTEGER liDelay;
>> // Query number of ticks per second
>> if (QueryPerformanceFrequency(&liDelay))
>> {
>> // 1ms delay
>> liDelay.QuadPart /= 1000;
>>
>> LARGE_INTEGER liTimeOut;
>> // Get current ticks
>> if (QueryPerformanceCounter(&liTimeOut))
>> {
>> // Create timeout value
>> liTimeOut.QuadPart += liDelay.QuadPart;
>> LARGE_INTEGER liCurrent;
>> do
>> {
>> // Get current ticks
>> QueryPerformanceCounter(&liCurrent);
>> // Delay until timeout
>> } while (liCurrent.QuadPart<liTimeOut.QuadPart);
>> }
>> }
>>
LARGE_INTEGER liStart;
// Get current ticks
if (QueryPerformanceCounter(&liStart))
{
do
{
LARGE_INTEGER liCurrent;
LARGE_INTEGER liSpan;
// Get current ticks
QueryPerformanceCounter(&liCurrent);
liSpan.QuadPart = liCurrent.QuadPart - liStart.QuadPart;
} while (liSpan.QuadPart<liTimeOut.QuadPart);
}
/Helge