Can't get a servo to do what I want?

SpragmaticSpragmatic Posts: 59
edited 2013-01-02 - 12:25:56 in Microcontrollers
Can't for the life of me figure out what's going on here? I'm trying to get a servo to function with the SX28. I've written a simple code using PULSOUT to test and it just doesn't want to work. I thought it might be my SX Key causing it, but I wrote another simple code for some on/off leds and that works fine. I'm trying all of this on the Professional Development Board Rev D. Thought maybe the board was wonky. Tried on my SX Tech Board with same results. Tried different chips as well with same results. Has to be the code right? I have not tried running servo off of seperate power supply yet. Could it be that I'm running off of board regulator suppy VDD? Here is the code I'm working with. Please let me know if you can think of anything that I'm doing wrong. I'm working on a project that has multiple servos and linear actuators and would like to figure out all my timings and such. Controlling servos and actuators with RC radio for now, but will need SX to control once all is done. Yes I know the Propeller would be a great choice for this, but I have a hard enough time using SX/B. And I've got a bunch just sitting here ready for use. :-) Thanks in advance!! Greg



DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ 4_000_000

Servo PIN RC.4 OUTPUT

counter VAR WORD

PROGRAM Start

Start:

FOR counter = 1 To 150
PULSOUT Servo, 1000
PAUSE 20
NEXT

FOR counter = 1 To 150
PULSOUT Servo, 500
PAUSE 20
NEXT

FOR counter = 1 To 150
PULSOUT Servo, 750
PAUSE 20
NEXT

END

