Timer function for repeated delay?



#2

I'm looking for a delay timer function for the HP 41CX or any other HP calculator. I want to create a program that does the following:

 1) Accept a number of rounds
2) Accept a delay in seconds
3) Delay execution for the given delay time
4) Increment round number
5) If the requested number of rounds is reached
6) sound a long beep
7) stop
else
8) sound a short beep
9) go to (3)

I checked the CX timer functions but couldn't find a match. Can the stopwatch functions be used to implement this?

What is the easiest way to produce different beeps (without synthetics.)?


#3

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

	"^^WAKEUP"
0
DATE
TIME
increment time by n seconds
XYZALM
OFF
LBL "WAKEUP
continue execution

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.

**vp


Edited: 21 Jan 2006, 1:40 a.m.


#4

Quote:
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.

Not really a big problem (see the Ultimate Alarm Clock how this was solved).

#5

XYZALM allows you to put in the repeat interval, and starting the string in alpha with ^^ makes it a control alarm that will begin execution at the label whose name follows the ^^ in alpha. That program could do your incrementing, comparing, and beeping, and if it has reached the last one you wanted, clear the alarm to stop the repetition. If there is no label name after the ^^ in alpha when you set the alarm, then execution will resume where it had stopped the last time. The 41 does not need to be off for the alarm to work and take control. The first alarm time may need to be calculated. After that they will keep coming at the interval you specified until you (or your program) clear the alarm. This interval will not depend on execution speed, but you will want the execution to be completed before the alarm comes due the next time. IOW, if you want every 30 seconds, and the program takes 3 seconds to execute every time, and then you add more lines and it takes 8 seconds every time, it doesn't matter. The alarm will still come up every 30 seconds as specified, regardless.

User beeps are numbers 0-9 and are all the same length. Synthetic beeps allow different lengths and pitches, and range from 10-129. I might suggest TONE 7 and TONE 87, which are the same pitch but 7 is about three times as long as 87.


#6

Garth Wilson wrote:
> XYZALM allows you to put in the repeat interval ...

You are right. For some reason I thought Marcus required different timeouts depending on the round. Silly of me.

So, Marcus, if you want the reminder to be every n seconds, do as Garth suggested.

Note, however, that my warning regarding the date is still valid (i.e. make sure that TIME + n <= 23.59599).
Luckily this is required only for the first alarm. Repeat alarms will be handled by the Timer Module.

Another issue is how to stop the alarms once the required number of iterations has been reached. On a non-CX with a TIME module, you have to clear the alarm manually. On a 41CX you can use the CLALMA command to clear the alarm.

Finally be careful that the execution time of the program is shorter than the specified time interval. Otherwise the alarm processing routine will be interupted by the next alarm and so on, till you get in a total mess.

**vp


So here is an example program

; REPTMR -- Repeat Timer
; X iterations (i)
; Y sleep interval in seconds (ss)

01 LBL "REPTMR
02 STO 00 ; store i in R00
03 RDN ; bring ss to X register
04 1 E4 ; change ss to 0.00ss
05 /
06 "^^RING ; unconditional alarm function
07 0 ; use 0 to indicate that the alarm is due today
08 TIME
09 RCL Z ; bring 0.00ss into X-Register
10 + ; X := TIME + ss seconds
; here you are supposed to check if X > 23.59599 and do smth about it
11 XYZALM ; set the alarm
12 OFF ; wait

13 LBL "RING
14 DSE 00
15 GTO 01

16 BEEP ; final beep
17 CLALMA ; clear alarm
18 OFF ; terminate


19 LBL 01 ; repeat beep
20 TONE 3
21 TONE 3
22 OFF ; wait


#7

Thanks to both of you!

There is an additional difficulty: I want to be able to suspend execution after each beep with a key. Why? The timer is intended to monitor an IQ test with a given number of seconds for each question. Now what if my telephone rings?

I'll probably go for a simpler aproach that requires to hit a key to advance to the next round. This requires to reprogram the timer for each round but is much more flexible for the user. I'll keep you informed - about both the program and my IQ ;-)

Marcus


#8

Marcus von Cube wrote:
> There is an additional difficulty: I want to be able to suspend
> execution after each beep with a key.

Why didn't you say so from the beginning??????

It changes the whole program design!

In this case I'd use the GETKEYX command (HP-41CX only) which
takes the number of seconds to wait for the key as argument.

So you can use this program

; REPTMR -- Repeat Timer
; X iterations (i)
; Y sleep interval in seconds (ss)

01 LBL "REPTMR
02 STO 00 ; store i in R00
03 RDN ; bring ss to X register
04 LBL 00
05 VIEW 00 ; (optional) display countdown value
06 TONE 3 ; beep to let user know start of interval
07 GETKEYX ; wait for X seconds
08 X<>0? ; if nothing pressed, skip STOP
09 STOP ; freeze program
10 LASTx ; recover timeout value
11 DSE 00 ; decrement count
12 GTO 00
13 BEEP
14 END

If you press a key while it waits, it will stop (line 09). Pressing R/S will cause it to continue

So as friend used to say tell me what you want to do, not how you think you should do it :-)

**vp


#9

Hi Vassilis,

I was asking for a delay function in the first place. GETKEYX seems to be what I was asking for. I'll modify your solution slightly because I need to restart the round if it's interrupted. I like this aproach because it leaves the control to the program, not to an external timer.

Thanks again to all who replied.

Marcus


Possibly Related Threads…
Thread Author Replies Views Last Post
  HP50g: Writing a function that returns a function Chris de Castro 2 2,140 12-10-2013, 06:49 PM
Last Post: Han
  [Prime] Shutdown timer bug? Cristian Arezzini 2 1,684 11-16-2013, 10:34 AM
Last Post: Cristian Arezzini
  Apologies on mail delay. Diego Diaz 0 771 11-07-2012, 02:27 PM
Last Post: Diego Diaz
  New Blog Entry (repeated functions) is now up Eddie W. Shore 0 779 02-08-2012, 10:10 PM
Last Post: Eddie W. Shore
  Kitchen timer on 17B/17BII/17BII+/19B/19BII/27S y.miyata 1 1,087 03-04-2010, 12:18 PM
Last Post: Martin Pinckney
  hp 45 conversion to quartz timer Geoff Quickfall 5 1,612 01-22-2008, 08:44 PM
Last Post: Geoff Quickfall
  Timer with splits Sam Levy 2 1,065 06-09-2007, 03:42 PM
Last Post: Maximilian Hohmann
  33s repeated operations Sam Levy 2 1,028 03-13-2007, 10:11 AM
Last Post: Hal Bitton
  48GX computing delay Steve Jirsa 7 1,916 12-02-2005, 05:45 PM
Last Post: Arnaud Amiel
  HP-45 TIMER ROUTINE Hank 1 834 05-15-2005, 02:01 PM
Last Post: GWB

Forum Jump: