|   Creating Motion  |  Program Flow  |  Variables  |  Encoder and Pulse Train Following  |
|   Input and Output  |  Communications  |  The PID Filter  |

Communications

While there are a variety of options, the default mode for communicating with a SmartMotor™ is serial RS-232 for the main port. Each SmartMotor™ is equipped with a secondary serial port named the AniLink port. The AniLink port on a SmartMotor™ can be configured to communicate with either RS-485 or I2C. The I2C connects SmartMotor™ peripherals like LCD displays, I/O cards, etc., while the RS-485 will interface bar code readers, light curtains, and other intelligent" peripherals including other SmartMotors if desired.

To maximize the flexibility of the SmartMotor™, these serial communications ports are fully programmable with regard to bit-rate and protocol.

There is a sixteen-byte input buffer for the primary RS-232 port and another for the secondary RS-485 port. These buffers ensure that no arriving information is ever lost, although when either port is in data mode, it is the responsibility of the user program within the motor to keep up with the incoming data.

By default, the primary RS-232 channel, which shares a connector with the incoming power, is set up as a command port with the following default characteristics:

  Default: Other Options:
Type: RS-232 RS-485 (w/adapter)
Parity: None Odd or Even
Bit Rate: 9600 2400 to 38400
Stop Bits: 1 0 or 2
Data Bits: 8 7
Mode: Command Data
Echo: Off On

If you do not have a cable, you can communicate with your SmartMotor™by making the connections shown here and the SmartMotor™ will execute the commands it receives.

Because of the buffers on both sides there is no need for any hand shaking protocol when commanding the SmartMotor™. Most commands execute in less time than it would take to receive the next one. Still, you should take some care to allow processes to complete, particularly relatively slow processes like printing to a connected LCD display, or executing a full subroutine. Since the EEPROM long term memory is slow to write, the terminal software does employ two way communication to regulate the download of a new program.

Daisy chaining RS-232

Multiple SmartMotors can be connected to a single RS-232 port as shown.

This diagram could be expanded to as many as 100 motors. For independent motion, however, each motor must be programmed with a unique address. In a multi-motor system the programmer has the choice of putting a host computer in control or having the first motor in the chain be in control of the rest.

SADDR#                    Set motor to new address

The SADDR# command causes a SmartMotor™ to respond exclusively to commands addressed to it. The range of address numbers is from 1 to 100. Once each motor in a chain has a unique address, each individual motor will communicate normally after its address is sent at least once over the chain. To send an address, add 128 to its value and output the binary result over the communication link. This puts the value above the ASCII character set, quickly and easily differentiating it from all other commands or data. The address needs to be sent only once until the host computer, or motor, wants to change it to something else. Sending out an address zero (128) will cause all motors to listen and is a great way to send global data such as you would do to start simultaneous motion in a chain. Once set, the address features work the same for RS-232 and RS-485 communications.

Unlike the RS-485 star topology, the consecutive nature of the RS-232 daisy-chain creates the opportunity for the chain to be independently addressed entirely from the host, rather than have a uniquely addressed program in each motor. Setting up a system this way can add simplicity because the program in each motor can be exactly the same. If the RUN? command is the first in each of the motor's programs, the programs will not start upon power up. Addressing can be worked out by the host prior to the programs being started later by the host sending the RUN command globally.

SLEEP, SLEEP1                             Assert sleep mode

WAKE, WAKE1                               De-assert SLEEP

Telling a motor to sleep causes it to ignore all commands except the WAKE command. This feature can often be useful, particularly when establishing unique addresses in a chain of motors. A 1 at the end of the command specifies the AniLink RS-485 port.

ECHO, ECHO1                                ECHO input

ECHO_OFF, ECHO_OFF1               De-assert ECHO

The ECHO and ECHO_OFF commands toggle the echoing of data input. Because the motors do not echo character input by default, consecutive commands can be presented, configuring them with unique addresses, one at a time. If the host computer or controller sent out the following command sequence, each motor would have a unique and consecutive address (~0 equals 128, ~1 equals 129, etc.).

            ~0SADDR1

            ~1ECHO

            ~1SLEEP

            ~0SADDR2

            ~2ECHO

            ~2SLEEP

            ~0SADDR3

            ~3ECHO

            ~0WAKE

