IMC Lisp

Macro Processor For
Imc01-D - Intelligent Stepper Drivers

Programmer’s Reference



Contents

1. IMCLisp - Macro Processor
1.1 Installation & Usage

2. IMCLisp Command Set
2.1 Command Syntax
2.1.1 Statement Structure
2.1.2 Variables
2.1.3 Command : MOVEWAIT, IMOVEWAIT
2.1.4 Command : MOVE, IMOVE
2.1.5 Command : HOME
2.1.6 Command : STOP
2.1.7 Command : DELAY
2.1.8 Command : OUTPUT
2.1.9 Command : JUMP
2.1.10 Command : JUMPIF
2.1.11 Command : CALL, RET
2.1.12 Command : COMP

3. Local Mode Operation
3.1 Jogging/Inching
3.2 Going to specified position
3.3 Edit Mode

4. Application Example
4.1 Description
4.2 Connections & Setup



1. IMCLisp - Macro Processor

The IMCLisp is a macro command language providing macros for single axis control applications.  The command list contains powerful features like input/output processing, program control by the way of branching and subroutine calling and arithmetic computation.  The back end of this software is the IMC01 series of motion controllers and drivers which offer the following features:


While the IMCLIB software library offers complete control over all the features of the IMC01 from a simple IBM - PC, considerable programming expertise either in C or C++ is required to implement a given application. Even then, for on line control an PC would still be required to run the application.

Another option is to get the IMC customised for a particular application.  In this case, development of the application logic requires close interaction between the user and the OEM’s  programmer.  This can become quite expensive in terms of time spent for finalising the logic.

The IMCLisp is an ideal solution for such a situation.  The macro control language has evolved out of the development of several customised controllers built around the IMC and provides full and simple control of all the features of the IMC.  The development consists of the following phases:

  1. Code the application with the IMCLisp macro command set on a PC
  2. Compile the lisp code into an intermediate object code with the utility provided LSPCOMP on the PC.
  3. Download this object code to the target IMC using LSPSEND.  The IMC stores the code in its E2PROM.
  4. Set the parameters/constants to required values, if required, from the PC using LSPSET.


The application is now ready to run.

Note that the requirement of IMCLisp interpreter on the IMC unit should be included in the ordering information.

The IMC simultaneously supports a minimal user interface through the keypad and display.  This allows manual setting up that is necessary in most applications.  This is discussed in Section 3 of this documentation.

1.1 Installation and Usage

The package consists of 3 files :

  1. LSPCOMP.EXE - Containing the macro processor to generate intermediate object code.
  2. LSPSEND.EXE - for communicating object code to the IMC unit.
  3. LSPSET.EXE - for setting up constant parameters.


Installation is done by simply copying these onto the target computer.



2. IMCLISP Command Set
The various commands are grouped as under:

A. For Movement

  1. MOVEWAIT - Start a movement and wait for movement to finish
  2. MOVE - Start movement and proceed to next lisp statement
  3. IMOVEWAIT - similar to MOVEWAIT but in incremental mode
  4. IMOVE - similar to MOVE but incremental mode
  5. HOME - Seek the reference position and set position to 0
  6. STOP - Stop current movement, if any


B. Branching and program control

  1. JUMP - Branch to a statement
  2. JUMPIF - Conditional branching based on computation or logical operation
  3. CALL - Call a subroutine - upto 3 levels of nesting
  4. RET - Return, complements a call statement


C. I/O Control

  1. OUTPUT - Set or reset an output bit
  2. DELAY  - include a delay
  3. Implicit input reading during conditional branching statements




2.1 Command Syntax

The following describes the structure of the lisp statements, details of utilisation of variables and description of the commands.  Examples are provided as appropriate.

2.1.1 Statement Structure
The structure of a single lisp statement is:

N<#>  <command>   <field1>  <field2> ...

Each statement should begin with a N followed by a statement number.

All situations where a constant or number is input is required may be replaced by a variable referencing operation by prefixing the variable number with a ‘#’ sign.  The resolution is done dynamically as the program executes.

2.1.2 Variables
The lisp statements may use utmost seven  variables (numbered 0 to 6).   They are assigned as follows:

Variable Number Usage
#0 to #4 General purposeMay be user defined
#5 Always holds current encoder count reading
#6 Holds the current absolute position in steps at the end of each statement.For MOVE, MOVE state-ments, this has the value after the movement stops.

