Re: Multimedia Timer

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



"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]

.



Relevant Pages

  • Re: 8ms Timer for serial port access
    ... >which is done depended on the measurements I take. ... The OS's serial port hardware buffers ... You can probably display your ... The first bit of every byte is a frame control bit. ...
    (comp.os.linux.development.apps)
  • Re: 8ms Timer for serial port access
    ... > saccadic eye-movements last only around 90ms I need to detect them really ... the data that is sent over the serial port, it doesn't seem to matter ... If you get it 2 milliseconds later, ...
    (comp.os.linux.development.apps)
  • Re: MSComm control array
    ... > array every 500 milliseconds. ... > software is querying the plc status by sending a special character to the ... > serial port and then enables an other 400 millisecond timer (this is ... I also simulated the control array in a new project ...
    (microsoft.public.vb.general.discussion)
  • MSComm control array
    ... array every 500 milliseconds. ... On each serial port is connected a plc and the ...
    (microsoft.public.vb.general.discussion)
  • big font
    ... instruments via the serial port. ... I'd love to display the measurements ...
    (comp.sys.hp48)