11170 Flatiron Dr.
Lafayette, CO 80026
303.828.9156  (voice)
303.828.9316 (fax)
sales@protean-logic.com

Application Note - AN045

RSB509C with BS2 and RC servos

Purpose: Demonstrate the use of an RSB509C for background command reception.

Submitted by: Glenn Clark of Protean Logic Inc.

This application uses an RSB509C-0 and a BS2 Stamp to control an RC servo. Only two BS2  I/O pins used; P7 for buffered serial input and P8 for  RC servo output. The RSB509 gates the serial stream on the same I/O pin that it receives data. This saves I/O and simplifies board layout. The application contains four sub-circuits: 
  • The BS2 circuit is just the BS2 with connectors for programming and general purpose serial communication with a PC. R7 limits signal ringing on the servo pulse line.

  • The Power supply uses a 12volt wall transformer to power both the stamp and servo. D2 works with C3 to isolate  the Stamp's internal regulator from brownouts caused by high servo loads. R5 and R6 strap Regulator U3 to provide a stable 7.2 volts for the RC servo.

  • X1, C2, and C3 form a 4MHz time base for the buffer. R2 and D1 convert the incoming RS232 levels to 5 volt levels compatible with the RSB509. R1, R3 and R4 pull down the RSB509's open drain logic signals. R4 also limits LED D3 current. LED D3 indicates when the RSB509's buffer is empty. The polorized 5 pin cable connector is compatible with the one in the BS2 circuit. The BS2's TX output is used on this serial connector also.

  

Programming the Application

I have included three programs  in this application to demonstrate how servo control is accomplished with and without the RSB509. Of course, the RSB509 serial buffer is useful in circuits beyond those that use RC servos. Any continuous or simultaneous control requirement needs to have a serial buffer of some sort if it is to receive asynchronous serial data. The demo programs are:

  1. A stamp positioning the servo between position 0 and a value 1 to 4 input from a PC using Hyperterminal. The RSB509 is not used in this program.  The servo makes one cycle between user input and waits indefinitely for user input.  This program works exactly as expected, however there is no ability to have the process continue without user input for every cycle.

  2. A stamp positioning the servo between position 0 and a value 0 to 4 as input from a PC.  The RSB509 is not used in this program. In this program the user has only 5ms to input the value. This program is trying to accomplish an uninterrupted cycle of servo movements. The user input is used to determine the extent of the movement only.  Because there is virtually no way to synchronize the user input with the servo cycle, most user input is missed or corrupt.  This program produces poor results.

  3. A stamp positions the servo between position 0 and a value of 0 to 4 as input from a PC. In this program, the RSB509 is used to buffer the user's input. This program works as expected where the cycle continues on without concern for the user's input.  When the user does input a different value, the program seamlessly uses the new value.

To use the programming code directly from this on-line application note, highlight the code you want to use. Press <ctrl-C> to copy it into the clipboard. Open up the stamp editor and position the cursor in the programming area. Press <ctrl-V> to paste the clipboard contents into the programming area. Repeat this process as necessary to get all elements of the program into the Stamp editor program. Then run the program with the appropriate stamp type selected.

 

Program 1: No RSB509. User input required for every cycle. Use the programming cable plugged into the unbuffered plug.

'{$STAMP BS2}

 

x var byte 'This is just a loop counter for positioning'

inbyte var byte 'this is the value received from the serial port'

highval var word ' this is the value used to position the server to its max'

 

around:

 serin 0,16468,[inbyte]

 

 highval=1000

 if inbyte<>"1" then next1

  highval=625

 

next1:

 if inbyte<>"2" then next2

  highval=750

 

next2:

 if inbyte<>"3" then next3

  highval=875

 

next3:

 if inbyte<>"4" then next4

  highval=1000

 

next4:

 for x=1 to 40

  pulsout 8, 500

  pause 9

 next

 

 for x=1 to 40

  pulsout 8, highval

  pause 9

 next

 

 goto around

The first program works well as long as you wait for the entire servo positioning pulse train to be sent before you enter your positioning command. This program is completely synchronous. The servo action is synchronized to the users input. In fact the servo does nothing until the user inputs a value. Often this situation is unacceptable.

