Delay

Blitz3D Forums/Blitz3D Beginners Area/Delay

splinux(Posted 2005) [#1]
Do anyone know if i can use a floating point number with the delay function?
example:

Delay 1.5



Floyd(Posted 2005) [#2]
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 )

WaitKey
This means that Delay 1.5 is really the same as Delay 2.


splinux(Posted 2005) [#3]
And what can I do if I need a 1.5 milliseconds delay?
Are there any library, dll,...?


_PJ_(Posted 2005) [#4]
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?


Ross C(Posted 2005) [#5]
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.


splinux(Posted 2005) [#6]
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.


_PJ_(Posted 2005) [#7]


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



splinux(Posted 2005) [#8]
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


_PJ_(Posted 2005) [#9]

It's incorrect, the correct program is:

- What's the difference?


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.


splinux(Posted 2005) [#10]
The difference is here:

For F=1 To 9999999




_PJ_(Posted 2005) [#11]
Oh.

You need that many???

:)


Rook Zimbabwe(Posted 2005) [#12]
Yeah... I got 467300 for xxx
in 1 second.
RZ


Ross C(Posted 2005) [#13]
it's a tad inaccurate though, that's the only thing. It probably won't return the same result all the time.


_PJ_(Posted 2005) [#14]
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.


Damien Sturdy(Posted 2005) [#15]
um, Why can't you use repeat/until time>3ms? does it make all that difference?


_PJ_(Posted 2005) [#16]
Thjat'd be good, probably quicker in fact...


Damien Sturdy(Posted 2005) [#17]
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