Galil Motion Control DMC-21 5 Series User Manual page 102

Table of Contents

Advertisement

Using basic mathematics it is known that 1.4*(80,000) = 112,000. However, using a terminal, a DMC controller
would calculate the following:
:var=1.4*80000
:MG var
111999.5117
:
The reason for this error relies in the precision of the controller. 1.4 must be stored to the nearest multiple of
1/65536, which is 91750/65536 = 1.3999. Thus, (91750/65536)*80000 = 111999.5117 and reveals the source of
the error.
By ignoring decimals and multiplying by integers first (since they carry no error), and then adding the decimal back
in by dividing by a factor of 10 will allow the user to avoid any errors caused by the limitations of precision of the
controller. Continuing from the example above:
:var=14*80000
:MG var
1120000.0000
:var=var/10
:MG var
112000.0000
:
Bit-Wise Operators
The mathematical operators & and | are bit-wise operators. The operator, &, is a Logical And. The operator, |, is a
Logical Or. These operators allow for bit-wise operations on any valid DMC-21x5 numeric operand, including
variables, array elements, numeric values, functions, keywords, and arithmetic expressions. The bit-wise operators
may also be used with strings. This is useful for separating characters from an input string. When using the input
command for string input, the input variable will hold up to 6 characters. These characters are combined into a
single value which is represented as 32 bits of integer and 16 bits of fraction. Each ASCII character is represented as
one byte (8 bits), therefore the input variable can hold up to six characters. The first character of the string will be
placed in the top byte of the variable and the last character will be placed in the lowest significant byte of the
fraction. The characters can be individually separated by using bit-wise operations as illustrated in the following
example:
#main;
len="TESTME";
Flen=@FRAC[len];
Flen=Flen*$10000;
len1=(Flen&$00FF);
len2=(Flen&$FF00)/$100;
len3=len&$000000FF;
len4=(len&$0000FF00)/$100;
len5=(len&$00FF0000)/
$10000;
len6=(len&$FF000000)/
$1000000;
MG
len6
{S4};
MG
len5
{S4};
MG
len4
{S4};
MG
len3
{S4};
MG
len2
{S4};
MG
len1
{S4};
EN;
Chapter 7 Application Programming ▫ 97
'main program
'set len to a string value
'set variable to fractional part of string
'shift Flen by 32 bits, convert fraction to integer
'mask first byte of Flen and set new variable
'set variable to top byte of Flen
'set variable to bottom byte of len
'set variable to second byte of len
'set variable to third byte of len
'set variable to fourth byte of len
'display 'len6' as string message of up to 4 chars
'display 'len5' as string message of up to 4 chars
'display 'len4' as string message of up to 4 chars
'display 'len3' as string message of up to 4 chars
'display 'len2' as string message of up to 4 chars
'display 'len1' as string message of up to 4 chars
'end program
DMC-21x5 User Manual 1.0a1

Advertisement

Table of Contents
loading

Table of Contents