Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

something about timing 1

Status
Not open for further replies.

qbasicking

Programmer
Aug 19, 2001
628
US
How do I get an object to scroll onto the screen? Here's the problem. I want a menu to scroll down and take exactly 1/3 of a second. I need to know how many lines to draw in each loop, how? the TIMER function doesn't work, it only goes in increments of .11 sec, I need it more precise, maybe thousandths of a second. here's what i got:

DO
LINE (100,100+A)-(200,100+A),15
T = TIMER
WHILE T+.01 < TIMER:WEND
A = A+1
LOOP UNTIL A = 100

The TIMER has to be more precise
 
Use a FOR-NEXT loop as a timing delay. First, check the machine speed by finding how many loops are done in 1 second, and work from there.
 
pebe:
I have done your way in the past, but for some reason it doesn't work. I use this code to get the speed variable:

a = TIMER
DO
t = t+1
LOOP UNTIL TIMER >= a+1
a 386 gets 120 and a P4 gets 420

then when I incorporate the varible into the program it doesn't work, it works too slow on the 386 and too fast on the P4. Is there some sort of quadratic formula I need to use? or something?
 
The reason this doesn't work is because DO-LOOP UNTIL loops at a different speed than FOR-NEXT. I'm working on figureing out what the difference is.
 
qbasicking, You're right - it's not that simple.

I thought it might be helpful to try a few tests. I did a DO-LOOP routine in QBX that counted the number of loops in 1 second as determined by TIMER. I also did the same loop but with PEEKing the Bios register at 0040:006C which changes every 18th of a sec, so the loops are per 1/18sec. I ran them with and without compiling, in a full screen under Windows 98, and in DOS6.22. Each prog was repeated for several minutes, and the results show the spread of loop counts and the percentage spread over that period.
My machine is an AMD 700MHz Duron.

DOS using Timer
not comp: 106529 107263 0.69% spread
exe: 94288 94643 0.38%
WIN using Timer
not comp: 93062 94779 2.02%
exe: 84647 86006 1.61%

DOS Peeking
not comp: 24333 24339 0.02%
exe: 20512 20551 0.19%
WIN Peeking
not comp: 21023 25842 22.92% ***
exe: 17634 22718 20.80%

*** that figure went up to 68.58% when windows started some disk activity!

The peeking routine would be no good if running under windows but seems the best otherwise. Windows obviously has lots of stuff running in the background and this steals time from the QB prog, so short timing periods cannot be very accurate.

 
You are right The type of Windows makes a huge difference. My P1 (windows 98) runs 6000 loops per second uncompiled, yet my P4 (windows xp) only runs 420. my 386(win 3.1) does 120.
My P1 does 15x as many loops as my P4
 
qbasicking:

You might like to try this, as you have a choice of several machines, whereas I've only got one. It is pretty accurate on my machine when run under DOS.

The first section, the test, counts the number of loops in one tick of the LSB of the Bios register (the Do routine starts when the reg changes, to get max accuracy). This takes 1/18.26 of a sec. From that the number of loops for 1 millisec is calculated. Min/Max gives the spread of loops.

Enter a multiplier for 'time'.

The second section loops for 'time' loops, with TIMER measuring time taken for the routine.

The dummy lines are to ensure that both DO-LOOP routines are the same length.

CLS
DEF SEG = &H40
min& = 1000000 : max& = 0 'initialise min/max

DO
IF INKEY$<>&quot;&quot; THEN END 'getout if using .exe version
'------- start of machine test ------
n = 0 : a% = PEEK(&H6C)
'/start when reg changes
DO : b% = PEEK(&H6C) : LOOP UNTIL a% <> b%
DO
n = n + 1
IF b > n THEN EXIT DO 'dummy line
a% = PEEK(&H6C)
IF a% <> b% THEN EXIT DO
LOOP
'----- end of machine test --------
IF n > max& THEN max& = n
IF n < min& THEN min& = n
PRINT &quot;Peeks: &quot;;a%;b%;: PRINT TAB(40); &quot;Loops: &quot;;n
PRINT &quot;Min/Max: &quot;;mni&;max&;
PRINT TAB(40);USING &quot;###.##&quot;;(max& - min&)/min& * 100;
PRINT &quot;% spread&quot;

sec = n * 18.26 'loops per second
ms = sec/1000 'per ms

time = 1000 * ms 'for 1 sec delay

'----- start of delay routine ------
b% = 1 : c% = 1 'dummies
n = 0 : t1! = TIMER
DO
n = n + 1
IF n > time THEN EXIT DO 'active line
a% = PEEK(&H6C) 'dummy line
IF b% <> c% THEN EXIT DO 'dummy line
LOOP
'------ end of delay routine -------
t2! = TIMER
PRINT &quot;Timers: &quot;;t1!;t2!:pRINT TAB(40);t2! - t1!;&quot;secs&quot;
PRINT
LOOP
END

I believe the Bios timer is advanced with a hardware interrupt, so it should never be wrong. So I think the spreads are due to possible delays in qbasic reading the regs to get TIMER. If that is the case, then this method should give the same results on any machine.

I would be intersted in your findings.
 
Your code worked alright, under DOS, but it was doing some odd things when I ran it under Windows XP.
I got a new code for timinga dn it seems to work pretty good.

F = 1000
DO
T = TIMER
FOR A = 1 TO F:NEXT
Q = TIMER-T
IF Q >.1 THEN EXIT LOOP
F = F*5
LOOP
SPEED = Q*F
 
oops, my bad!
if you want to use my code change the 6th line to say IF Q>.1 THEN EXIT DO; there is no such command as EXIT LOOP. lol
 
I think you have an error. Speed is number of loops/unit time, so surely your line should read F/Q not Q*F.

I tried your prog out. Then ran it several times within a second DO-LOOP. The results varied so I got the prog to print out Q.

There was a large variation on my machine - it read anything from .109 to .171secs, giving an error spread of over 50%. It seems that occasionally (and regularly), QB misses a read of the timer. I think if you use this in a program as a test for machine speed, you may need to run the prog for several cycles and take the lowest reading.

It may be just my machine at fault, and I would be interested in your comments.
 
no, i had it right, it is Q*F. Even though this is fairly accurate, you will need to modify it to work with your programs. Different graphics take longer to put of the screen. i have to double the loop to get it to do
LINE ()-(),,BF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top