-
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
-
Use GetTickCount for the timing.
Code:
Do
Start = Timer
Do While Timer < Start + 1
DoEvents
Loop
'<-- Code here-->
Loop
-
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
-
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.
-
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
-
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
-
THANK YOU VERY MUCH FOR YOUR HELP. I'll try it right on! Thanx again.
-
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.
-
You mean QueryPerformanceCounter?
-
You could use that, or you could get mental and use the RTDSC (or something like that) instruction :) I was referring to timeSetEvent.
-
1 Attachment(s)
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