Delay
Blitz3D Forums/Blitz3D Beginners Area/Delay
| ||
Do anyone know if i can use a floating point number with the delay function? example: Delay 1.5 |
| ||
Delay expects an integer. Whatever value you use will be converted, if needed, to an integer. You could use: Delay 1.5 but the 1.5 will be converted to an integer. Print Int( 1.5 ) WaitKeyThis means that Delay 1.5 is really the same as Delay 2. |
| ||
And what can I do if I need a 1.5 milliseconds delay? Are there any library, dll,...? |
| ||
Don't use 'Delay'. I would be uncertain of the accuracy of such a time-split, especially dependent of the processor. Im curious... why would you need 0.5ms division? |
| ||
You could have a loop, and increment a variable until the timer equals one millisecond. Get the variable number, and use this to work out how many times you need to increment the variable to get to half of a millisecond. I imagine this might be very inaccurate though, and heavy dependant on windows and other processes being used. |
| ||
I'm doing an electronic project connected with the parallel port and i need an 1.5 millisecond delay to use servo motors. I'll try your method, Ross C. |
| ||
How about, run this code first to find out how many FOR/NEXT iterations are equivalent to 1500 ms then divide this figure by 1000 (should be most accurate). Unfortunately calls to millisecs() take a fair bit of comparitive time too. Instead of delay, then use For F=1 to xxx Next xxx |
| ||
It's incorrect, the correct program is: Timer=MilliSecs() For F=1 To 9999999 If xxx=0 If (MilliSecs()-Timer)=>1500 xxx=F Print F End If End If Next The value is 4726, so: for xxx=4276 next is 1.5 milliseconds. I tried this program: a=millisecs() for xxx=0 To 4726 next b=millisecs() print b-a and return 0 or 1, this mean the value is 0.5 milliseconds, and not 1.5, but i'll make 4276*3. Thanks |
| ||
It's incorrect, the correct program is: It's possible the result was 0.5 The difference is going to vary a lot between computers and current running processes. Chances are, the 2nd routine is MUCH quicker, because it doesn't have to check for IF's and call to Millisecs() which would slow the thing down. Instead of just For F=1 To xxx Next use Timer=MilliSecs() For F=1 To xxx If 1=1 If (MilliSecs()-Timer)=>1500 Print End If End If Next This should slow it down to match the initial test a little. |
| ||
The difference is here: For F=1 To 9999999 |
| ||
Oh. You need that many??? :) |
| ||
Yeah... I got 467300 for xxx in 1 second. RZ |
| ||
it's a tad inaccurate though, that's the only thing. It probably won't return the same result all the time. |
| ||
Then run it 100 times, ensuring the cpu isn't doing anything else or whatever and take an average. multiple testing in this manner is the best way to get the most accurate result. |
| ||
um, Why can't you use repeat/until time>3ms? does it make all that difference? |
| ||
Thjat'd be good, probably quicker in fact... |
| ||
Well, with all the dropouts with the guessing code, this is probrably going to function more acurately too. besides, all the motors ive played with? you can be anywhere >1.5ms. This must be a picky motor :P |