May 18, 2024, 02:06:33 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.


MultiTasking?

Started by steveo, September 20, 2007, 08:45:02 AM

Previous topic - Next topic

steveo

Jon,
Lets say my TOTs are walking up the path, I trigger an animation sequence, but then I have to wait till that bit of code runs through before I can trigger another (assuming I have only one prop1).

Can the SX multi-task, meaning can I have simultanous events running?

Any bits of clever code smoke and mirrors that might pull such a thing off for the Prop1?




JonnyMac

Are you saying you want to control two separate props for a single Prop-1?  Is that what you mean by multitasking?  If yes, we're raising the price! -- the idea behind a low-cost controller is that the build could afford to dedicate a single controller to a single prop.  Okay, I'm joking.

"Multii-tasking" is a very loaded term.  Yes... it can be done, even on a Prop-1 -- but with LIMITED capabilities.  You can create a program that runs two sequencers (so you only get digital outputs at a specific rate); nothing fancy like RANDOM or SEROUT, etc.

I wrote a whole article on this process for Nuts & Volts magazine: http://www.parallax.com/dl/docs/cols/nv/vol7/col/NV135.pdf


Here's an updated version of that program -- as you can see, it's a little tricky.

' =========================================================================
'
'   File....... Dual-Sequencer.BS1
'   Purpose....
'   Author..... Jon Williams
'               -- based on code by Allen Huffman
'   E-mail..... jwilliams@efx-tek.com
'   Started....
'   Updated.... 17 MAY 2006
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program converts the Prop-1 into a dual timer capable of simultane-
' ously and independently controlling two individual props.  The outputs
' for each prop are defined by an EEPROM table.  Each record in the table
' holds the new outputs for a given state as well as the timing for that
' state.  Bit7 of the outputs value indicates the end of the sequence. It
' is the programmer's responsibility to set Seq1Start and Seq2Start to
' the proper values before downloading the program.
'
' P6 and P7 are setup for active-high inputs -- move the SETUP jumpers to
' the DN position.


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


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

SYMBOL  Trigger2        = PIN7                  ' move setup to DN
SYMBOL  Trigger1        = PIN6                  ' move setup to DN


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

SYMBOL  IsOn            = 1                     ' for active-high input
SYMBOL  IsOff           = 0

SYMBOL  Running         = 1                     ' for status flags
SYMBOL  Stopped         = 0

SYMBOL  Yes             = 1
SYMBOL  No              = 0


SYMBOL  Seq1Start       = 0                     ' start point in EE
SYMBOL  Seq1Mask        = %00111000             ' protect P3-P5

SYMBOL  Seq2Start       = 12                    ' start point in EE
SYMBOL  Seq2Mask        = %00000111             ' protect P0-P2


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

SYMBOL  status          = B0                    ' sequence status flags
SYMBOL  seq1            = BIT0
SYMBOL  seq2            = BIT1
SYMBOL  pinsTemp        = B1                    ' temporary output
SYMBOL  endOfSeq        = BIT15                 ' 1 = end of sequence
SYMBOL  loopTmr         = B2
SYMBOL  pntr1           = B3                    ' pointer for seq 1
SYMBOL  timer1          = B4                    ' timer for seq 1
SYMBOL  pntr2           = B5
SYMBOL  timer2          = B6


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

Reset:
  PINS = %00000000                              ' clear outputs
  DIRS = %00111111                              ' set to output mode

  pntr1 = Seq1Start                             ' initialize pointers
  pntr2 = Seq2Start


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

Main:                                           ' test triggers, pad loop
  FOR loopTmr = 1 TO 5                          ' test 5x
    seq1 = seq1 | Trigger1                      ' update running flag
    seq2 = seq2 | Trigger2                      ' update running flag
    PAUSE 20                                    ' 5 x 20 ms = ~100 ms
  NEXT


Run_1:
  IF seq1 = Stopped THEN Run_2                  ' running?
    IF timer1 = 0 THEN Reload_1                 '  yes, timer expired?
      timer1 = timer1 - 1                       '   no, decrement timer
      GOTO Run_2

Reload_1:
  READ pntr1, pinsTemp                          ' read output state
  pinsTemp = pinsTemp & Seq2Mask                ' protect Seq1 pins
  PINS = PINS & Seq1Mask | pinsTemp             ' apply new outputs
  pntr1 = pntr1 + 1                             ' point to timing
  READ pntr1, timer1                            ' read it
  pntr1 = pntr1 + 1                             ' point to next record
  IF endOfSeq = No THEN Run_2                   ' at end?
    seq1 = Stopped                              ' - stop sequence
    pntr1 = Seq1Start                           ' - reset pointer


Run_2:
  IF seq2 = Stopped THEN Main                   ' running?
    IF timer2 = 0 THEN Reload_2                 '  yes, timer expired?
      timer2 = timer2 - 1                       '   no, decrement timer
      GOTO Main

Reload_2:
  READ pntr2, pinsTemp                          ' read output state
  pinsTemp = pinsTemp & Seq1Mask                ' protect Seq2 pins
  PINS = PINS & Seq2Mask | pinsTemp             ' apply new outputs
  pntr2 = pntr2 + 1                             ' point to timing
  READ pntr2, timer2                            ' read it
  pntr2 = pntr2 + 1                             ' point to next record
  IF endOfSeq = No THEN Main                    ' at end?
    seq2 = Stopped                              ' - stop sequence
    pntr2 = Seq2Start                           ' - reset pointer

  GOTO Main


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


' -----[ EEPROM Data ]-----------------------------------------------------

' Timing value is in ~100 millisecond units
' -- trigger check loop is 5 iterations x 20 ms

Sequence1:
  EEPROM (%00000001, 5)
  EEPROM (%00000010, 5)
  EEPROM (%00000100, 5)
  EEPROM (%00000010, 5)
  EEPROM (%00000001, 5)
  EEPROM (%10000000, 0)                         ' end of sequence


Sequence2:
  EEPROM (%00100000, 2)
  EEPROM (%00010000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00100000, 2)
  EEPROM (%00010000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00100000, 2)
  EEPROM (%00010000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00100000, 2)
  EEPROM (%00010000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%00100000, 2)
  EEPROM (%00010000, 2)
  EEPROM (%00001000, 2)
  EEPROM (%10000000, 0)

Jon McPhalen
EFX-TEK Hollywood Office

steveo

I look at that code, and I say to myself.. yikes.

Nice bit of work there, though.

So yes, you get the idea, I want to run multiple sequences off the same controller. While automation is the name of the game for most, I like the idea of firing off scares, lighting, sounds, and mayhem in an active role. Some like to dress in a sheet and yell boo, i'd rather wait for just the right moment to fire off a pop up.

I'm weird that way. Back on track - will the SX allow me this control? I'm willing to invest the time to learn.

JonnyMac

As I have suggested to others, If you don't understand what's happening on the Prop-1 there is really no sense attempting it on the Prop-SX (a far more sophisticated beast).  The key is understanding the process; once you get it on the Prop-1, implementing it elsewhere is possible.  The process is tricky, and it doesn't get easier on more sophisticated processors.
Jon McPhalen
EFX-TEK Hollywood Office