November 23, 2024, 03:21:31 AM

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.


Trying to use a Parallax ServoPal with prop2

Started by GOT, November 22, 2011, 06:22:00 AM

Previous topic - Next topic

GOT

What am I doing wrong here? This is the first time I am trying to use a ServoPal to and nothing happens.  I have it plugging into PINs 0 and 1 and two servos hooked up. Everything is hooked up correctly according to the instructions and I am using the Parallax initiation code.


' {$STAMP BS2}
' {$PBASIC 2.5}
nInp PIN 0 'Define the input pin.
Alarm PIN 1 'Define the alarm pin.


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


ServoOffset   CON   250   ' servo 450 = fully closed, 700 half open, 900 fully open


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


pan           VAR        WORD                 ' servo position, 0 - 400
tilt           VAR        WORD

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

Reset:
 
  DIRS = %0000111111111111


Restart:
INPUT nInp 'Make sure nInp isn't being driven.
DO UNTIL nInp 'Wait for ServoPAL to power up.
LOOP
LOW nInp 'Set pin to an output and hold it low
PAUSE 100 ' for 100mS.
HIGH nInp 'Raise the pin.


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

Main:

pan = 95
tilt = 95
PULSOUT nInp, (pan + ServoOffset)                     ' refresh servos
PULSOUT nInp, (tilt + ServoOffset)                     ' refresh servos
PAUSE 4000

pan = 300
PULSOUT nInp, (pan + ServoOffset)                     ' refresh servos
PULSOUT nInp, (tilt + ServoOffset)                     ' refresh servos
PAUSE 4000

tilt = 300
PULSOUT nInp, (pan + ServoOffset)                     ' refresh servos
PULSOUT nInp, (tilt + ServoOffset)                     ' refresh servos
PAUSE 4000

pan = 95
tilt = 95
PULSOUT nInp, (pan + ServoOffset)                     ' refresh servos
PULSOUT nInp, (tilt + ServoOffset)                     ' refresh servos
PAUSE 4000
 

pan = 400
tilt = 400
PULSOUT nInp, (pan + ServoOffset)                     ' refresh servos
PULSOUT nInp, (tilt + ServoOffset)                     ' refresh servos
PAUSE 4000 

GOTO Main



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


JonnyMac

You're using the Prop-2 (BS2) but your pulse timing seems odd. Should be 500 (for 1ms) to 1000 (2ms) as the BS2 sends pulses in 2us increments.

To make your code easy to deal, and as you're dealing with words, anyway, I would suggest having your servo values be 600 to 2400 (0.6ms to 2.4ms for 180 degree servo) and then update them as required with this subroutine:

Update_Servos:
  PULSOUT nInp, (pos1 >> 1)
  PULSOUT nInp, (pos2 >> 1)
  RETURN


The >> 1 in the code is a fast way to divide the value by two which will deliver the correct value for PULSOUT. By using a subroutine you'll have less redundancy in your code.  You can update one or both of the values and call the subroutine; both servos will be taken care of.

Note: I don't have a ServoPal; I am making these suggestions based on many years of programming Parallax processors.
Jon McPhalen
EFX-TEK Hollywood Office

JonnyMac

Just another thought... The ULN2803 input circuitry acts like a pull-down and you may want to pull the ULN pin that corresponds to nInp so that it has no influence.
Jon McPhalen
EFX-TEK Hollywood Office

GOT

Sorry, I see that I did not change my ServoOffset constant back to 450 (I was playing with the timing).  Even with the constant at 450 (which means I was sending signals from 545msec to 850msec) the servos did not respond.  They do respond with a program using similar timeing but controling only one servo without the ServoPal.
Forgive my newbiness, but I have no idea what you mean by pulling the nInp pin. I am using the recommending ServoPal initialization and the nInp pin is the one getting the signals so what "influence" are you refering to?

JonnyMac

For the time being, pop the ULN associated with the port that is using the ServoPal out of its socket -- this will prevent it from interfering with the "ready" signal from the ServoPal.
Jon McPhalen
EFX-TEK Hollywood Office

GOT

OK, I simplified the code and popped out the ULN. No dice. Not even a jitter. I guess I didn't understand why you were dividing the servo inputs by two, but I know these values work with my servos without the servopal.  Maybe the servopal is dead. I guess it is time to talk with Parallax.

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

nInp PIN 0          'Define the input pin.
Alarm PIN 1        'Define the alarm pin.

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

pan           VAR        WORD                 
tilt           VAR        WORD

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

Reset:
  DIRS = %0000111111111111


Restart:
INPUT nInp              'Make sure nInp isn't being driven.
DO UNTIL nInp         'Wait for ServoPAL to power up.
LOOP
LOW nInp                'Set pin to an output and hold it low
PAUSE 100              ' for 100mS.
HIGH nInp              'Raise the pin.



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

Main:

pan = 595
tilt = 595
PULSOUT nInp, pan                   
PULSOUT nInp, tilt                   
PAUSE 4000

pan = 800
PULSOUT nInp, pan                   
PULSOUT nInp, tilt                   
PAUSE 4000

tilt = 800
PULSOUT nInp, pan                   
PULSOUT nInp, tilt                   
PAUSE 4000

pan = 595
tilt = 595
PULSOUT nInp, pan                   
PULSOUT nInp, tilt                   
PAUSE 4000
 

pan = 900
tilt = 900
PULSOUT nInp, pan                     
PULSOUT nInp, tilt                   
PAUSE 4000 

GOTO Main



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


livinlowe

Do you have the servo pal on the headers correctly with white red black in the proper order?
Shawn
Scaring someone with a prop you built -- priceless!

GOT


bsnut

November 23, 2011, 10:19:08 AM #8 Last Edit: November 23, 2011, 11:15:26 AM by bsnut
What I suggest you to do, is try demo the program that comes with the ServoPal first to see if it works first before returning it.
William Stefan
The Basic Stamp Nut

JonnyMac

QuoteI guess I didn't understand why you were dividing the servo inputs by two

Because the BS2 in the Prop-2 uses 2us units for PULSOUT commands.  What this means is that if you want to create a 1ms (1000us) pulse, you have to use a value of 500.
Jon McPhalen
EFX-TEK Hollywood Office