November 23, 2024, 01:49:15 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.


Electric Chair Sequencer program not correct

Started by BigRez, November 12, 2008, 07:23:26 PM

Previous topic - Next topic

BigRez

Hi Jon (and others),

Trying to create a program for an Electric Chair.  There are eight actions that can occur and do so after a given amount of time between each action.  Four are connected to an RC-4 and four are driven by OUT0-3.  I've taken concepts from a few posts here, specifically a sequencer program and created this version.  I've only got it running with the trainer and debug, but can tell the PINS aren't getting set correctly.

The sequences are read and activated only while the trigger (PIN6) is pressed.  Once released all should be reset.  I include a "duration" in the EEPROM data which is really just a loop counter value. Once the counter reaches that value we'll get the next sequence.  There's got to be a better way of doing this while ensuring that the trigger hasn't been released.

Please have a look and see if you can spot the issue.  Oh, and of course, if there's a better way to do this then that would be helpful too.

Debug shows the following and I can tell the PINS value (in BOLD) is incorrect.  Looks like only the lowest bit.

NEXT:  bits=%00000000   Relays=%00000000   PINS=%01000000   Duration=50
NEXT:  bits=%10000000   Relays=%10000000   PINS=%01000000   Duration=150
NEXT:  bits=%10000001   Relays=%10000000   PINS=%01000000   Duration=200
NEXT:  bits=%10100001   Relays=%10100000   PINS=%01000000   Duration=200
NEXT:  bits=%10110001   Relays=%10110000   PINS=%01000000   Duration=255
NEXT:  bits=%11111001   Relays=%11110000   PINS=%01001000   Duration=20
NEXT:  bits=%10110111   Relays=%10110000   PINS=%01000110   Duration=20
NEXT:  bits=%10111001   Relays=%10110000   PINS=%01001000   Duration=20

Thanks in advance!

' =========================================================================
'
'   File...... ElectChair.bs1
'   Purpose... Controls eight effects of the Electric chair.  Four are
'              connected to an RC-4 device and four are connected to
'              pin0-3.  See EEPROM data for sequence of events.
'   Author.... M. Resnick
'              Concepts borrowed from EFX-TEX Forum content.
'   E-mail.... mike.resnick@sbcglobal.net
'   Started... 20081112
'   Updated...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


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

SYMBOL  Sio             = PIN7                  ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  p5              = PIN5                  ' nuttin
SYMBOL  p4              = PIN4                  ' nuttin
SYMBOL  Knock           = PIN3                  ' 12v motor
SYMBOL  Spray           = PIN2                  ' burning smell
SYMBOL  Blast           = PIN1                  ' valve for air vents
SYMBOL  Lift            = PIN0                  ' valve to left side

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

SYMBOL  Baud            = OT2400


' -----[ Variables ]-------------------------------------------------------
SYMBOL  relays          = B0       ' Relays data in eeprom is 00001111
SYMBOL   Shake           =  BIT0
SYMBOL   Smoke           =  BIT1
SYMBOL   Heat            =  BIT2
SYMBOL   Strobe          =  BIT3
SYMBOL  seqBits         = B1

SYMBOL  cycle           = B2
SYMBOL  pointer         = B3

SYMBOL  duration        = B4

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

Main:
  SEROUT Sio, Baud, ("!!!RC4", %00, "X")        ' clear RC-4


Reset:
  DEBUG "Resetting...", CR
  PINS = %00000000                              ' clear all outputs
  DIRS = %00001111                              ' make P0-P3 outputs
  relays = %0000                                ' turn off all RC-4 relays
  GOSUB Set_RC4
  cycle = 0

  PAUSE 10000                                   ' wait 10 seconds before starting...

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

Check_Trigger:
  cycle = cycle + 5 * Trigger                   ' update cycle
  IF cycle < 50 THEN Check_Trigger              ' wait for input

  pointer = 0                                   ' set pointer to first mem location
  GOSUB Next_Level                              ' go fetch (first) event sequence