Program 2: No RSB509. User input attempted for any cycle. Use the programming cable plugged into the unbuffered plug.

Lets take a case where a servo is agitating a container. In this situation you want the agitation to continue until it is stopped, but you would like to be able to change the severity of the agitation on command from your PC. Program 2 attempts this without a serial buffer. In program 2 you have a 5 millisecond window to enter your command before the next servo cycle begins.

 

'{$STAMP BS2}

' The servo is acting as an agitator now, running continuously'

' The user has only 5ms window to input serial data'

' All data input must by synchronous'

 

x var byte 'This is just a loop counter for positioning'

inbyte var byte 'this is the value received from the serial port'

highval var word ' this is the value used to position the server to its max'

 

around:

 serin 0,16468,5, no_input, [inbyte]

 

no_input:

 highval=1000

 if inbyte<>"0" then next0

  highval=500

 

next0:

 if inbyte<>"1" then next1

  highval=625

 

next1:

 if inbyte<>"2" then next2

  highval=750

 

next2:

 if inbyte<>"3" then next3

  highval=875

 

next3:

 if inbyte<>"4" then next4

  highval=1000

 

next4:

 for x=1 to 40

  pulsout 8, 500

  pause 9

 next

 

 for x=1 to 40

  pulsout 8, highval

  pause 9

 next

 

 goto around

Program 2 works terribly. It is nearly impossible for a user to enter data at exactly the right point in time. In this program we require serial input to be synchronized with servo actions. A real world situation might offer other strategies for synchronizing input, but it is still a complication that is nice to avoid. 

 

Program 3: RSB509 used. User input allowed any time. Use the programming cable plugged into the buffered plug.

In the third program, an RSB509 serial buffer is used to capture serial input and store it until the Stamp is ready to look at it. In this case, the Stamp is polling the RSB509 for data and gives the RSB509 only 1 millisecond to send data.

'{$STAMP BS2}

' The servo is acting as an agitator now, running continuously'

' The user has only 5ms window to input serial data'

' All data input must by synchronous'

 

x var byte 'This is just a loop counter for positioning'

inbyte var byte 'this is the value received from the serial port'

highval var word ' this is the value used to position the server to its max'

 

' This first code just initializes the RSB509C-0'

' Signal Initialization'

 high 7

 pause 2

 input 7

 

' program the RSB509C-0 for 9600 buad inverted 8N1 format

 serout 7,49236, [%00000100]

 

' wait for recover from init (really not required on slow stamp)

 pause 1

 

around:

' signal RSB509 to send data if it has any

 high 7

 serin 7,16468,1, no_input, [inbyte]

 

no_input:

 highval=1000

 if inbyte<>"0" then next0

  highval=500

 

next0:

 if inbyte<>"1" then next1

  highval=625

 

next1:

 if inbyte<>"2" then next2

  highval=750

 

next2:

 if inbyte<>"3" then next3

  highval=875

 

next3:

 if inbyte<>"4" then next4

  highval=1000

 

next4:

 for x=1 to 40

  pulsout 8, 500

  pause 9

 next

 

 for x=1 to 40

  pulsout 8, highval

  pause 9

 next

 

 goto around

 

Program 3 works perfectly. The user can stop the agitation servo by entering a "0". Likewise the user can enter a severity of agitation from 1 to 4 and the servo will continue the agitation until it is stopped. The user can also type several settings ahead which are buffered. Each setting is retrieved from the buffer after a servo cycle. Up to 32 cycles can be "programmed" ahead of time. The actual utility of this example is questionable in the real world, but the concept of asynchronous serial reception is required very often. The RSB509 provides that capability with ease.

Application Conclusion

The RSB509 serial buffer gives single thread processors like the Basic Stamp a whole new bag of tricks. The Stamp can even perform complex time intensive functions and still have the ability to receive asynchronous serial input. The time required to receive the input is reduced because all communication with the RSB509 takes place at 9600 baud. It takes 1/4 of the processing time to receive 1200 baud signals through the RSB509 as compared to the Stamp receiving the signal directly. Also, no additional I/O is required beyond the single data pin. This opens up applications for stamp use with modems, NEMA devices like GPS receivers, Terminal node controllers, etc.