Jump to content

Recommended Posts

Posted (edited)

:angry:

hi,

i have a application where i need a timer to intr every 40 ms

but i found it was not accurate

so i made a program to test it

timer_tick event -----

current_time = my.computer.clock.time.milliseconds

actual_interval = (current_time-earlier_time)

earlier_time = current_time

end sub ---------

seems like "user defined interval" is very diff from "actual interval"

any userdefined interval from 1-14 makes the timer work every 16ms

any userdefined interval from 15-34 makes the timer work every 32ms

any userdefined interval from 35-45 makes the timer work every 47ms

why does the timer not intr exactly acc to interval?

or is the program wrong?

Edited by theboss.robin

Posted
any userdefined interval from 1-14 makes the timer work every 16ms

any userdefined interval from 15-34 makes the timer work every 32ms

any userdefined interval from 35-45 makes the timer work every 47ms

The system timer does *not* have 1ms granularity.

See http://www.codeproject.com/system/simpletime.asp

Learn to use the CPU's clock counter if you want nanosecond accuracy (e.g. 2GHz CPU = 0.5ns per clock)

  • 3 weeks later...
Posted

I think in VB6, the Timer control had a 55ms granularity. Not sure if .Net is the same. IIRC, using the API SetTimer() function, you could get as low as 10ms. (Not sure if that's the best it can do, or if VB's overhead just prevents it from being any faster.)

BTW, you might want to look at GetTickCount(), which returns the system's uptime in milliseconds. (It's only 32 bits, so it's not really useable if you actually want the uptime, but it's great for timing. Just ensure you don't get caught in a loop waiting for it to be >4,294,967,295, because it never will be.)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...