Can't get a servo to do what I want?
Spragmatic
Posts: 59
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
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
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.
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.
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).
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!!
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.
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
And this is the SX forum
(sorry can't help myself -- just love my SXs)
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).
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.
Maybe it's time for you to pick a few SX procs.
The price is right and they are nice little chips. With an external resonator they'll run at 50MIPs.
Robert
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?
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
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.