November 21, 2024, 11:33:42 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


Delays That Do Work

Started by JonnyMac, September 05, 2009, 01:14:28 PM

Previous topic - Next topic

JonnyMac

We're all familiar with the PAUSE instruction which causes the Prop-1/2/SX to do nothing for some number of milliseconds; easy-breezy.  The problem with PAUSE, however, is when we need to hold the program and be doing something else at the same time -- refreshing a servo, for example.   Here's a subroutine that you can substitute for PAUSE that will refresh the servo while performing the required delay.

' Delays "timer" milliseconds
' -- Set milliseconds to delay in "timer" (word variable)
' -- Servo position is in "pos" (byte variable)

Servo_Delay:
 IF timer < 20 THEN SD_Exit
   PULSOUT Servo, pos
   PAUSE 19
   timer = timer - 20
   GOTO Servo_Delay

SD_Exit:
 PAUSE timer
 RETURN


To use this routine you have to do something like this:

 timer = 1000
 GOSUB Servo_Delay


This assumes that the value of "pos" already holds the servo position.


Another friend of EFX-TEK had a requirement to scan a trigger input while running a delay; if the trigger had input during the delay it would abort.    Here's a version of that code:

' Delays "timer" milliseconds
' -- Set milliseconds to delay in "timer" (word variable)
' -- Scans "Trigger" input; debounces for 100ms input

Trigger_Delay:
 trTix = 0

TD_Loop:
 IF timer < 5 THEN TD_Exit
   PAUSE 5
   trTix = trTix + 5 * Trigger
   IF trTix >= 100 THEN TD_Abort
     timer = timer - 5
     GOTO TD_Loop

TD_Exit:
 PAUSE timer
 timer = 0

TD_Abort:
 RETURN


When using this you load "timer" and call it.  How can you tell if it aborted early?  If timer is greater than zero when it RETRNs from the call then the Trigger input was debounced as active; if timer is zero then the delay completed.  Here's a snippet of code that will turn on an output for about 5 seconds, unless a new trigger shows up during the delay which will restart the on duration.

Main:
 timer = 100
 GOSUB Trigger_Delay
 IF timer = 0 THEN Main

Light_On:
 Light = IsOn
 timer = 5000                                  ' on for 5 secs
 GOSUB Trigger_Delay
 IF timer > 0 THEN Light_On                    ' restart if new trigger
   Light = IsOff
   GOTO Main




Jon McPhalen
EFX-TEK Hollywood Office