Results 1 to 9 of 9

Thread: Timer resolution

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Unhappy

    Even though the timer indicates is can operate down to 1ms intervals the best I can get it to achive is 50ms is this a common problem? Is there any way around it?

    Cheers

  2. #2
    Guest
    I think the resolution is around 60ms

    You could download the SubTimer from http://www.vbaccelerator.com for it has a smaller resolution.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Wink

    I just found this in the help.

    "The system generates 18 clock ticks per second — so even though the Interval property is measured in milliseconds, the true precision of an interval is no more than one-eighteenth of a second. "

    This answers my question (1/18)sec = 55ms.

    Cheers Azzmodan, I'll have a look on that site.

    Rick



    [Edited by Rick H on 06-21-2000 at 05:15 AM]

  4. #4
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Lightbulb

    Hi, Rick H Just take a look at this Thread

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Jan 2000
    Location
    Gloucestershire, England
    Posts
    301

    Smile

    Chris, I`m not entirley sure on your test routine. I`ve adapted your code slightly to this:

    Code:
    Option Explicit
    Private T1&, T2&, dl&
    
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    
    Public Sub load_SetTimer()
        SetTimer frmSome.hwnd, 0, 5, AddressOf TimerProc
        T1 = GetTickCount
        frmSome.txtoutput = ""
    End Sub
    
    Sub TimerProc(ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long)
    Static a As Integer
    Static store(10) As Long
    If a <= 10 Then
        store(a) = GetTickCount
        a = a + 1
    Else
        KillTimer frmSome.hwnd, 0
        For a = 0 To 9
        frmSome.txtoutput = frmSome.txtoutput & (store(a) - store(a + 1)) & vbCrLf
        Next
        a = 0
    End If
    End Sub
    And these are the results I get:

    -58
    -52
    -58
    -52
    -58
    -52
    -57
    -53
    -60
    -53

    indicating the same 55ms problem as before, this happens even if you change the interval from 5ms to 10ms. Do you think this is a problem with GetTickCount or the Settimer?

    If you put 20ms as your interval you get 55ms exactly

    Cheers


    [Edited by Rick H on 06-21-2000 at 11:12 AM]

  6. #6
    Guest
    There was a debate about this awhile ago. The QueryPerformanceCounter is the most accurate one. 1 microsecond.

  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Yeah but that depends on the machine, i tested out the multimedia timer, that raised an event each millisecond, but it crashed as soon as you started to use your keyboard or mouse...
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  8. #8
    Guest
    So I guess GetTickCount is the most stable one.

  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I don't think there's particulary stable or unstable api functions since they all work fine but what i meant was stable events raised by timers.
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width