04.03.2013 Views

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

Basic Micro Studio Syntax Manual

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

SERVO<br />

<strong>Syntax</strong><br />

servo pin,pos{,repeat}<br />

• Pin - is a variable, constant or expression that indicates what processor pin to use.<br />

Commands<br />

• Pos - is a variable, constant or expression that indicates servo position. The value used must be<br />

signed to indicate left or right swing. Valid real world ranges are +/- 3000 with 0 being center. The<br />

ranges will vary from servo to servo.<br />

• Repeat - is a variable, constant or expression that is optional and specifi es how many times<br />

a pulse is repeated before exiting the command. A repeat value of 0 is a special case and will<br />

only wait until the high side of the pulse is fi nished before resuming normal program execution.<br />

Supported<br />

• BA - Supported<br />

• BAN - Supported<br />

• BAP - Supported<br />

• BAP40 - Supported<br />

Description<br />

The SERVO commands will generate pulses to control a standard R/C hobby servo. The range is<br />

-3000 to +3000. Most servos will run from -2200 to +2200. Center is typically 0. The command is a<br />

blocking command and will wait until the pulse is fi nished.<br />

The repeat argument can be used to drive up to 6 servos by setting it to 0. The time it takes to update<br />

6 SERVO commands in a row with repeat = 0 is about 18ms. This leaves time for the program to<br />

perform additional tasks before more servo pulses need to be sent.<br />

Notes<br />

1. Setting the repeat argument to 0 means this servo command will output 1 pulse and continue on to<br />

the next command without waiting for the low part of the pulse to fi nish<br />

2. Setting the repeat argument to 1 or more will cause the SERVO command to output the pulse the<br />

number of times value is set to. Repeat = 20 would generate 20 pulses and take 400ms.<br />

Examples<br />

The program below demonstrates how to update more than one servo at a time using the optional repeat<br />

argument. Setting the fi rst repeat to 0 will allow the second SERVO command to run while the fi rst would<br />

normally be waiting for the low side of it’s pulse to fi nish. Each servo command takes approximately 3ms<br />

when repeat is 0 so we need a pause after them to add up to approximately 20ms total.<br />

pos var sword<br />

main<br />

for pos = -500 to 500<br />

servo p0,pos,0<br />

servo p1,-pos,0<br />

pause 14<br />

next<br />

for pos = -500 to 500<br />

servo p0,-pos,0<br />

servo p1,pos,0<br />

pause 14<br />

next<br />

goto main<br />

185

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!