Re: Multimedia Timer
- From: "Scott McPhillips [MVP]" <org-dot-mvps-at-scottmcp>
- Date: Mon, 11 Feb 2008 12:41:48 -0500
"clinisbut" <clinisbut@xxxxxxxxx> wrote in message news:ac5877e2-3c6d-4c4e-9d05-8b9a58de16c6@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I need to execute some code every 20ms. This code is just send some
data through serial port, so I think it's not heavy.
At first I was using SetTimer function and OnTimer event, but with no
good results: seems that not sending every 20ms, instead is sending 3
or so consecutive frames at same time.
Today I tried the multimedia timers, and seems that does the same.
Inside my TimeEventHandler, I trace:
TRACE( "Time:%d\n", GetTickCount() );
And I see that sometimes event handler fires up more than one time at
same time, look:
Time:30664983
Time:30664983
Time:30664983
Time:30664993
Time:30665013
Time:30665033
Time:30665054
Time:30665074
I'm measuring correctly the time elapsed between calls?
The 'resolution' claimed by the multimedia timer is not the same as the resolution provided by GetTickCount. GetTickCount is only updated at the system clock rate, which is much longer than a millisecond. So GetTickCount will not give you good measurements for fast events.
20 milliseconds is also rather fast for attempting to do anything like output to the serial port. Your thread may not be run, even though 20 milliseconds have elapsed, because other higher-priority threads may need to be run.
For better measurements you can use QueryPerformanceCounter. For better periodic timing you would probably have to adjust priorities with SetThreadPriority.
--
Scott McPhillips [VC++ MVP]
.
- References:
- Multimedia Timer
- From: clinisbut
- Multimedia Timer
- Prev by Date: Re: CString question
- Next by Date: Re: How do I use a modem to record telephone
- Previous by thread: Re: Multimedia Timer
- Next by thread: Re: Multimedia Timer
- Index(es):
Relevant Pages
|