PDA

View Full Version : Another bizarre question...



Smitty
02-12-2005, 05:44 AM
This code...




MAIN:
DEBUG "."
'check for input
SERIN 16, 240, 15, TIMEOUT, [WAIT("*"), STR cmdIn\2]

'do some stuff
GOTO AFTER_INPUT

TIMEOUT:
'do some stuff

AFTER_INPUT:
'do some stuff

GOTO MAIN




Should run NO FASTER than 66 times per second with no input. There is a 15 ms timeout value... 1000ms / 15 ms = 66.6... and that doesn't even consider the time to execute all of the other instructions in the "Do some stuff" sections...

So when I let it run for 10 seconds, why does it print over 4000 dots in the console? I cut and pasted the output into notepad, saved it as a text file, and checked the file size in bytes... I tried various run times to get a better average... they all show that a dot is printed roughly every .0029 seconds.

How can this loop run in less than 3 ms per iteration when it should take 15 ms just to timeout?

(This could explain some funky timing issues with SERIN...)

MacGeek117
02-12-2005, 05:55 AM
Could you please post the whole program-you might get more help.
bugg

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
I think I know what I'm doing...

Smitty
02-12-2005, 06:06 AM
Well, the only line that is of any importance is the SERIN line... here, I rewrote it with nothing else in it. This program exhibits the very same behavior with only one SERIN statement, one debug statement, and 2 gotos.

I tested this particular program for 10 seconds... the loop ran in about 8 ms despite a 15 ms timeout. (My math was a little off before... its still way fast--2x what it should be--but not as bad as I indicated earlier).




' {$STAMP BS2sx}
' {$PBASIC 2.5}

cmdIn VAR Byte(2)

MAIN:
SERIN 16, 240, 15, NO_INPUT, [WAIT("*"), STR cmdIn\2]
GOTO MAIN

NO_INPUT:
DEBUG "."
GOTO MAIN

achilles03
02-12-2005, 09:28 AM
Ah, that's why... it's an SX. You should have stated that in your first post. The units for the timeout for the SX are .4ms, not 1ms.

Dave