Variables
are data holders that you can set and change within the program or over
the communication channel.
The first 26 variables are long integers (32 bits) and are accessed with
the lower case letters of the alphabet, a, b, c, . . . x, y, z.
a=# Set variable a to a numerical value
a=exp Set variable a to value of an expression
A
variable can be set to an expression with only one operator and two
operands. The operators can be any of the following:
+ Addition
- Subtraction
* Multiplication
/ Division
& Bitwise AND (see appendix A)
| Bitwise OR (see appendix A)
The following
are legal:
|
a=b+c,
|
a=b+3
|
a=5+8
|
|
a=b-c
|
a=5-c
|
a=b-10
|
|
a=b*c
|
a=3*5
|
a=c*3
|
|
a=b/c
|
a=b/2
|
a=5/b
|
|
a=b&c
|
a=b&8
|
|
|
a=b|c
|
a=b|15
|
|
Arrays
In
addition to the first 26, there are 52 more long integer variables
accessible with double and triple lower case letters: aa, bb, cc, . . .
xxx, yyy, zzz. The memory space that holds these 52 variables is more
flexible, however. This same variable space can be accessed with an array
variable type. An array variable is one that has a numeric index
component, that allows which variable a program changes to be selected
numerically, and therefore mathematically. This memory space is further
made flexible by the fact that it can hold 51 thirty two bit integers, or
101 sixteen bit integers, or 201 eight bit integers (all signed).
The
array variables take the following form:
ab[i]=exp Set variable to a signed 8
bit value where index i = 0...200
aw[i]=exp Set variable to a signed 16 bit
value where index i = 0...100
al[i]=exp Set variable to a signed 32
bit value where index i = 0...50
The
index i may be a number, a variable a thru z, or the sum or difference of
any two variables a thru z (variables only).
The
same array space can be accessed with any combination of variable types.
Just keep in mind how much space each variable takes. We can even go so
far as to say that one type of variable can be written and another read
from the same space. For example, if you assigned the first four eight
bit integers as follows:
ab[0]=0
ab[1]=0
ab[2]=1
ab[3]=0
that
would occupy the same space as the first single 32 bit number, and due to
the way binary numbers work, would make the thirty two bit variable equal
to 256 (see appendix A).
A common
use of the array variable type is to set up what is called a buffer. In
many applications, the SmartMotor will be tasked with inputting data
about an array of objects and to do processing on that data in the same
order, but not necessarily at the same time. Under those circumstances it
may be necessary to buffer" or store" that data while the SmartMotor™
processes it at the proper times.
To
set up a buffer the programmer would allocate a block of memory to it,
assign a variable to an input pointer and another to an output pointer.
Both pointers would start out as zero and every time data was put into
the buffer the input pointer would increment. Every time the data was
used, the output buffer would likewise increment. Every time one of the
pointers is incremented, it would be checked for exceeding the allocated
memory space and rolled back to zero in that event, where it would
continue to increment as data came in. This is a first-in, first-out or
FIFO", circular buffer. You need to be sure that there is enough memory
allocated so that the input pointer never overruns the output pointer.
Storage of variables
(Not available in SMXXX5 SmartMotors)
Each
SmartMotor has 8K of non-volatile EEPROM memory to store variables when
they need to survive the motor powering down.
EPTR=expression Set
EEPROM pointer, 0-7999
To
read or write into this memory space you first need to properly locate
the pointer. This is accomplished by setting EPTR equal to the offset.
VST(variable,index) Store variables
To store
a series of variables use the VST command. In the "variable"
space of the command put the name of the variable and in the
"index" space put the number of variables following that
variable that you also want to store. Put a one here if you only want to
store the one variable specified. The actual sizes of the variables will
be handled automatically.
VLD(variable,index) Load variables
To
load variables, starting at the pointer, use the VLD command. In the
"variable" space of the command put the name of the variable
and in the "index" space put the number of subsequent variables
you want loaded.
Fixed or pre-assigned functions
In
addition to the general purpose variables there are variables that are
gateways into the different functions of the motor itself.
@P Current position
@PE Current position error
@V Current velocity
ADDR Motor's self address
CHN0 RS-232 com error flags
CHN1 RS-485 com error flags
CLK Read/write sample
rate counter
CTR External encoder
count variable
I Last recorded
index position
LEN # of characters in
RS-232 buffer
LEN1 # of characters in
RS-485 buffer
Report to host commands
Ra...Rzzz Report
variable a ... zzz, 78 in all
Rab[i] Report 8 bit variable
value Rab[i]
Raw[i] Report 16 bit variable
value Raw[i]
Ral[i] Report 32 bit variable
value Ral[i]
RA Report buffered
acceleration
RAIN{port}{ch} Report 8 bit analog input port=A-H,
ch= 1-4
RAMPS Report assigned maximum
current
RBa Report overcurrent
status bit
RBb Report parity error
status bit
RBc Report communications
error bit
RBd Report user math
overflow status bit
RBe Report position error status bit
RBf Report
communications framing error status bit
RBk Report EEPROM
read/write status bit
RBl Report historical
left limit status bit
RBi Report index status
bit
RBh Report overheat
status bit
RBm Report negative limit
status bit
RBo Report motor off
status bit
RBp Report positive limit
status bit
RBr Report historical
right limit status bit
RBs Report program scan
status bit
RBt Report trajectory
status bit
RBu Report user array
index status bit
RBw Report wrap around
status bit
RBx Report hardware index
input level
RCHN Report combined
communications status bits
RCHN0 Report RS-232 communications status
bits
RCHN1 Report RS-485 communications status
bits
RCLK Report clock value
RCTR Report secondary counter
RCS Report RS-232
communications check sum
RCS1 Report RS-485
communications check sum
RD Report buffered
move distance value
RDIN{port}{ch} Report 8 bit digital input byte,
port=A-H, and ch=0-63
RE Report buffered
maximum pos. error
RI Report last stored index position
RKA Report buffered Kaff
coefficient
RKD Report buffered Kd
coefficient
RKG Report buffered Kg
coefficient
RKI Report buffered Ki
coefficient
RKL Report buffered Kl
limit value
RKP Report buffered Kp
coefficient
RKS Report buffered Ks
coefficient
RKV Report buffered Kvff
coefficient
RP Report measured
position
RPE Report present
position error
RMODE Report present positioning
mode:
P Absolute position move
R Relative position move
V Velocity move
T Torque mode
F Follow mode
S Step and Direction mode
C Cam Table mode
W Drive mode
X Follow mode with multiplier
E Position error
O Motor off
H Contouring mode
RS2 Restore RS-232 mode
RS4 Assign UG to RS-485
control
RS Report status byte
(8 system states)
RSP Report sample period
and version number
RT Report current
requested torque
RV Report velocity
RW Report status word
(16 system states)