Commanded by the first motor, instead of a host, the same chain could be addressed with the following sequence:

            SADDR1 ‘Address the first

            ECHO                                                ‘Echo for host data

            PRINT(#128,SADDR2",#13)

            WAIT=10 ‘Allow time

            PRINT(#130,ECHO",#13)

            WAIT=10

            PRINT(#130,SLEEP",#13)

            WAIT=10

            PRINT(#128,SADDR2",#13)

            WAIT=10

            PRINT(#131,ECHO",#13)

            WAIT=10

            PRINT(#131,SLEEP",#13)

            WAIT=10

            PRINT(#128,SADDR3",#13)

            WAIT=10

            PRINT(#132,ECHO",#13)

            WAIT=10

            PRINT(#128,WAKE",#13)

            WAIT=10

The two communications ports have enormous flexibility. To select from the vast array of options, use the OCHN command.

OCHN

Options:
Type: RS2, RS4 RS-232 or RS-485
Channel: 0, 1 or 2 0=Main, 1=AniLink
Parity: N, O or E None, Odd or Even
Bit rate: 2400, 4800, 9600, 19200, 38400 baud
Stop bits: 0, 1 or 2
Data bits: 7 or 8
Mode: C or D Command or Data

For the AniLink port in I2C mode use IIC for the type, 2 for the channel and either 400 or 1000 for the bit rate. Use any legal value for the other parameters as place holders. They will otherwise be ignored. Here is an example of the OCHN command:

            OCHN(RS2,0,N,38400,1,8,D)

If the primary communication channel (0) is opened as an RS-485 port, it will assume the RS-485 adapter is connected to it. If that is the case the UG pin in the same connector is assigned the task of directing the adapter to be in Transmit or Receive mode in accordance with the motor's communication activity.

CCHN(type,channel)             Close a communications channel

Use the CCHN command to close a communications port when desired.

BAUD#                                  Set BAUD rate of main port

The BAUD# command presents a convenient way of changing only the bit rate of the main channel. The number can be from 2400 to 38400 bps.

PRINT( ), PRINT1( ) PRINTA-PRINTH Print to RS-232 or AniLink channel

A variety of data formats can exist within the parentheses of the PRINT( ) command. A text string is marked as such by enclosing it between double quotation marks. Variables can be placed between the parentheses as well as two variables separated by one operator. To send out a specific byte value, prefix the value with the # sign and represent the value with as many as three decimal digits ranging from 0 to 255. Multiple types of data can be sent in a single PRINT( ) statement by separating the entries with commas. Do not use spaces outside of text strings because SmartMotors use spaces as delimiters along with carriage returns and line feeds.

The following are all valid print statements and will transmit data through the main RS-232 channel:

PRINT(Hello World") ‘text
PRINT(a*b) ‘exp.
PRINT(#32) ‘data
PRINT(A",a,a*b,#13) ‘all

PRINT1 prints to the AniLink port with RS-485 protocol while PRINTA prints to the AniLink port using I2C protocol in such a way as to send data to an LCD display or standard parallel input line printer (with a DIO-100 card on the AniLink bus).

SILENT, SILENT1     Suppress PRINT() outputs

TALK, TALK1           De-assert silent mode

The SILENT mode causes all PRINT( ) output to be suppressed. This is useful when talking to a chain of motors from a host, when the chain would otherwise be talking amongst itself because of executing programs containing PRINT( ) commands.

!                               Wait for RS-232 char. to be received

A single exclamation mark will cause program execution to stop until a character is received. This can be handy under certain circumstances like debugging a program in real time.

a=CHN0, a=CHN1    RS-485 communications error flags

The CHN0 and CHN1 variables hold binary coded information about the historical errors experienced by the two communications channels. The information is as follows:

Bit Value Meaning
0 1 Error?
1 2  
2 4  
3 8  
4 16  
5 32  
6 64  
7 128  

A subroutine that printed the errors to an LCD display would look like the following:

            C911

                        IF CHN0 ‘If CHN0 != 0

   DOUT0,1                                ‘Home LCD cursor

    IF CHN0&1

      PRINTA(ERROR1")

    ENDIF

    IF CHN0&2

      PRINTA(ERROR2")

    ENDIF

    IF CHN0&4

      PRINTA(ERROR3")

    ENDIF

    IF CHN0&8

      PRINTA(ERROR4")

    ENDIF

    CHN0=0                                 ‘Reset CHN0

                        ENDIF

            RETURN

a=ADDR                    Motor's self address

If the motor's address (addr) is set by an external source, it may still be useful for the program in the motor to know what address it is set to. When a motor is set to an address, the ADDR variable will reflect that address from 1 to 120.


Getting data from a COM port

If a com port is in Command Mode, then the motor will simply respond to arriving commands it recognizes. If the port is opened in Data Mode, however, then incoming data will start to fill the 16 byte buffer until it is retrieved with the GETCHR command.

            a=LEN                       Number of characters in RS-232 buffer

            a=LEN1                     Number of characters in RS-485 buffer

            a=GETCHR               Get character from RS-232 buffer

            a=GETCHR1             Get character from RS-485 buffer

The buffer is a standard FIFO (First In First Out) buffer,. This means that if the letter A is the first character the buffer receives, then it will be the first byte offered to the GETCHR command. The buffer exists to make sure that no data is lost, even if your program is not retrieving the data at just the right time. Two things are very important when dealing with a data buffer for the protection of the data:

            1)  Never GETCHR if there is no CHR to get.

            2)  Never let the buffer overflow.

The LEN variable holds the number of characters in the buffer. Your program must observe that the LEN is greater than zero before issuing a command like: a=GETCHR. Likewise, you will need to arrange your application such that overall, you will be pulling data out of the buffer faster than it comes in.

Being able to configure the communication ports for any protocol as well as being able to transmit and receive data allows the SmartMotor™ to interface with a vast array of RS-232 or RS-485 devices. Some of the typical devices that would interface with SmartMotors over the communication interfaces are:

            1) Other SmartMotors

            2) Bar Code Readers

            3) Light Curtains

            4) Terminals

            5) Printers

The following is an example program that repeatedly transmits a message to an external device (in this case another SmartMotor™) and then takes a number back from the device as a series of ASCII letter digits, each ranging from 0 to 9. A carriage return character will mark the end of the received data. The program will use that data as a position to move to.

            A=500 ‘Preset Accel.

            V=1000000 ‘Preset Vel.

            P=0 ‘Zero out Pos.

            O0 ‘Declare origin

            G ‘Servo in place

            OCHN(RS2,0,N,19200,1,8,D)

            PRINT(RP",#13)

            C0

                        IF LEN                                    ‘Check for chars

    a=GETCHR               ‘Get char

    IF a==13 ‘If carriage ret.

      G                                 ‘Start motion

      P=0                 ‘Reset P to zero

      PRINT(RP",#13)       ‘Next

    ELSE

      P=P*10          ‘Shift P

                                    a=a-48            ‘Adjust for ASCII

      P=P+a                        ‘Build P

    ENDIF

                        ENDIF

            GOTO0 ‘Loop forever

The ASCII code for zero is 48. The other nine digits count up from there so the ASCII code can be converted to a useful number by subtracting the value of 0 (ASCII 48). The example assumes that the most significant digits will be transmitted back first. Any time it sees a new digit, it multiplies the previous quantity by 10 to shift it over and then adds the new digit as the least significant. Once a carriage return is seen (ASCII 13), motion starts. After motion is started, P (Position) is reset to zero in preparation for building up again. P is buffered so it will not do anything until the G command is issued.

 
|  Home   |   About Us  |   Products  |   Sales  |   Support  |   Press and Literature  |  Contact Us   |   Site Map  |
Animatics Corporation. 3200 Patrick Henry Dr, Santa Clara, CA, Tel:408.748.8721
Copyright © 2001-  All rights reserved.  Any comments or problems email webmaster