Organize and Share your Electronics the way you want. Sign-Up for a free account now. It takes only 30 seconds!

Addressable Serial Servo Controllers

Addressable Serial Servo Controllers

The code for the servo-pod is very simple, and modifications to suit your specific needs should not be much of a problem. My motto is to keep it simple if at all possible, and always leave plenty of room for expansion.
A Look Under The Hood:

The first line include “modedefs.bas” simply includes the mode definitions file allowing us to use the pre-defined mode N2400 to specify the baud rate. This isn’t 100% necessary, but it makes our code much more readable. The alternate way to indicate the baud rate would be to simply indicate the mode by using the mode number. In this case N9600 would be mode 6. See the PBP manuals serin command page for detailed information on the different serial modes.

The ID number hard-coded into each servo-pod forces each PIC to respond only when it receives its assigned ID number. Once the correct ID number is received, position data is then accepted, and stored in the byte-variable pos.

The serial input line uses the built-in timeout and label capabilities of PicBasic Pro to allow program execution to continue if no serial data is received within a pre-set time frame. In this case, the timeout has been set to 15mS as shown below.

serin serpin,N9600,15,nxt,

This forces program execution to wait for 15 milliseconds. If no serial data is received within 15mS, then goto label nxt. The nxt label holds a goto instruction that directs program flow back to the main label which resumes sending control pulses to the servo motor, and looking for more incoming serial data.

Using the timeout & label method we can use the timeout for setting up the time between each control pulse, and to make sure we aren’t locked in the serial receiving routine waiting for incoming serial data. We have pretty much killed two birds with one stone by using this method.

Wait For The Servo ID #:

The next thing we need is to force the servo-pod to respond only to positional data that is specifically meant for a certain address by using the data qualifier capabilities of PBP. The qualifier is the actual ID value we have assigned to each servo-pod as shown below.

ID var byte ‘ID number storage variable
ID = 5 ‘Assign unique ID to servo-pod

Line 1 assigns the byte-variable storage space to hold the physical value or number for the servo-pod ID. Line 2 writes the physical value of #5 into this RAM byte-variable storage location. The last part of our serial input line will now wait until the ID number 5 arrives before accepting servo positional data and placing it into the pre-defined RAM storage location pos.

Here’s a complete breakdown of how the serial input line functions.

serin serpin,N9600,15,nxt,[ID],pos ‘serial in on gpio.4

Get serial input on serpin (GPIO.4). 
Receive this data at 9600 baud — inverted. 
Wait 15mS for incoming data. 
If no data is received within 15mS, jump to label nxt. 
Wait for only 15mS to receive the ID. 
ID received, store servo position data in byte-variable pos. 
Return to “Main” and send the pulse to the servo. 

PicBasic Pro allows us to create some very powerful command lines with the unique capability of waiting for specific data, and the timeout, jump to label features. This single line of code handles many various requirements that are necessary to make the servo-pod successful.

Visit Here for more.







 

More Articles to Read

Smart "Homer"
Smart "Homer"
A DIY Segway-style vehicle
A DIY Segway-style vehicle
Superbeta transistors inside: Die photos and analysis of the LM108 op amp
Superbeta transistors inside: Die photos and analysis of the LM108 op amp
Peeqo is a desktop bot that communicates through GIFs
Peeqo is a desktop bot that communicates through GIFs
Using a Programmable Input Multiplier to Minimize Integer Boundary Spurs
Using a Programmable Input Multiplier to Minimize Integer Boundary Spurs
Serial seven segment LED display shield
Serial seven segment LED display shield
G-code controlled drawing plotter
G-code controlled drawing plotter
An Arduino round word clock
An Arduino round word clock
The Sandwich-o-Matic will make your lunch automatically
The Sandwich-o-Matic will make your lunch automatically
Scalar Network Analyser Jr
Scalar Network Analyser Jr

Top


Shares