Comments

  • Duane DegnDuane Degn Posts: 10,002
    edited 2012-12-02 - 18:26:48
    Spragmatic wrote: »
    I have not tried running servo off of seperate power supply yet. Could it be that I'm running off of board regulator suppy VDD?

    How are you powering the servo? It's unclear from your post.

    Servos need a lot of current to start moving. Most of the servo problems I've seen on the forum are from using power supplies that can't provide enough current.

    If you use a seperate power supply for the servo make sure the supplies share a common ground connection.
  • SpragmaticSpragmatic Posts: 59
    edited 2012-12-02 - 18:40:53
    Duane-

    I'm powering off of the servo port on the Professional Development Board which is Vdd and Vss. I should of mentioned that the servo does work it just doesn't do what I want it to with the code. I'm assuming from the code that it should go counterclockwise first then clockwise second then center out and stop. When started the servo goes all the way counterclockwise and stays. It's timing seems right because I have a LED to monitor the movement and it stays on for the duration. Hope that all made sense? Just not sure why it doesn't rotate correct? Thanks!
  • Duane DegnDuane Degn Posts: 10,002
    edited 2012-12-02 - 18:50:20
    Spragmatic wrote: »
    Duane-

    I'm powering off of the servo port on the Professional Development Board which is Vdd and Vss. I should of mentioned that the servo does work it just doesn't do what I want it to with the code. I'm assuming from the code that it should go counterclockwise first then clockwise second then center out and stop. When started the servo goes all the way counterclockwise and stays. It's timing seems right because I have a LED to monitor the movement and it stays on for the duration. Hope that all made sense? Just not sure why it doesn't rotate correct? Thanks!

    It does look like the board may providing enough power.

    How about adding some debug statements between direction changes or LEDs to make sure the program is making it all the way through?

    I haven't ever used a SX chip so I'm not much help with the programming.
  • SpragmaticSpragmatic Posts: 59
    edited 2012-12-02 - 19:22:48
    Honestly I don't quite understand the Debug screen in the SX Compiler. I did look at it while running and it seems to be stuck at Start: That's where I get confused. If the code isn't right I'm not sure where to go from there. I think I'm going to test this on my old Basic Stamp Homework board to see if it works there. Then at least I can rule out hardware. I have tried a few other servos so it has to be the code I'm guessing? Thanks!
  • Duane DegnDuane Degn Posts: 10,002
    edited 2012-12-02 - 19:40:04
    Spragmatic wrote: »
    Honestly I don't quite understand the Debug screen in the SX Compiler. I did look at it while running and it seems to be stuck at Start:

    What does the debug look like without the servo attached? Does it still get stopped at start? If not, then it's a power supply problem (still my bet).
  • SpragmaticSpragmatic Posts: 59
    edited 2012-12-02 - 20:26:23
    So I tried a seperate power source. Does the same thing. Ran simlar code on Basic Stamp Homework Board and it works fine. Has to be something I'm missing in the code to work on the SX28. Hopefully someone will chime in and let me know what I'm doing wrong. I'll keep trying though. At least now I know all hardware is good. At least I hope so. :-) Those new SX Keys ain't cheap! Thanks Duane!
  • W9GFOW9GFO Posts: 3,847
    edited 2012-12-02 - 23:19:23
    I think the problem is that you are not sending it a valid pulsewidth.

    The BS2's PULSOUT command has each unit equal to two microseconds. So PULSOUT 750 sends a 1,500 microsecond (1.5 millisecond) pulse.

    The SX uses PULSOUT units that are equal to a minimum of ten microseconds each. Your code is sending pulses that vary from 5,000 to 10,000 microseconds (5.0 to 10.0 milliseconds).

    Refer to the command reference for more info.
  • SpragmaticSpragmatic Posts: 59
    edited 2012-12-03 - 06:56:35
    W9GFO wrote: »
    I think the problem is that you are not sending it a valid pulsewidth.

    The BS2's PULSOUT command has each unit equal to two microseconds. So PULSOUT 750 sends a 1,500 microsecond (1.5 millisecond) pulse.

    The SX uses PULSOUT units that are equal to a minimum of ten microseconds each. Your code is sending pulses that vary from 5,000 to 10,000 microseconds (5.0 to 10.0 milliseconds).

    Refer to the command reference for more info.


    W9GFO-

    You are exactly right. I woke up in the middle of the night remebering that the PULSOUT units are different on the SX. Doh! I just tested it on the PDB and it works great! Now I can begin figuring my project out. Thanks!!
  • ZootZoot Posts: 2,226
    edited 2012-12-04 - 08:41:19
    FYI -- If you end up needing finer resolution than 10us, you will need to use ISR-based servo code.

    More importantly, it looks like are using the internal 4mhz oscillator -- be warned that this can drift, esp. with temperature, which can affect the timing of things like servo output pulses. This was not your original problem, obviously, but it is something to think about. The drift can be up to 8% or so.
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • Duane DegnDuane Degn Posts: 10,002
    edited 2012-12-04 - 11:07:44
    Zoot wrote: »
    FYI -- If you end up needing finer resolution than 10us, you will need to use ISR-based servo code.

    10us isn't really course, but I've recently been centering my hexapod servos and I find I often need better than 10us resolution to get the servos positioned correctly.


    If you want to switch your project over to a Propeller, you'll find lots of help on the Propeller forum. The Prop and Beau's servo object make using servos really easy.

    Here's a couple examples:

    http://forums.parallax.com/showthread.php?137597-QuickStart-Driving-32-Servos-(Video)
    http://forums.parallax.com/showthread.php?138088-Popsicle-Stick-Hexapod-Attempt-(walks-with-tether)
    http://forums.parallax.com/showthread.php?137197-QuickStart-Servo-Tester

    You can also use the Propeller to receive inputs from a RC receiver.

    http://forums.parallax.com/showthread.php?143879-Object-to-Read-6-RC-Receiver-Channels-on-Any-I-O-Pins
  • ZootZoot Posts: 2,226
    edited 2012-12-04 - 12:14:56
    I know the Prop is awesome, but with a suitable resonator, a $1.10 SX28 can serve as 1-2us resolution servo controller with simple serial (or as a SPI slave), with group moves, ramping, etc. And no need for external EEPROM, etc.

    And this is the SX forum :)

    (sorry can't help myself -- just love my SXs)
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • Duane DegnDuane Degn Posts: 10,002
    edited 2012-12-04 - 13:28:53
    [QUOTE=Zoot;1147311(sorry can't help myself -- just love my SXs)[/QUOTE]

    Fair enough. I haven't used a SX but it seems like anyone who has, loves them. If they weren't EOL I might try to learn how to use them. I didn't realize an external resonator would improve the resolution so much (probably why you recommended it).

    In my defense (for bring up the Prop in the SX forum), the OP did mention the Propeller and. . . (can't help myself - just love my Props).
  • ZootZoot Posts: 2,226
    edited 2012-12-04 - 13:51:44
    The external resonator won't improve resolution per se, it's just that at 4mhz (whether the sloppy internal oscillator or an external clock source) the device is too slow to run a very very fast ISR. The Prop isn't any different -- clearly WAITCNT at 80mhz provides a whole other order of resolution than WAITCNT at 4mhz.

    The bigger issue, generally, is that for time-critical applications (accurate pulse generation/measurement, serial comms, etc.) the internal 4mhz (and slower) RC oscillator circuits in the SX aren't particularly accurate and are subject to drift over time and with big temperature swings.

    The SXs are really great for speed, determinism and simplicty of layout, programming and few external parts. The only thing that is old about 'em, IMO, is the total lack of any on-board EEPROM storage -- even for just a handful of program-written-overwritten config numbers. And they're kinda power hungery (by modern standards) at speeds over 20mhz.
    When the going gets weird, the weird turn pro. -- HST

    my site: 1uffakind.com
    create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
    resistor ladder tool: 1uffakind.com/robots/resistorLadder.php
    convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
    MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
  • 4x5n4x5n Posts: 716
    edited 2012-12-04 - 17:27:23
    Duane Degn wrote: »
    Fair enough. I haven't used a SX but it seems like anyone who has, loves them. If they weren't EOL I might try to learn how to use them. I didn't realize an external resonator would improve the resolution so much (probably why you recommended it).

    In my defense (for bring up the Prop in the SX forum), the OP did mention the Propeller and. . . (can't help myself - just love my Props).

    Maybe it's time for you to pick a few SX procs. :lol:

    The price is right and they are nice little chips. With an external resonator they'll run at 50MIPs.
  • RobotWorkshopRobotWorkshop Posts: 2,300
    edited 2012-12-05 - 12:38:56
    How many servos do you need to control? If you are controlling just one or two servos there is another option. I was using the SX48 more often than the SX28 chips and the SX48 has a pair of 16-bit timers. You can use each one to control a servo. I used that method on a small Sumo robot for my son. Worked out well. That way the hardware handled the control of the servo and I could use the ISR routines for something else. It was like having a built-in ServoPAL module...

    Robert
  • SpragmaticSpragmatic Posts: 59
    edited 2012-12-05 - 20:36:02
    Thanks everyone for the insight!

    RobotWorkshop- I will be trying to control (6) servos and (1) RC Firgelli linear actuator. Hopefully? :-) It's been trying to get the linear actuator to function right with code. I can get the servos to work just fine, but not the actuator. I'm gonna get more info from the manufacture to figure this out. Not sure if anyone has tried to use these?
  • RobotWorkshopRobotWorkshop Posts: 2,300
    edited 2012-12-11 - 09:26:38
    I haven't tried any of those linear actuators. One thing that you may way to keep on hand is one of these small testers:

    http://www.ebay.com/itm/RC-Helicopter-Plane-CCPM-Servo-ESC-Consistency-Tester-/120960776997

    They work well for setting up the servos and testing them. If the linear actuator doesn't work with one of these then perhaps it needs a different protocol to control it.

    Robert
  • RogerLouieRogerLouie Posts: 2
    edited 2013-01-02 - 12:25:56
    Hi Spragmatic,

    I stumbled upon your call for help on using a SX28 to drive a common RC Servo. After trial and error, it appears that your PULSOUT command has incorrect pulse duration numbers, which were 10 times what they should have been. I had the same problem understanding the "default resolution" pulse duration value for that command. If you bring up the help screen information on PULSOUT using the SX/B help command, it tries to describe the "various" parameters of that command. You and I used the "default resolution" timing, which I would stick with for myself. Good luck on your project, and speak up of this code does not work. January 2, 2013.
    '----THIS CODE SEEMS TO FIX YOUR SERVO PROBLEM THAT "Spragmatic" HAS.
    '----CIRCUIT TESTED ON SX TECH BOARD, REV-B, 7.5VDC INPUT REGULATED TO 5.0VDC
    '----SERVO USED:  PARALLAX STANDARD SERVO, 4MHz PARALLAX RESONATOR, SX28
    '----SX-KEY VERSION 3.3.0,  SX/B VERSION 1.5 , SERVO POWERED FROM SAME SX28 5.0VDC==Vdd
    '----CORRECTIONS/COMMENTS BY ROGER LOUIE, [email]RWLSUPPORT@AOL.COM[/email] , 1-2-2013
    DEVICE SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
    FREQ 4_000_000
     
    Servo PIN RC.4 OUTPUT
     
    counter VAR WORD
     
    PROGRAM Start
     
    Start:
    
    '----GENERAL SERVO OPERATION NOTES:
    '----RADIO CONTROL SERVOS REQUIRE LOW-HIGH-LOW PULSE BETWEEN APPROX:
    '----  1.00mS ... 1.50mS ... 2.00mS  (COMMONLY STATED VIA INTERNET LIMITS)
    '----  0.50mS ... 1.50mS ... 2.50mS  (PARALLAX STANDARD SERVO LIMITS)
    '----  SERVO ROTATION:  MINIMUM    CENTERED   MAXIMUM
    '----THIS PULSE SHALL BE REPEATED EVERY 20mS IN ORDER
    '----FOR THE SERVO TO RETAIN IT'S POSITION.
     
    '----ROTATE SERVO FULLY COUNTER-CLOCKWISE
    FOR counter = 1 To 150	'----LOOP 150 TIMES
    			'----(APPROX: 150 * 0.020sec = 3.00 SECONDS)
    
     '-------IMPORTANT_INFORMATION_TO_UNDERSTAND---------------------------
     'PULSOUT Servo, 5 	'---- 50 µs pulse (THIS IS FROM SX/B HELP INFO)
     '                      '---- NOTICE THAT 5 GIVES 50 MICRO SECONDS, AND
     '                      '----                    NOT MILLI SECONDS!!!
     '---------------------------------------------------------------------
    
     'PULSOUT Servo, 1000	'----(ORIG CODE - 1000 NUMBER TOO BIG!!!)
     'PULSOUT Servo, 100	'----COMMON SERVO PULSE 1000uS = 1.00mS (FIXED CODE)
     PULSOUT Servo, 50	'----PARALLAX SERVO PULSE 500uS = 0.50mS (FIXED CODE)
     PAUSE 20		'----PAUSE 20 MILLISECONDS
     NEXT			'----BOTTOM OF LOOP
     
    '----ROTATE SERVO FULLY CLOCKWISE
    FOR counter = 1 To 150
     'PULSOUT Servo, 500	'----(ORIG CODE - 500 NUMBER TOO BIG!!!)
     'PULSOUT Servo, 200	'----COMMON SERVO PULSE 2000uS = 2.00mS (FIXED CODE)
     PULSOUT Servo, 250	'----PARALLAX SERVO PULSE 2500uS = 2.50mS (FIXED CODE)
     PAUSE 20
     NEXT
     
    '----ROTATE SERVO TO CENTER POSITION
    FOR counter = 1 To 150
     'PULSOUT Servo, 750	'----(ORIG CODE - 750 NUMBER TOO BIG!!!)
     PULSOUT Servo, 150	'----STANDARD SERVO CENTERING PULSE 1500uS = 1.50mS (FIXED CODE)
     PAUSE 20
     NEXT
     
    END
    
Sign In or Register to comment.