November 17, 2024, 03:40:01 PM

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.


Parallax ServoPAL Demo

Started by JonnyMac, May 27, 2008, 09:39:14 PM

Previous topic - Next topic

JonnyMac

May 27, 2008, 09:39:14 PM Last Edit: May 28, 2008, 08:55:18 AM by JonnyMac
While up vising my pals at Parallax last week they gave me a couple ServoPAL modules so that I could whip up a little Prop-1 program for our customers -- here it is.

Notes:
-- the ServoPAL uses active-low inputs, so the ULN may interfere; clip pins
    * 8 :: this corresponds to P1 which is the ServoPAL command pin
    * 9 :: only if you want to use the alarm function of the ServoPAL; if not you may use P0 any way you want
-- commands for servo position go out P1
-- alarm input, if used, comes back on P0; if not used P0 can do other things
-- both servos are controlled by pulses sent out P1
-- mount the ServoPAL onto the Prop-1 so that the little PCB "flag" points toward the reset button

' =========================================================================
'
'   File...... ServoPAL.BS1
'   Purpose... Demo program for the Parallax ServoPal module (#28824)
'   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...
'
'   {$STAMP BS1}
'   {$PBASIC 1.0}
'
' =========================================================================


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


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


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

SYMBOL  Sio             = 7                     ' SETUP = out; no ULN
SYMBOL  Trigger         = PIN6                  ' SETUP = DN

SYMBOL  SPInp           = PIN1                  ' SP status in
SYMBOL  SPCmd           = 1                     ' for pulse outputs

SYMBOL  SPAlarm         = PIN0                  ' SP alarm in


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

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

SYMBOL  Baud            = OT2400


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

SYMBOL  pos1            = B2                    ' 50 to 250
SYMBOL  pos2            = B3

SYMBOL  alarmSet        = W5                    ' each unit = 0.5 seconds


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

Reset:
  INPUT SPCmd
  IF SPInp = 0 THEN Reset                       ' wait for ServoPal

  DEBUG "SP alive", CR

  LOW SPCmd                                     ' reset the ServoPal
  PAUSE 100
  HIGH SPCmd

  DEBUG "SP reset -- sending commands", CR


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

Main:
  pos1 = 150
  pos2 = 150
  alarmSet = 10                                  ' 5 seconds
  GOSUB Update_Servos
  GOSUB Wait_For_Alarm

  pos1 = 125
  pos2 = 125
  alarmSet = 10
  GOSUB Update_Servos
  GOSUB Wait_For_Alarm

  pos1 = 175
  pos2 = 175
  alarmSet = 10
  GOSUB Update_Servos
  GOSUB Wait_For_Alarm

  GOTO Main


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

Update_Servos:
  PULSOUT SPCmd, pos1
  PULSOUT SPCmd, pos2
  PULSOUT SPCmd, alarmSet
  RETURN

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

Wait_For_Alarm:
  IF SPAlarm = 0 THEN Wait_For_Alarm
  DEBUG "Alarm detected", CR
  RETURN

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


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


Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Since a picture is worth a 1000 words.... the diagram below shows which pins to clip on the ULN2x03 when using the ServoPAL with the demo code above.

Jon McPhalen
EFX-TEK Hollywood Office