Still_Active:
  PAUSE 20
  cycle = cycle + 1
  IF Trigger = 0 THEN Reset                     ' if trigger is off then reset  PAUSE 5
  IF cycle < duration THEN Still_Active         ' if haven't reached next level...

  GOSUB Next_Level                              ' Go get and set the next level...

  IF seqBits = %00000000 AND duration = 0 THEN Reset  ' Reset if we're done...
  GOTO Still_Active                             ' otherwise continue...


' -----[ Subroutines ]-----------------------------------------------------
' Responsible for resetting cycle counter and fetching the next sequence value
' from EEPROM memory.  There are really three items; first is data for the pins and RC4
' and second is a cycle duration. The first is divided into four bits by four bits.
' High four are for the RC4 and low four for the pins.
Next_Level:
  cycle = 0                                    ' reet cycle counter
  READ pointer, seqBits                        ' get data item 1 from EEPROM
  pointer = pointer + 1                        '   Advance the pointer
  READ pointer, duration                       ' get duration from EEPROM
  pointer = pointer + 1                        '   advance pointer
  DEBUG "NEXT:  bits=", #%seqBits

  PINS = seqBits & %00001111                   ' update outputs
  relays = seqBits & %11110000                 ' update RC-4 relays
  GOSUB Set_RC4

  DEBUG "  Relays=", #%relays, "  PINS=", #%PINS, "  Duration=", #duration, CR
  RETURN
' -------------------------------------------------------------------------

Set_RC4:
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)
  RETURN

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


' -----[ User Data ]-------------------------------------------------------
Level_Data:
'          +---------------- Shake  (RC-4.0)
'          |+--------------- Smoke  (RC-4.1)
'          ||+-------------- Heat   (RC-4.2)
'          |||+------------- Strobe (RC-4.3)
'          ||||+------------ Lift   (pin0)
'          |||||+----------- Blast  (pin1)
'          ||||||+---------- Spray  (pin2)
'          |||||||+--------- Knock  (pin3)
'          ||||||||
'          ||||||||    +---- timing cycles (do not exceed 255!)
  EEPROM (%00000000, 050)    ' do nothing for 50 cycles...
  EEPROM (%10000000, 150)    ' shake 'em a little...
  EEPROM (%10000001, 200)    ' shake and knock...
  EEPROM (%10100001, 200)    ' shake, knock, heat...
  EEPROM (%10110001, 255)    ' shake, knock, heat, strobe...
  EEPROM (%11111001, 020)    ' Keep the above active and start activating others...
  EEPROM (%10110111, 020)
  EEPROM (%10111001, 020)
  EEPROM (%10110001, 020)
  EEPROM (%11111101, 020)
  EEPROM (%10110001, 020)
  EEPROM (%10110111, 020)
  EEPROM (%10111001, 020)
  EEPROM (%10110101, 020)
  EEPROM (%10110011, 020)
  EEPROM (%10111001, 020)
  EEPROM (%11110101, 020)
  EEPROM (%11010011, 020)
  EEPROM (%11011001, 020)
  EEPROM (%10010101, 020)
  EEPROM (%00000000, 000)     ' end of show marker

JonnyMac

Here's my take on your program -- you may find it a little sleeker.

Note that your Sio definition was incorrect; you cannon use the PINx version with SERIN and SEROUT; you must use the pin #.  Note, too, that to get the relay bits from seqBits you must shift them left after the masking opperation.  The BS1 doesn't have shift operators so we can use / 16 -- that shifts the value right by four bits.

' =========================================================================
'
'   File......
'   Purpose...
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2008 EFX-TEK
'              Some Rights Reserved
'              -- see http://creativecommons.org/licenses/by/3.0/
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 13 NOV 2008
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------


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


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

SYMBOL  Sio             = 7                     ' SETUP = UP; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN
SYMBOL  p5              = PIN5                  ' nuttin
SYMBOL  p4              = PIN4                  ' nuttin
SYMBOL  Knock           = PIN3                  ' 12v motor
SYMBOL  Spray           = PIN2                  ' burning smell
SYMBOL  Blast           = PIN1                  ' valve for air vents
SYMBOL  Lift            = PIN0                  ' valve to left side


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

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

