November 21, 2024, 01:37:06 PM

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.


Breaking out some of the dig outs to make inputs

Started by datbates, September 17, 2007, 03:20:37 PM

Previous topic - Next topic

datbates

With the normal vixen firmware it copies the digouts right from the serial stream (prop-2).   I had to comment that part out so that I could use one as an input.  However I want to use some as inputs and some as outputs.   It seems that if I ever use them as outputs they will no longer work as inputs for that program.  How do I not write to some of them?  Thanks.  This is for future expansion, so I am not in a hurry.  Thanks for all your quick answers of late!

JonnyMac

The idea behind that program is that Vixen is using the Prop-2 as a slave -- what do you want to do with the inputs that you can't control from Vixen?
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

September 17, 2007, 03:38:47 PM #2 Last Edit: September 17, 2007, 03:42:58 PM by JonnyMac
As an example, this Vixen driver breaks P15 from the outputs to be used an an input.  When the switchis off the outputs are cleared and the servos are centered; when the switch is on the program will accept data from Vixen -- no matter where Vixen is in its cycle (so be careful).

Note that the DIRS register has been modified to make P15 an input; you can write to it all day long, when in input mode that doesn't matter.

' =========================================================================
'
'   File...... Vixen.BS2
'   Purpose... Simple Vixen interface for Prop-2_8s8d.DLL driver
'   Author.... Jon Williams, EFX-TEK
'              Copyright (c) 2007 EFX-TEK
'   E-mail.... jwilliams@efx-tek.com
'   Started...
'   Updated... 14 MAY 2007
'
'   {$STAMP BS2}
'   {$PBASIC 2.5}
'
' =========================================================================


' -----[ Program Description ]---------------------------------------------
'
' This program serves as a slave interface to Vixen (www.vixenlights.com),
' when using the Prop-2_8s8d.DLL driver.
'
' Connect to PC using the Prop-2 programming port.
'
' Note: Set the Vixen Prop-2 driver baud rate to 9600 (this is the fastest
' practical baud for using the WAIT modifier of SERIN which is required
' to maintain sync with Vixen packets).
'
' Note: The best Vixen Event Period (Tools\Preferences\EventPeriod) is
' 40 ms; periods shorter will cause some packets to be missed by the Prop-2
' while periods longer may result in "rough" servo movement.
'
' Remove the SETUP jumpers from P12..P15.


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


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

RX              CON     16                      ' use programming port

Enabled         PIN     15                      ' P15; SETUP = DN

DigOuts         VAR     OUTH                    ' use P8..P14
Servos          VAR     OUTL                    ' use P0..P7

Servo8          CON     7
Servo7          CON     6
Servo6          CON     5
Servo5          CON     4
Servo4          CON     3
Servo3          CON     2
Servo2          CON     1
Servo1          CON     0


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

T2400           CON     396
T9600           CON     84                      ' recommended baud rate
T19K2           CON     32
T38K4           CON     6


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

Baud            CON     T9600                   ' use 9600!

Yes             CON     1
No              CON     0


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

idx             VAR     Byte                    ' servo index

pos1            VAR     Byte                    ' servo position values
pos2            VAR     Byte
pos3            VAR     Byte
pos4            VAR     Byte
pos5            VAR     Byte
pos6            VAR     Byte
pos7            VAR     Byte
pos8            VAR     Byte


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

Reset:
  OUTS = $0000                                  ' clear all pins
  DIRS = $7FFF                                  ' all outputs

  FOR idx = 0 TO 7                              ' center servos to start
    pos1(idx) = 150
  NEXT
  GOSUB Refresh_Servos

  IF Enabled = No THEN Reset                    ' wait for enabled input


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

Main:
  DO WHILE (Enabled = Yes)
    SERIN RX, Baud, 40, No_Serial,
      [WAIT ("VXN"), DigOuts,
         pos1, pos2, pos3, pos4, pos5, pos6, pos7, pos8]

No_Serial:
    GOSUB Refresh_Servos
  LOOP
  GOTO Reset


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

Refresh_Servos:
  PULSOUT Servo1, (pos1 * 5)
  PULSOUT Servo2, (pos2 * 5)
  PULSOUT Servo3, (pos3 * 5)
  PULSOUT Servo4, (pos4 * 5)
  PULSOUT Servo5, (pos5 * 5)
  PULSOUT Servo6, (pos6 * 5)
  PULSOUT Servo7, (pos7 * 5)
  PULSOUT Servo8, (pos8 * 5)
  RETURN
Jon McPhalen
EFX-TEK Hollywood Office

datbates

Thanks.  So whatever a program uses a io pin for first, it is that way for the rest of the run.  Cool.  I am currently using one for serial input, and in the future I expect to need some limit switches for some continuous rotation servos.  Thanks again!

JonnyMac

DIRS controls what a pin does; when a DIRS bit for a pin has a 1 in it, the pin is an output; when that bit has a 0 in it, the pin is an input.  You can write to input pins all day long -- nothing happens because the output bit is not connected to the pin (via DIRS).

Just keep in mind that when using the Prop-1/Prop-2 with Vixen, adding inputs that can override/ignore the Vixen command stream may make things tricky.
Jon McPhalen
EFX-TEK Hollywood Office