[MAT logo][Prev][Up][Next]

MAT IL language

Introduction

The MAT IL is a simple text transcription of the traditional "stepladder" style of programming (sometimes also called "mnemonics").

The stepladder is described a rung at a time from left to right.

At the top of the scan, inputs are read from the MatPLC core. The program is then scanned an instruction at a time from top to bottom (unless a JMP instruction changes this). Once scanning reaches the bottom of the program or the special instruction END, outputs are written to the MatPLC core and the process starts over.

For all non-latching relays, make sure an OUT or OUTI instruction is scanned on every scan. Otherwise relays are latching: unless an OUT, OUTI, SET or RST instruction changes them, they remain as they were.

Instructions

LD contact/register
Start new rung with a normal contact or a register.

LDI contact
Start new rung with an inverted contact.

K value
Start new rung with the given value, which can be on, off or a number.

AND contact
Add a contact on the end of the current rung (in series).

ANI contact
Add an inverted contact on the end of the current rung (in series).

OR contact
Add a contact in parallel with the current rung so far.

ORI contact
Add an inverted contact in parallel with the current rung so far.

OUT coil/register
Connect a relay coil to the rung. If the current rung is on, the relay turns on, if the current rung is off, the relay turns off. For numeric rungs, the value is written to the register.

There should not normally be more than one OUT or OUTI for each coil (unless one or the other is skipped using a JMP). Having more than one is valid, but will mean that some rungs (between the first and second OUT) will use the value from the first OUT, while a different value (from the second OUT) will actually appear on the output. This effect can be quite useful, of course, as long as scan-order is taken into account.

OUTI coil
Connect an inverted relay coil to the rung. If the current rung is on, the relay turns off, if the current rung is off, the relay turns on.

Please see the remarks at the OUT instruction.

SET coil
Connect the `set' coil of the relay to the rung. If the current rung is on, the relay turns on, otherwise no effect.

It is somewhat more sensible to have a SET or RST in combination with an OUT than it is to have two OUT instructions. For instance, an exception logic may wish to override a previous OUT, setting the relay on or off as appropriate. Nevertheless, care should be taken to avoid confusion.

RST coil
Connect the `reset' coil of the relay to the rung. If the current rung is on, the relay turns off, otherwise no effect.

Please see the remarks at the SET instruction.

LT register
LE register
GT register
GE register
Compare the current rung with the register numerically. The result will be on if the comparison is true, and off if it is false.

MCS
Master Control start - the current rung becomes a new rail. All subsequent LD, LDI and OR instructions will use this rail until another MCS or a MCE.

Warning: this instruction is not a substitute for hard-wired safety and emergency stop circuits.

MCE
Master Control end - cancels all current MCS.

ANB
And block - takes the current and previous rungs and connects them in series. This also converts them into a single rung for the purposes of subsequent ANBs and ORBs (up to 7 previous rungs may be used).

Unless you know what you are doing, you probably shouldn't have had an OUT on the previous rung.

ORB
Or block - takes the current and previous rungs and connects them in parallel. This also converts them into a single rung for the purposes of subsequent ANBs and ORBs (up to 7 previous rungs may be used).

Unless you know what you are doing, you probably shouldn't have had an OUT on the previous rung.

LTB
LEB
GTB
GEB
Comparison block - takes the current and previous rungs and compares them numerically. This also converts them into a single rung for the purposes of subsequent ANBs and ORBs, which will be on if the comparison is true, and off if it is false. (Up to 7 previous rungs may be used at any time.)

END
In main program, end program scan. In a subroutine, return. This can be used at the end of the program/subroutine, or in conjunction with JMP and LBL.

JMP label
If the current rung is on, transfer scanning to a different part of the program. Jumps can be made in any direction, to any point in the program, but not into or out of a subroutine.

It is valid to jump into the middle of a rung: before the jump the current rung (which is on) is discarded and the previous rung reinstated as the current rung (and so on).

If the current rung is off, JMP has no effect and scanning continues as normal on the current rung.

LBL label
Mark the location to which a JMP transfers scanning. When encountered, has no effect.

JSR subname
If the current rung is on, transfer scanning to a subroutine. When the subroutine finishes, scanning will resume at this point in the program.

Before the jump the current rung (which is on) is discarded and the previous rung reinstated as the current rung (and so on). This can be used to pass parameters to the subroutine.

If the current rung is off, JSR has no effect and scanning continues as normal on the current rung.

It is valid for a subroutine to JSR another, or even itself (directly or indirectly). In the latter case, care should be taken to avoid infinite recursion and ensure that the subroutine eventually returns.

SUB subname
Marks the beginning of a subroutine. The subroutine extends to the next SUB instruction or to the end of the program (though an END can be used to return from it prematurely).

The SUB instruction always marks the end of the previous subroutine or the main program. If it is encountered in normal scan, it causes a subroutine return (in a subroutine) or a program scan end (in main program), just like an END.

The only way to get into a subroutine is with a JSR. It is not valid to JMP in and out of subroutines or between different subroutines.

RET
If the current rung is on, return (in a subroutine) or end program scan (in main program).

When this instruction results in a return from subroutine, the current rung (which is on) is discarded and the previous rung reinstated as the current rung (and so on). This can be used to return values from subroutines.

If the current rung is off, RET has no effect and scanning continues as normal on the current rung.

POP
Discard the current rung and reinstate the previous rung as the current rung (and so on up to 7 rungs back).

NOP
No effect. May appear anywhere in the program.

Instructions appear one to a line. The instructions may appear in upper or lower case (ie "LD" is the same as "ld") but the contacts, coils and labels must agree exactly (ie "X1" is not the same as "x1").

Comments must appear on their own lines. They are indicated with a hash (#) or semicolon (;) at the beginning of a line.

Both instructions and comments may be indented from the left by any number of spaces and any number of spaces or tabs may be used to separate an instruction and its contact, coil or label.

At the start of each scan, both the current rung and previous rungs have undefined values (which means they could be anything). This means that the first instruction (other than LBL or NOP) must be LD or LDI and similarly a sufficient number of LD or LDI instructions must be scanned before an ANB or an ORB.

[Prev][Up][Next]

$Date: 2004/12/28 05:32:11 $