SYMBOL  Yes             = 1
SYMBOL  No              = 0

SYMBOL  Baud            = OT2400                ' B/R jumper removed


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

SYMBOL  relays          = B0
SYMBOL   Shake           =  BIT0
SYMBOL   Smoke           =  BIT1
SYMBOL   Heat            =  BIT2
SYMBOL   Strobe          =  BIT3

SYMBOL  seqBits         = B1
SYMBOL  timer           = B2
SYMBOL  pointer         = B3
SYMBOL  duration        = B4


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

Reset:
  PINS = %00000000                              ' clear all
  DIRS = %00001111                              ' set outputs

  SEROUT Sio, Baud, ("!!!!!RC4", %00, "X")      ' clear RC-4
  relays = %0000

Trigger_Hold:
  IF Trigger = IsOn THEN Trigger_Hold           ' force release

  PAUSE 10000


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

Main:
  timer = 0                                     ' reset timer

Check_Trigger:
  PAUSE 5                                       ' loop pad
  timer = timer + 5 * Trigger                   ' update timer
  IF timer < 50 THEN Check_Trigger              ' wait for 50ms input

  pointer = 0

Run_Show:
  READ pointer, seqBits
  pointer = pointer + 1
  READ pointer, duration
  pointer = pointer + 1

  IF duration = 0 THEN Reset

Set_Outputs:
  PINS = seqBits & %00001111
  relays = seqBits & %11110000 / 16
  SEROUT Sio, Baud, ("!RC4", %00, "S", relays)

  timer = 0

Run_Segment:
  IF Trigger = IsOff THEN Reset
  PAUSE 20
  timer = timer + 1
  IF timer < duration THEN Run_Segment
    GOTO Run_Show


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


' -----[ User Data ]-------------------------------------------------------

Show_Data:
'          +---------------- Shake  (RC-4.3)
'          |+--------------- Smoke  (RC-4.2)
'          ||+-------------- Heat   (RC-4.1)
'          |||+------------- Strobe (RC-4.0)
'          ||||+------------ Lift   (pin0)
'          |||||+----------- Blast  (pin1)
'          ||||||+---------- Spray  (pin2)
'          |||||||+--------- Knock  (pin3)
'          ||||||||
'          ||||||||    +---- timing cycles (do not exceed 255!)
  EEPROM (%00000000, 050)    ' do nothing for 50 cycles...
  EEPROM (%10000000, 150)    ' shake 'em a little...
  EEPROM (%10000001, 200)    ' shake and knock...
  EEPROM (%10100001, 200)    ' shake, knock, heat...
  EEPROM (%10110001, 255)    ' shake, knock, heat, strobe...
  EEPROM (%11111001, 020)    ' Keep the above active and start activating others...
  EEPROM (%10110111, 020)
  EEPROM (%10111001, 020)
  EEPROM (%10110001, 020)
  EEPROM (%11111101, 020)
  EEPROM (%10110001, 020)
  EEPROM (%10110111, 020)
  EEPROM (%10111001, 020)
  EEPROM (%10110101, 020)
  EEPROM (%10110011, 020)
  EEPROM (%10111001, 020)
  EEPROM (%11110101, 020)
  EEPROM (%11010011, 020)
  EEPROM (%11011001, 020)
  EEPROM (%10010101, 020)
  EEPROM (%00000000, 000)     ' end of show marker
Jon McPhalen
EFX-TEK Hollywood Office

BigRez

Sleeker?  I'll say so.  I guess it'll take a while longer to be able to think correctly when writing these programs.   ;)

Thank you!  This looks like it'll do just fine.

JonnyMac

The BASIC Stamp 1 (core of the Prop-1) came out in 1993 and I was an early adopter.  I have used them most days since so I'd say I have bit more practice.  Keep at it, we all get there.
Jon McPhalen
EFX-TEK Hollywood Office