Variables #0 to #4 may be edited upon power up to any initial required value.  Alternatively, they may be initialised from the PC.  In both case, they are stored in the NV memory and reloaded upon start of execution.  If the initial value is known only at run time, or, if they are used as scratch pad variables, they need to be initialised to the required value by list statements.
 

2.1.3 Command : MOVEWAIT, IMOVEWAIT
This command initiates a specified movement and monitors it till the movement stops. Thereafter, the next lisp statement is executed.  The syntax for this command is:

N<nnn> MOVEWAIT <steps>  <speed>

where:
 nnn is the statement number
 steps is the movement required in number of steps
  This may be a constant value or a variable reference
 speed is the speed of movement in number of steps per second
  This may be a constant value or a variable reference

When IMOVEWAIT is specified, the steps is interpreted as a incremental movement rather than absolute position.

Example: (Assume that the current position is 0)

 % Example, refer discussion below
 N20  MOVEWAIT  500  2000
 N22  MOVEWAIT  500  1000
 N25  IMOVEWAIT 500  2000
 % Move by an amount stored in parameter 4 with speed 1000
 N30  MOVEWAIT #4   1000
 % Move by an amount stored in parameter #3 with speed in #0
 N40  MOVEWAIT #3   #0

In the above example, in statement 20, the motor moves by 500 steps at speed of 2000 sps so that the final position is 500.
In statement 22, the motor does not move at all, since the final position is already 500.
In statement 25, the motor moves 500 steps at a speed of 2000, since the IMOVEWAIT command is used rather than MOVEWAIT command.  The final position at the end of execution of this statement is 1000.

In all cases, parameter #6 holds the final position at the end of the movement.

2.1.4 Command : MOVE, IMOVE
This command initiates a specified movement and contrary to the MOVEWAIT commands, the next LISP statement is taken up for execution. The syntax for this command is:

N<nnn> MOVE <steps>  <speed>

where:
 nnn is the statement number
 steps is the movement required in number of steps
  This may be a constant value or a variable reference
 speed is the speed of movement in number of steps per second
  This may be a constant value or a variable reference

When IMOVE is specified, the steps is interpreted as a incremental movement rather than absolute position.

Example: (Assume that the current position is 0)

 N20  IMOVE  500  2000
 N21  JUMPIF I1 0 21
 N22  STOP
 % Referencing movement and speed by parameter number is possible
 % refer to example for previous command

In the above example, in statement 20, the motor starts moving by 500 steps at speed of 2000 sps.  After movement starts, execution continues to statement 21, where, the input number 1 is read and execution continued till the input 1 becomes high (refer to description of the JUMPIF command for syntax).  Once the input becomes high execution of N22 is done and this stops the movement (refer to the STOP command below).

Note that, if the program goes to N22 only when I1 becomes high - even if the previously started movement stops.  In this case, once I1 becomes high, the STOP command has no effect.

In all cases, at the end of movement, parameter #6 holds the value of current position.

2.1.5 Command: HOME
This command provides for referencing the axis position. The sequence is as follows:

  1. The motor is moved in the negative direction at a constant speed of 400 SPS.
  2. Simultaneously, input #0 is monitored till it becomes high.
  3. When it becomes high, the movement is stopped.  The motor is rotated in the reverse direction till the input is just released.
Note that there is no way to stop motion except a limit input or powering off.

2.1.6 Command: STOP
This command stops any existing movement, if any. The statement has not effect if there is not movement.  Also, the parameter #6 reflecting current position, is updated after the movement is stopped. The stop is abrupt without any ramping.
 

2.1.7 Command: DELAY
DELAY programs a dwell time in milliseconds.  During this period, the unit is completely idle.  There is not way to break a delay till the time elapses. The syntax is:

 N<nnn>  DELAY <ddd>

where:
 nnn is the statement number
 ddd is the delay in milliseconds
  This may be a constant value or a variable reference
 

2.1.8 Command: OUTPUT
OUTPUT is used to manipulate the 8 outputs of the system.  Refer to IMC documentation for connection of the outputs.  The syntax is:

 N<nnn>  OUTPUT <ooo> <s>

where:
 nnn is the statement number
 ooo is the output number
 s    is the output status

Example:

 N10  OUTPUT 2  1

This statement sets output 2 high.

2.1.9 Command: JUMP
Unconditional branching is provided by JUMP.  The syntax is:

 N<nnn>  JUMP <ttt>

