November 02, 2024, 02:28:11 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.


Controlling DC16's with a Data table

Started by PDoyle, September 11, 2010, 12:58:26 PM

Previous topic - Next topic

PDoyle

(RE: a phone call made yesterday around this time)

I've written this script that activates the outputs of a DC16 using data from a data table.  The data is successfully communicated, but it turns on the wrong outputs.


' {$STAMP BS2}
' {$PBASIC 2.5}


'============================ Final Script 2 ===============================================
          'This is a short sample script from a longer script that tests the operation of
          'DC16's from a Data table.

'============================ Variables/Pins/Constants =======================================

Times VAR Nib
Status VAR Bit
Showpins VAR Word
Pointer VAR Word


T PIN 0                         '"T" for Tamok, fire spirit
A PIN 1                         '"A" for Avarita, earth spirit
S PIN 2                         '"S" for Sonsente, water spirit
Fire PIN 3                      'four illuminating symbols around the Sun
Water PIN 4
Earth PIN 5
Air PIN 6
                                'Pins 7-9 are windows 1-2, 4 in the sky.
                                'Window 3 is at DC 16 %00 Pin 16
Eyes PIN 10                     'Eyes in Sonsente
Red PIN 11                      'Color of the temple
Crystal PIN 12                  'Crystal inside the temple
Blue PIN 13                     'Color of the temple
Aux PIN 14                      'For communications to extensions
Prop PIN 15                     'For communications to Master

Baud CON 6

'============================== Main Program===============================================

Main:
  PAUSE 3000
  GOSUB Preshow
  PAUSE 5000
  GOSUB Serout_00                                      'Turns Pin 2 off
  PAUSE 1000
  END

'================================ Subroutines ===========================================

Serout_00:                                              'For sending messages to DC16
  READ Pointer, Word Showpins                           'at address %00
  SEROUT Aux, Baud, ["!DC16", %00, "S", Showpins]
  Pointer = Pointer + 1
  RETURN

Serout_01:                                               ' " at address %01
  READ Pointer, Word Showpins
  SEROUT Aux, Baud, ["!DC16", %01, "S", Showpins]
  Pointer = Pointer + 1
  RETURN

Serout_10:
  READ Pointer, Word Showpins                            ' " at address %10
  SEROUT Aux, Baud, ["!DC16", %10, "S", Showpins]
  RETURN

Preshow:
  GOSUB Serout_00                                  'Turns on Pin 2 of DC16 %00
  PAUSE 5000
  HIGH 7
  PAUSE 4000
  HIGH 8
  PAUSE 19300
  LOW 7
  LOW 8
  GOSUB Serout_00                                 'Turns on Pin 16 of DC16 %00
  PAUSE 9680
  GOSUB Serout_00                                 'Turns Pin 16 back off
  HIGH 9
  GOSUB Serout_10                                 'Turns on Pin 5 of DC16 %10
  PAUSE 100
  LOW 9
  GOSUB Serout_10                                 'Turns Pin 5 back off
  PAUSE 20
  HIGH 9
  PAUSE 7000
  LOW 9
  RETURN

'============================== Data Table ===========================================


Show_Data:

DATA Word %00000010, %00000000
DATA Word %00000010, %10000000
DATA Word %00000010, %00000000
DATA Word %00010000, %00000000
DATA Word %00000000, %00000000
DATA Word %00000000, %00000000

JonnyMac

It's always better to tell us what you want than to show us what doesn't work.  We can't always deduce the former from the latter.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

I have to go out so here's a quick framework that demos what I described yesterday.

' =========================================================================
'
'   File......
'   Purpose...
'   Author....
'   E-mail....
'   Started...
'   Updated...
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


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


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


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

Sio             PIN     15                      ' no ULN, SETUP = UP
Trigger         PIN     14                      ' SETUP = DN


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

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

Yes             CON     1
No              CON     0

#SELECT $STAMP
  #CASE BS2, BS2E, BS2PE
    T1200       CON     813
    T2400       CON     396
    T4800       CON     188
    T9600       CON     84
    T19K2       CON     32
    T38K4       CON     6
  #CASE BS2SX, BS2P
    T1200       CON     2063
    T2400       CON     1021
    T4800       CON     500
    T9600       CON     240
    T19K2       CON     110
    T38K4       CON     45
  #CASE BS2PX
    T1200       CON     3313
    T2400       CON     1646
    T4800       CON     813
    T9600       CON     396
    T19K2       CON     188
    T38K4       CON     84
#ENDSELECT

SevenBit        CON     $2000
Inverted        CON     $4000
Open            CON     $8000

Baud            CON     Open | T38K4            ' for EFX-TEK accessories


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

timer           VAR     Word

showPntr        VAR     Word                    ' points to start of show
showSteps       VAR     Byte                    ' steps in show

showBits        VAR     Word                    ' DC-16 channel bits
showBitsLo     VAR     showBits.lowbyte
showbitsHi     VAR     showBits.HIGHbyte

stepDelay       VAR     Word                    ' step delay (ms)


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

Reset:
  OUTH = %00000000 : OUTL = %00000000           ' clear all
  DIRH = %00000000 : DIRL = %00000000           ' set outputs

  showPntr = Show_00                            ' clear DC-16 outputs
  GOSUB Play_Show


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

Main:
  timer = 0
  DO WHILE (timer < 100)                        ' debounce = 100ms
    timer = (timer + 5) * Trigger
    PAUSE 5
  LOOP

  showPntr = Zipper
  GOSUB Play_Show

  PAUSE 10000

  GOTO Main


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

Play_Show:
  READ showPntr, showSteps                      ' get steps
  showPntr = showPntr + 1                       ' point to 1st step data
  DO WHILE (showSteps > 0)
    READ showPntr, Word showBits, Word stepDelay
    showPntr = showPntr + 4
    showSteps = showSteps - 1
    GOSUB DC16_Update
    PAUSE stepDelay
  LOOP

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

DC16_Update:
  SEROUT Sio, Baud, ["!AP16", %00, "S", showBitsLo, showBitsHi]
  RETURN


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


Show_00         DATA    1
                DATA    Word %0000000000000000, Word 0


' zip from OUT1 to OUT16 on DC-16, 100ms per step

Zipper          DATA    17
                DATA    Word %0000000000000001, Word 100
                DATA    Word %0000000000000010, Word 100
                DATA    Word %0000000000000100, Word 100
                DATA    Word %0000000000001000, Word 100
                DATA    Word %0000000000010000, Word 100
                DATA    Word %0000000000100000, Word 100
                DATA    Word %0000000001000000, Word 100
                DATA    Word %0000000010000000, Word 100
                DATA    Word %0000000100000000, Word 100
                DATA    Word %0000001000000000, Word 100
                DATA    Word %0000010000000000, Word 100
                DATA    Word %0000100000000000, Word 100
                DATA    Word %0001000000000000, Word 100
                DATA    Word %0010000000000000, Word 100
                DATA    Word %0100000000000000, Word 100
                DATA    Word %1000000000000000, Word 100
                DATA    Word %0000000000000000, 0
Jon McPhalen
EFX-TEK Hollywood Office

PDoyle

I'll keep that in mind next time.  Copying script from your example solved my problem. Thanks!