' © Wolfstone, 2005 ' ========================================================================= ' ' File....... BeastValveExerciseOne ' Purpose.... Test the Crate Beast ' Author..... Dennis Griesser ' E-mail..... wolfstone@pobox.com ' ' {$STAMP BS1} ' {$PBASIC 1.0} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Test program for the Crate Beast Halloween prop. EXERCISE A SINGLE VALVE. ' ' For information about the I/O, peripheral boards, etc, please see ' BeastControllerSetup.txt ' -----[ Revision History ]------------------------------------------------ ' BeastValveExerciseOne_01.bs1 - 14 October 2007 ' -----[ I/O Definitions ]------------------------------------------------- SYMBOL TrigBeast = PIN7 ' input trigger on P7 - jumpered for pull-down SYMBOL TrigLid = PIN6 ' input trigger on P6 - jumpered for pull-down SYMBOL RedLED = PIN5 ' output debug feedback on P5 - bare LED SYMBOL GreenLED = PIN4 ' output debug feedback on P4 - bare LED SYMBOL Sio = 0 ' serial I/O on P0 ' -----[ Constants ]------------------------------------------------------- ' Communication with DC-16 Digital Control Board: SYMBOL Baud = OT2400 ' serial rate to talk to DC-16 SYMBOL Addr = %00 ' address of DC-16 board (%00 - %11) ' Solenoids: SYMBOL DoorOpen = 1 ' Open Door SYMBOL DoorClose = 2 ' Close Door SYMBOL ArmOpen = 3 ' Open Arm SYMBOL ArmClose = 4 ' Close Arm SYMBOL BeastOpen = 13 ' Open Beast SYMBOL BeastClose = 14 ' Close Beast SYMBOL LidOpen = 15 ' Open Lid SYMBOL LidClose = 16 ' Close Lid SYMBOL IsOff = 0 SYMBOL IsOn = 1 ' -----[ Variables ]------------------------------------------------------- SYMBOL RndNum = W0 ' 16-bit random number (and seed for next one) SYMBOL Solenoid = W1 SYMBOL Delay = W2 SYMBOL Cycles = B6 ' Using GOSUB on the BS1 requires variables B12 and B13 (W6) ' -----[ EEPROM Data ]----------------------------------------------------- ' -----[ Initialization ]-------------------------------------------------- Reset: ' 76543210 ' bit positions DIRS = %00111111 ' make P7-P6 inputs, P5-P0 outputs PINS = %00000000 ' all outputs off RedLED = IsOn ' turn on red LED to show LED works GreenLED = IsOn ' turn on green LED to show LED works SEROUT Sio, Baud, ("!DC16", Addr, "X") ' turn off all solenoids PAUSE 1000 ' wait 1.0 second ' GOSUB Clear ' Reset all solenoids to Normally Closed ' -----[ Program Code ]---------------------------------------------------- ' The main loop just sits and spins until it sees an incoming command. Main: DEBUG "Program to exercise one valve.", CR DEBUG CR FOR Cycles = 1 TO 10 DEBUG Cycles DEBUG "Exercise one valve..." GOSUB ExerciseOne ' Exercise! DEBUG "...done", CR NEXT DEBUG CR DEBUG "Program complete.", CR END ' -----[ Subroutines ]----------------------------------------------------- ' Using GOSUB on the BS1 requires variables B12 and B13 (W6), making those ' variables unavailable for general program use. ' Reset all solenoids to Normally Closed position. ' We have to do this because the solenoids are bistable. ExerciseOne: Solenoid = BeastOpen ' open GOSUB Ping PAUSE 1000 ' open for .5 second Solenoid = BeastClose ' close GOSUB Ping PAUSE 2000 ' close for .2 seconds RETURN ' Fire one solenoid _coil_ and return it to rest state. ' Since the valves are bistable, it is a good idea to remove ' power after every operation is complete. Removing power does not ' change the position of the pneumatic valve! Ping: ' Fire the solenoid that we want, and wait for it to happen. ' According to our experiments (backed by the LTV data sheet), ' it takes up to 30 mSec for the valve to switch. SEROUT Sio, Baud, ("!DC16", Addr, "P", Solenoid, IsOn) ' turn on PAUSE 100 ' wait .03 second for valve to respond ' PAUSE 30 ' wait .03 second for valve to respond ' The valve has switched. Remove the solenoid power. After sending ' this command, we must wait a little while for the parallel board ' to finish executing before we send another command. SEROUT Sio, Baud, ("!DC16", Addr, "P", Solenoid, IsOff) ' turn off PAUSE 5 ' wait .005 second for parallel board RETURN