November 23, 2024, 11:07:16 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Vortex Motor and Lighting Controller

Started by Ryanm0085, October 09, 2009, 11:31:15 AM

Previous topic - Next topic

Ryanm0085

i was hoping someone could give me a hand.  I have a vortex tunnel that has black lights inside.  The motor will be on PIN 0, the blacklights will be on PIN 2.   All i need is when the trigger on PIN 7 is pushed, the black lights come on, pause for 2 seconds, then the motor turns on.  The trigger it a normally open push-button.  After 2 minutes, it will reset, motor off black lights off.  The catch is, i would like to have an emergency stop incase something happens to shut everything down.  The E-Stop is a normal closed switch.  when pushed, it latches open, breaking the circuit.  Thats it.  Im alright with the on and off of the lights and motor, but the E-stop is a little tricky for me.  The other thing is i was wondering if there was a way to put another push button on a nother trigger to toggle the black lights on and off.  Thanks Guys.  Appreciate the help.

JonnyMac

October 09, 2009, 12:10:13 PM #1 Last Edit: October 09, 2009, 12:43:25 PM by JonnyMac
Here's a program that uses a NC button on P6 as an E-Stop control.  The way it's wired if the circuit opens (by pressing the button or pulling the switch from the board) the program will jump to Reset, killing all outputs.

The key is to get rid of normal PAUSE statements and use a subroutine that samples the E-Stop input between delay "ticks."  The delay resolution is now 100ms instead of 1ms, but for this kind of program that is not a problem.

Important Lesson: You cannot simply bail out of a subroutine (that was called with GOSUB) with a GOTO (to Reset, that is), you must jump to the exit point (RETURN) to leave the subroutine cleanly.  If you don't, the RETURN stack (W6) will get hosed up and the program will misbehave later -- something you don't want when you're monitoring an E-Stop input.

[Edit] I moved an E-Stop check from Reset into the debounce loop -- this lets you disable triggering and the program, even if you've
dropped down into that loop.

' =========================================================================
'
'   File...... Vortex.BS1
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' Trigger = N.O. button/switch between P7.W and P7.R
' EStop   = N.C. switch between P6.W and P6.R



' -----[ Revision History ]------------------------------------------------


' -----[ I/O Definitions ]-------------------------------------------------

SYMBOL  Trigger         = PIN7                  ' SETUP = DN
SYMBOL  EStop           = PIN6                  ' SETUP = DN

SYMBOL  Light           = PIN2
SYMBOL  Motor           = PIN0



' -----[ Constants ]-------------------------------------------------------

SYMBOL  IsOn            = 1                     ' for active-high in/out
SYMBOL  IsOff           = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Okay            = 1
SYMBOL  Emergency       = 0


' -----[ Variables ]-------------------------------------------------------

SYMBOL  timer           = B2
SYMBOL  tix             = W5


' -----[ Initialization ]--------------------------------------------------

Reset:
 PINS = %00000000                              ' clear all
 DIRS = %00000101                              ' set output pins


' -----[ Program Code ]----------------------------------------------------

Main:
 timer = 0                                     ' reset timer

Check_Trigger:
 IF EStop = Emergency THEN Reset
 PAUSE 5                                       ' loop pad
 timer = timer + 5 * Trigger                   ' update timer
 IF timer < 100 THEN Check_Trigger             ' wait for 0.1 sec input

 Light = IsOn
 tix = 20                                      ' 2 seconds
 GOSUB Delay_Tix
 IF EStop = Emergency THEN Reset

 Motor = IsOn
 tix = 1200                                    ' 120 seconds (2 min)
 GOSUB Delay_Tix

 GOTO Reset


' -----[ Subroutines ]-----------------------------------------------------

Delay_Tix:
 IF EStop = Emergency THEN Delay_Exit          ' abort on E-Stop input
   IF tix = 0 THEN Delay_Exit                  ' delay done?
     PAUSE 100                                 ' no, hold 0.1s
     tix = tix - 1                             ' update tix
     GOTO Delay_Tix

Delay_Exit:
 RETURN

' -------------------------------------------------------------------------


' -----[ User Data ]-------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office