Results 1 to 11 of 11

Thread: Accurate timer function

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Slovenia
    Posts
    11

    Post Accurate timer function

    Hi there! This is my firs post, so if there are any misshaps pls - don't be mad.

    Q: In my App I have to drive a single Servo motor (Graupner C512). It should be connected on LPT port. The problem is that I don't have a clue how to do that. I thought about using Timer control but I've learned it tickes only in 55ms periods minimum (for that servo it should tick between 1 and 2ms in intervals of 0.1ms). I've been told to use timeGetTime API function or Sleep API function, but...don't know how!
    The second thing is, I don't know how to send those ticks to LPT port (like LPT1, bit 0 or sometning).

    I would really appreciate any suggestion or code.

    Regards! Ales Zigon

  2. #2
    Megatron
    Guest
    Use GetTickCount for the timing.
    Code:
    Do
        Start = Timer
        Do While Timer < Start + 1
            DoEvents
        Loop
        '<-- Code here-->
    Loop

  3. #3

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Slovenia
    Posts
    11
    Thank You! I see, what are you trying to tell me, but I still don' quite get it.

    First: What does The API GetTickCout looks like?
    Second: I don't know, how to make that code for sending ticks to LPT port

    Maybe, if I explain my problem a little further, it will help you to explain it to me. So here goes:

    Let say, I woul like to turn one LED diode, whitch is attached to LPT1 - pin D0, ON and OFF every 30ms. It should stay ON for 1.5ms.
    (If I should look like using "astabile multivibrator" in electronic).

    If this is of ANY help, please, DO reply!

    Regards! Ales Zigon
    Last edited by zigona; Jun 1st, 2001 at 08:09 AM.

  4. #4
    Megatron
    Guest
    Sorry about that: It should look like this.
    Code:
    Do
        Start = GetTickCount 
        Do While GetTickCount < Start + 1
            DoEvents
        Loop
        '<-- Code here-->
    Loop
    Where is the number of milliseconds to pause for. In your case, you'll need to change it to 30.

  5. #5

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Slovenia
    Posts
    11
    Thank you for the reply!
    If I got it right, it should look like this:

    Declare Function GetTickCount Lib "kernel32.dll" () As Long

    Do
    Start=GetTickCount
    Do While GetTickCount < Start + 30 'setting bit to 0 (zero) for 30ms
    output=0 'output bit D0 on LPT1
    Loop
    Start=GetTickCount
    Do While GetTickCount < Start + 1.5 'setting bit to 1 (one) for 1.5ms
    output=1
    Loop
    Loop

    Where 1.5 can be presented as Long and deviated between 1.0 and 2.0ms.

    Am I in the right way?
    Regards!
    Ales Zigon
    Last edited by zigona; Jun 1st, 2001 at 05:03 PM.

  6. #6
    Megatron
    Guest
    You code looks find, except that the declare statements needs to be Private so it should read as:
    Code:
    Private Declare Function GetTickCount Lib "kernel32.dll" () As Long

  7. #7

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Slovenia
    Posts
    11
    THANK YOU VERY MUCH FOR YOUR HELP. I'll try it right on! Thanx again.

  8. #8
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can also use a high-resolution multimedia timer. I posted some code somewhere but don't have it on my PC anymore, do a search.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  9. #9
    Megatron
    Guest
    You mean QueryPerformanceCounter?

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You could use that, or you could get mental and use the RTDSC (or something like that) instruction I was referring to timeSetEvent.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11

    Thread Starter
    New Member
    Join Date
    May 2001
    Location
    Slovenia
    Posts
    11
    Hi, guys!
    Sorry, but I don't quite get it. Are those API functions? (timeSetEvent, QuerryPerformanceCounter,...)
    I'm not really familliar with multimedia, but still... if this can be a good solution, I would like to know more, I really do.

    And yes, I've tried that code above with GetTickCount API, but it caused some storm in my brain cells.
    I put a couter in Do-Lopp just to see, how it works and redirect an output in the List box (just n=n+1 for each loop). Quess what - it didn't return the same value each time it loops (it varried for about 20%)!
    Why?

    If I may, I have 1 more Q:

    How to make a Command button behave like this:
    When I press it (and keep it pressed) the counter should increment its value, and when I depress it (let it go), it should stop. I was thinking about KeyDown or MouseDown event but ither of them wouldn't work.
    I attached a file for you to look!

    Any ideas?

    Regards! Ales Zigon
    Attached Files Attached Files

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