Coding for non-continuous rotation servos

Razor Concepts

New Member
Hi, I am using a PIC16F88 and the PICAXE Programming Editor. Previously I have only been using continuous rotation servos. I plugged in a normal servo, and noticed that simple code like this:
Code:
servo 7, 225
pause 1000
Would move the normal servo to the right, say 60 degrees. Every time that peice of code runs, the servo tries to move 60 degrees, starting from its starting position. How do I code so that the servo will end at a certain position? So no matter what position it starts out in, the servo will end at the position I specify. Thanks :D
 

goom

Senior Member
With a normal hobby servo, the "sevo" command will indeed move it to a particular position, regardless of where it was when the command was issued.
What is the full code that you are using? If it just comprises of the above, then the program will end after one second, and the signal to the servo will be lost, and its commanded position will then be undefined.
A value of 225 is quite high. It is possible that you are hitting the physical end stop. If so, you may have done some damage. Could be that you have slipped or stripped some gears or a gear has rotated on its drive shaft. In either case the relationship between the feedback potentiometer will have changed in relation to the output shaft.
Try some more moderate values (e.g. 120 and 180), and increase the pause to several seconds.
 

BeanieBots

Moderator
Everything Goom says.
Servo 7,255 is very likely to damage a servo.

Try this.

servo 7,150
label:
goto label

The above code will move a servo to centre from wherever it is and hold it there.

Then try this
main:
servo 7,85
pause 2000
servo 7,215
pause 2000
goto main

Play with the numbers to find the limits for YOUR servo.
 

BeanieBots

Moderator
BCJKiwi, no I meant it the way i wrote it.

Try both and see the difference.

Your code will make frequent updates to the servo command and the pulses will be erratic. My code sets the servo command ONCE and then enters an empty loop to prevent the PICAXE from stopping and thus keeps the servo command alive.
 

Razor Concepts

New Member
For some reason it still isnt working properly... I tried it with 150 to center the servo, but it moved full right until the mechanical stopper prevented it from moving more (oops :eek: ). I tried servo 7, 50 and that still made it go full right! What's going on? I tried with two different servos and it happened to both.
 

mikie_121

Member
Are you using a picaxe 18X chip or a blank PIC 16f88?

Do you have a separate power supply for the servo? with a common ground for your picaxe supply.

I had lots of troubles with the 'servo' command, so I resorted to the following code. I needed to update my servo position frequently and the 'servopos' command wasn't around then.

servo:
pulsout 1,150
pause 19
goto servo
 

goom

Senior Member
What servos are you using? Is it possible that you have digital servos rather than analog?
Are you sure that the wiring is correct?
Signal (PICAXE pin) to white (Futaba), yellow (Hitec), Orange (JR), black or white (Airtronics)
+5V red for all models
Ground (common with PICAXE ground) black (Futaba, Hitec and Airtronix), brown (JR)
Try connecting an LED to the PICAXE pin through a 330ohm resistor to ground, and running the program suggested by BeanieBots. You should see a noticable change in LED brightness every 2 seconds if the servo command is working correctly.
What are you using for a power supply? Does the PICAXE and servo share a common supply?
Are you really using a raw PIC16F88 or a PICAXE?
Sorry for all of the questions, but something must be fundamentally wrong because the servo function is normally a no brainer to use.
 

Wrenow

Senior Member
OOPS You really need to try to keep the servo command between 100 and 200 for most servos to be safe. Servo 7,50 is WAY outside the normal defined range (note that the Picaxe manual indicates a minimum of 75 which is, by the way, to be used with care).

Note: Most servo testers only go from about 1ms to 2ms (translates to 100-200 in the Servo command). A few will go from .75 to 2.25, but the manual for mine that does says to only exceed the 1-2 range with care, as it can damage some servos.

There is a decent quick explanation of how they are supposed to work here:http://servocity.com/html/how_do_servos_work_.html

As for what is going on, you may have shifted the internal pot (position sensor) in it gear or stripped/jumped a gear.


Good luck.

Wreno
 

BeanieBots

Moderator
It does indeed sound like you have digital servos. They require a much higher frame rate than a 'standard' servo.
The very fact that they move indicates that they are wired correctly and pulses are being sent & received.
Dodgey power supply would result in erratic movement, not a run away.
Only other possibility is running the 18X at the wrong speed but you would have to explicitly put in a statement in your code to do that.

Please state your servo make and model number.
Does it remain stationary until the servo command is executed?
 

Michael 2727

Senior Member
Are you sure the servo IS a Normal one and the Pot is connected and working properely.
Sounds like it is running correctly just the pot has been relpaced by a fixed ballanced resistance. Didn't modify it and forgot about it ?
 

Razor Concepts

New Member
Here is a picture of the board, not sure what you guys mean by "blank" but the chip has PIC16F88 on it.


After taking the picture I have added more header pins for more servos... the only thing connecting the servos to the PIC is the signal wire. The ground and pos go to a separate battery just for the servos (I have a feeling this is critically wrong :eek: )

The servos work fine with radio control, and I know they are analog. If you are interested they are a Hextronik 9gram micro servo and a JR NES-517 servo.

In the picture you can see two rows of three pins, thats where the original two servo outputs were located, and those worked fine. I have a feeling this has to do with the ground not being connected to the board.
 

BeanieBots

Moderator
I have a feeling this has to do with the ground not being connected to the board.
I'll gaurantee it!

It is not possible to tell the difference between a blank PIC16F88 PIC and a PICAXE which is a PIC16F88 + bootloader program just by looking at it.

If you purchased a 18X PICAXE, then fine. If you purchased a 16F88, then it will never work.
 

MPep

Senior Member
To ensure that you have a PICAXE and not a 'standard' F88, you can check the firmware version in a PICAXE chip.
Under View, Options, Mode there is a box "Firmware?". With the programming lead in place, press this button. If correct, a Version number will be observed.
 

hippy

Ex-Staff (retired)
I nailed it by asking if his 16f88 was a picaxe or not. Seems like it wasn't.
Although everything Razor Concepts said earlier indicated PICAXE Basic code was being downloaded into something and that wouldn't be working at all if this were a 16F88. I suspect it's a PICAXE-18X but could be wrong.
 
Top