|Re: Timer function for repeated delay?|
Message #2 Posted by Vassilis Prevelakis on 21 Jan 2006, 1:14 a.m.,
in response to message #1 by Marcus von Cube, Germany
First the easy question:
> What is the easiest way to produce different beeps (without synthetics.)?
TONE accepts an argument 0 through 9, and it produces different
beeps according to the argument, giving you 10 different TONEs. With synthetics you can have around 99 different TONEs.
Now for the difficult question:
If I understand correctly, you essentially want a routine which suspends the execution of a program for n seconds, where n is supplied as a parameter.
In other words something like the Unix sleep n command.
If the stopwatch allowed you to call a function when it crossed zero, this would have been trivial to do. Unfortunately to the best of my knowledge, when the stopwatch timer crosses zero, it just makes some noices until you tell it to go away.
So there are two workarounds:
a) use STOPSW 0 SETSW RUNSW to start the stopwatch and have a
loop that repeatedly calls RCLSW and tests it against n. I am not really sure whether this will get you the required resolution though (i.e it may be slow by a second or two).
b) set an alarm in the future. For example
increment time by n seconds
This is a simplified algorithm which has a serious bug, namely it does not work near midnight when the date changes during the sleep period. In this case the n + TIME will be greater than 23.59599 and will be rejected by XYZALM.
Adding enough code to ensure that this works in the general case, will increase execution time by many seconds, affecting resolution.
Edited: 21 Jan 2006, 1:40 a.m.