SERVOPOS pin,pulse


Pin - is a variable/constant (constant only on some parts) which specifies the i/o pin to use.

Pulse - is variable/constant (75-225) which specifies the servo position


Adjust the pulse length applied to a radio-control style servo to change its position. A servo command on the same pin number must have been previously issued.

Servos, as commonly found in radio control toys, are a very accurate motor/ gearbox assembly that can be repeatedly moved to the same position due to their internal position sensor. Generally servos require a pulse of 0.75 to 2.25ms every 20ms, and this pulse must be constantly repeated every 20ms. Once the pulse is lost the servo will lose its position. The servo command starts a pin pulsing high for length of time pulse (x0.01 ms) every 20ms. The 'servopos' adjusts the length of this pulse. The servo command initialises the pin for servo operation and starts the timer. Once a pin has been initialised, it is recommended to use the 'servopos' command to adjust position. This prevents resetting of the timer, which could cause 'jitter'.

Do not use a pulse value less than 75 or greater than 225, as this may cause the servo to malfunction. Due to tolerances in servo manufacture all values are approximate and will require fine-tuning by experimentation. Always use a separate 6V (e.g 4x AA cells) power supply for the servo, as they generate a lot of electrical noise.

Note that the overhead processing time required for processing the servo commands every 20ms causes the other commands to be slightly extended i.e. a pause command will take slightly longer than expected. The servo pulses are also temporarily disabled during timing sensitive serin, serout, sertxd and debug commands.

Effect of increased clock speed:

The servopos command will function correctly at 4 or 16MHz (8 or 32Mhz for X2 parts). No other frequency will work correctly.

Applies To:
All (except 08, 18)
See Also:
Related Create:

Move a servo

Move a servo on output 4 between two positions

Code Example:
init:	servo 4,75	; initialise servo
main:	servopos 4,75	; move servo to one end
	pause 2000	; wait 2 seconds
	servopos 4,225	; move servo to other end
	pause 2000	; wait 2 seconds
	goto main	; loop back to start
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.


  • Login to leave a comment.