May 17, 2024, 01:36:25 AM

News:

You can now use Vixen to program your Prop-1 and Prop-2 controllers!  Get started quickly and easily, without having to learn PBASIC.  Details in the Library forum.


Vex to Multiple Servos

Started by JonnyMac, June 05, 2008, 11:58:32 AM

Previous topic - Next topic

JonnyMac

June 05, 2008, 11:58:32 AM Last Edit: June 05, 2008, 12:01:10 PM by JonnyMac
Yesterday I got a call from my friend (and make-up/FX wizard) Ralis Kahn -- he needs a little customized servo controller for a film shoot.  What he asked for was something we don't typically do: he wanted to servos on different channels do the same thing.  He's an easy-to-modify program that I whipped up for him; it uses a VEX transmitter tethered to the Prop-SX with the servo outputs on P0..P7; in this program channel 1 on the VEX controls the servos connected to P0 and P1; channel 2 controls the servos connected to P2 and P3; P4 through P7 correspond to channels 3 through 6, respectively.

' =========================================================================
'
'   File...... VEX_Custom.SXB
'   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... 05 JUN 2008
'
' =========================================================================


' -------------------------------------------------------------------------
' Program Description
' -------------------------------------------------------------------------
'
' Channel mapping:
'
' VEX 1         RB.0 & RB.1
' VEX 2         RB.2 & RB.3
' VEX 3         RB.4
' VEX 4         RB.5
' VEX 5         RB.6
' VEX 6         RB.7


' -------------------------------------------------------------------------
' Conditional Compilation Symbols
' -------------------------------------------------------------------------


' -------------------------------------------------------------------------
' Device Settings
' -------------------------------------------------------------------------

DEVICE          SX28, OSCXT2, TURBO, STACKX, OPTIONX, BOR42
FREQ            20_000_000
ID              "VexServo"


' -------------------------------------------------------------------------
' I/O Pins
' -------------------------------------------------------------------------

VexIn           PIN     RC.7 INPUT              ' P15, SETUP = UP, no ULN

Servos          PIN     RB                      ' servo control pins
Servo8         PIN     RB.7 OUTPUT
Servo7         PIN     RB.6 OUTPUT
Servo6         PIN     RB.5 OUTPUT
Servo5         PIN     RB.4 OUTPUT
Servo4         PIN     RB.3 OUTPUT
Servo3         PIN     RB.2 OUTPUT
Servo2         PIN     RB.1 OUTPUT
Servo1         PIN     RB.0 OUTPUT


' -------------------------------------------------------------------------
' Constants
' -------------------------------------------------------------------------

IsOn            CON     1
IsOff           CON     0

Yes             CON     1
No              CON     0


' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

tix             VAR     Word                    ' timing ticks
idx             VAR     Byte                    ' looping index

tmpB1           VAR     Byte                    ' for subs/funcs
tmpW1           VAR     Word


' =========================================================================
'  INTERRUPT
' =========================================================================


'  RETURNINT


' =========================================================================
  PROGRAM Start
' =========================================================================


' -------------------------------------------------------------------------
' Subroutine / Function Declarations
' -------------------------------------------------------------------------

DELAY_US        SUB     1, 2                    ' replaces PAUSEUS
DELAY_MS        SUB     1, 2                    ' replaces PAUSE

CH_TIMEOUT      SUB     0                       ' VEX channel timeout


' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  PLP_A = %0000                                 ' pull-up unused pins
  PLP_B = %11111111                             ' RB uses ULN pull-down
  PLP_C = %10000000


Main:
  tix = 0
  DO WHILE tix < 300                            ' wait for sync pulse
    IF VexIn = 0 THEN
      INC tix
      DELAY_US 10
    ELSE
      tix = 0
    ENDIF
  LOOP


Release_Sync:
  DO WHILE VexIn = 0                            ' wait for end of sync
  LOOP


' Note: It is okay to run multiple pins on the same servo
'       channel, but within the cycle a given output should
'       only be used once; i.e., do not assign the same output
'       to multiple VEX channels.

Ch1:
  Servos = %00000011                            ' set output(s) for CH1
  CH_TIMEOUT                                    ' finish CH1 timing

Ch2:
  Servos = %00001100
  CH_TIMEOUT

Ch3:
  Servos = %00010000
  CH_TIMEOUT

Ch4:
  Servos = %00100000
  CH_TIMEOUT

Ch5:
  Servos = %01000000
  CH_TIMEOUT

Ch6:
  Servos = %10000000
  CH_TIMEOUT


  Servos = %00000000                            ' clear servo outputs
  GOTO Main


' -------------------------------------------------------------------------
' Subroutine / Function Code
' -------------------------------------------------------------------------

' Use: DELAY_US duration
' -- duration is in microseconds
' -- replacement for PAUSE

SUB DELAY_US
  IF __PARAMCNT = 1 THEN                        ' byte value passed
    tmpW1 = __PARAM1
  ELSE                                          ' word value passed
    tmpW1 = __WPARAM12
  ENDIF
  PAUSEUS tmpW1
  ENDSUB

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

' Use: DELAY_MS duration
' -- duration is in milliseconds
' -- replacement for PAUSE

SUB DELAY_MS
  IF __PARAMCNT = 1 THEN                        ' byte value passed
    tmpW1 = __PARAM1
  ELSE                                          ' word value passed
    tmpW1 = __WPARAM12
  ENDIF
  PAUSE tmpW1
  ENDSUB

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

' Use: CH_TIMEOUT
' -- call at start of channel framing pulse

SUB CH_TIMEOUT
  DO WHILE VexIn = 1                            ' hold for framing pulse
  LOOP
  DO WHILE VexIn = 0                            ' hold for timing pulse
  LOOP
  ENDSUB

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


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


' -------------------------------------------------------------------------
' User Data
' -------------------------------------------------------------------------
Jon McPhalen
EFX-TEK Hollywood Office