where:
 nnn is the statement number
 ttt   is the target statement number

Example:

 N10  IMOVEWAIT  500 1000
 N20  DELAY 30
 N30  JUMP 10

This program segment works as follows:
 In statement 10, the motor moves by 500 steps with speed 1000.
 In statement 20, the system waits for 30 milliseconds
 In statement 30, the program jumps back to statement 10 and repeats
 the above sequence endlessly.

2.1.10 Command: JUMPIF
Conditional branching is provided by JUMPIF.  The syntax is:

 N<nnn>  JUMPIF {ccc} <ttt>

where:
 nnn is the statement number
 ccc is a condition statement which may be:

case a. :    <operand1>   <relational operator>  <operand2>
case b. :    I<ii>  <sss>

 ttt   is the target statement number

In the condition statement in case (a) above:

 operand1 should be a variable reference
 relational operator should be:

>  Greater Than
< Less Than
= Equals
! Not Equal

 operand 2 may be a variable or constant.

In the condition statement in case (b) above:

 <ii> is the input number
 <s> is the status to be checked for - may be 0 for low, 1 for high.

In both cases, transfer of control to the target statement occurs whenever the condition is evaluated true.

Example: Refer to the example for the MOVE, IMOVE commands above.

2.1.11 Command: CALL, RET
Subroutine calling and return are accomplished as follows:

 N<nnn>  CALL <ttt>
 N<mmm>  ....

 N<ttt>    RET

where:
 nnn is the statement number
 ttt   is the target statement number
 mmm is the following statement

Example:

 N40  CALL 10
 N50  JUMP  40

 N10  IMOVEWAIT  500 1000
 N20  DELAY 30
 N30  RET

This program segment works as follows:
 In statement 40, the subroutine at statement 10 is called.
 Program control is transferred to statement 10.
 In statement 10, the motor moves by 500 steps with speed 1000.
 In statement 20, the system waits for 30 milliseconds
 In statement 30, the program jumps to statement 50, i.e. executing a  return.
 In statement 50, program jumps to statement 40.
 the above sequence endlessly.

Note:

  1. Utmost 3 levels of nesting is provided for the calling sequence.
  2. Variable values changed in the subroutine remain changed, i.e., there is no saving of context except for return statement.
2.1.12 Command: COMP
Arithmetic computation is performed using this command.  The syntax is:

 N<nnn>  COMP  <rrr>  =  <operand1> { <operator>  <operand2> }

where,
 <nnn> is the statement number
 <rrr> is the result which should be a variable reference.  This value should not be a constant.
 <operand1> is the first operand of the arithmetic/logical computation.  This may be a constant (for assignment only) or parameter reference.
  In case of simple assignment, the following two fields may be omitted.
 <operator> The operator may be:

+ Addition
- Subtraction
& Bitwise AND ing
| Bitwise OR ing
^ Bitwise XOR ing

 <operand2> is the second operand of the operation.  This may be a constant or a parameter reference.

Example:

 N10   COMP    #2 = 40
 N20   COMP    #2 = #1 + 1
 N30   COMP    #2 = #4 + #6

 In the above program segment,

 In statement 10, the variable 2 is assigned a value 40
 In statement 20, the variable 2 is assigned a value contained in variable 1  added with 1.
 In statement 30, the variable 4 is added to variable 6 and stored in variable  2. Note that variable 6 used here is the actually the current position of the  axis.



3. Local Mode Operation

As mentioned earlier, the IMC supports a minimal set of operations in a local mode.  This is the default mode of operation after powering up. The features provided are:


When the unit is powered up, the display shows:
  GCD

Pressing F1 key leads to the SLAVE mode, in which programs may be downloaded from the PC.  The display shows “SLAVE”.

Pressing F2 key leads to the local mode.  In the local mode:
 

  1. The UP arrow key may be used to move to a specified position.
  2. The DOWN arrow key is pressed to go the Jogging mode.
  3. The LEFT arrow key is pressed to go the editing mode.
3.1 Jogging/Inching
In this mode, the user may use the RIGHT arrow key to move in the positive direction, the LEFT arrow key to move in the negative direction.  Once the key is pressed, the motor starts moving.  Pressing the ESC key will stop the motion.

The F1 key should be pressed to set the speed.  When this key is pressed, the current speed is displayed. The ENTER key is now pressed to indicate that the speed is to be changed.  The 4 arrow keys may now be used to set the required speed.  After entering the requisite speed, the ENTER key should be pressed to store the new speed value.  However, if ESC is pressed, the system ignores the newly entered speed and old speed continues.

3.2 Going To Specified Position
It is frequently required while setting up a machine to move the axis to a specified position.  Achieving exact positioning with jogging is a somewhat difficult process.  This mode is provided to overcome this difficulty.

In this mode, the system displays the position.  The user may press ENTER to change the position.  The system then allows editing of the position value in the display.  After data entry, the user presses ENTER to start register the newly entered position.  Pressing F2 starts the motion. If he presses ESC, the system ignores the newly entered value.

Speed setting is as discussed under the Jogging section.

3.3  Edit Mode
Variable editing is done in this mode.  The user may scroll across the variables using the right and left arrow keys.  When a particular variable number is displayed, the user may press ENTER to start changing the value.  The 4 arrow keys are used to set the new value, digit by digit. On pressing ENTER the values are stored in the E2PROM.  (Note that all the variable values are saved when this operation is done.)



4. Application Example

In this section we shall consider a cut to length application and develop the macro program for implementing the same on the IMC.
 

4.1 Description
The machine is expected to index or pull a fabric to a particular set length.  In order to avoid integral wind up, marks are provided on the fabric to indicate length to be cut.  These marks are sensed by a sensor which drives one of the inputs of the IMC. If, however, the mark is not sensed within a particular length, the motor should be stopped anyway. A start sensor triggers the indexing process.

A set-up mode is to be provided where the operator will manually run the motor in either direction using two push button switches to do the initial set-up.  Thereafter, he throws a toggle switch to indicate that the machine should be go to an automatic mode.  The operator should be able to set the number of cuts to be performed and the machine should stop after performing the required number of cuts.

Lamps are to be provided to show whether the system is in the manual or automatic mode.

4.2 Connections and Set-up

The inputs and outputs connected are:

 Input #0  Jog + input
 Input #1  Jog - input
 Input #2  Toggle Switch - 0 - Set-up
          1 - Auto operation
 Input #3  Mark Sensor Input - 0 - Mark sensed
       1 - Not sensed
 Input #5  Start input trigger  - 1 Active

 Output #1  Set-up Lamp 1 - ON, 0 - Off
 Output #2  Automatic Lamp 1 - ON, 0 - Off
 

It is assumed that the user will set:

 Variable #2 for Auto indexing speed
 Variable #3 for setting Jogging Speed
 Variable #4 for Total number of cuts required
 Variable #5 for Maximum length
4.3 Macro Code

The following is the macro code for this application.  Comments are provided for ease of comprehension.

% Code Starts here
% Whether Auto or Manual
N02 JUMPIF I2 1 100
% Manual here
% Switch the output to show set-up lamp
N03 OUTPUT 1 1
N04 OUTPUT 1 0
% Jogging here (implemented in 60)
N10 CALL 60
N20 JUMP 02
%
% Now automode working
% Reset counter
N100 COMP #1 = #4
% Wait for start input
N100 JUMPIF I5 110
% No start, check auto man switch again
N102 JUMPIF I2 1 100
N104 JUMP 02
% Start sensed, start moving
N110 COMP #0 = #6
N111 IMOVE #4 #2
N112 JUMPIF I3 0 N120
N113 JUMPIF #0 = #6 112
% Movement is over and yet no mark sensor , go back to top
N114 JUMP 02
% One cut length over, reduce counter
N120 COMP #1 = #1 - 1
% if all cuts over, go back to top
N122 JUMPIF #1 = 0 2
%
% Subroutines are following
%
% Jogging is implemented in subroutine 60
N60 JUMPIF I0 1 70
N62 JUMPIF I1 1 80
N63 RET
% Jog + pressed, start moving
% Speed is in parameter 3
N70 IMOVE 20000 #3
% Wait for jog+ to be released
N72 JUMPIF I0 1 72
N73 STOP
N74 RET
N70 IMOVE -20000 #3
% Wait for jog+ to be released
N82 JUMPIF I1 1 82
N83 STOP
N84 RET

As can be seen from the above code, if the application sequence is clear then generation of the MACRO code is simple.  This shows MACRO command set developed is simple yet powerful for end users/OEMs to successfully realise various applications in a short time.