By
Terry L. Tuttle
The micro programmable logic controller uses a Motorola 68HC11 microprocessor to behave as a mnemonic ladder logic controller. The Tuttle-Motorola PLC is able to read the eight inputs 0 though 7, analyze ladder logic and change the outputs (8 through F) according to the programmed logic. The program the Tuttle PLC is broken up in three sections; RAM (0-1A), the ladder logic (0100-01FF), and the main program (B600-B7FF). The ram is used to store the program variables. Program space is normally the preferred section for these variables, but there was a need to conserve program space.
The second section is where the ladder logic is stored. Each command is a byte of data composed of two hexadecimal characters. In the space between 0100 and 01FF there are 256 bytes available for your program. The Tuttle logic is as simple as A, B, C, D, E, & F. A# stand for AND. AND checks to see if an output or an input is TRUE, this can be imagined as a normally open set of contacts (-] [-). Inputs, outputs, timer, and the counter can be used to make a series of contacts (-] [--] [--] [--] [--). BB stands for BRANCH. The BRANCH (BB) command allows for parallel sets of contacts for a given output. C stands for COLUMNS. After each set of branches the rung is divided in sets of columns. It is recommended to place a BB after each series of contacts. Any branch can be true in order for the column to be true. All columns must be true in order for the rung to be true. It is also recommended to place a CC after each set of branches. D stands for DO. If all of the columns in the rung are true the outputs (8 through C) can be set to a true. There are three special cases of DO's; the timer (DF), counter (DE) and counter reset (DD). The counter and the timer need another byte of information. The second byte for the timer is the seconds in hexadecimal from 00 to FF. This is 256 seconds. The second byte for the counter is also in hexadecimal. The timer is a non-retentive do nothing timer. Nothing will change while the timer is activated. Once the timer is complete the output F will go true as long as the rung is true. The other special DO cases pertain to the counter. DE activates the counter and the count is incremented for each off to on cycle of the rung. Once the count is complete the output bit E is set to true. The DD command will reset the counter. The counter does not have to be finished before the counter can be reset. E stands for the END. At the end of the ladder an EE command is used to send the program counter back to the first rung. The last command is F that is for FALSE. This command is opposite of the AND command. AND checks to see if an input or output is not true. FALSE's and AND's can be used in the same series. An example might look like this A1 F8 A3 F4 (--] [--]/[--] [--]/[--).
All together a one rung program might look like:
A1 A2 F3 BB A9 FA BB CC D8 EE
9 A
|--] [--]/[--------|
| 1 2 3 | 8
------|-] [--] [---]/[---|----------------( )---
The program is in assembly language for the Motorola 68HC11. The program starts with most of the variables used in the program. The RAM storage for the variables is at 0000. The variables in assembly language are preferred to be placed in the program EEPROM, but in this case the program space is the limiting component to the program. This is done to allow the logic to be placed at 0100. The program itself has to be placed between B600 and B7FF. This is because of using Buffalo as the operating environment for the micro-controller. A possible improvement would be to get the micro-controller free of the Buffalo. This would allow more programming space. If the PLC was unimpeded by the PC, the PLC could be battery operated.
The initialization of the program is very similar to a counter reset command. The program stores the inputs before the Tuttle1 logic are analyzed. This allows a more controlled cycle through the logic. The outputs were originally saved but removing that portion of the program freed up space. This also allowed for an output to be changed several times during one cycle, and further evaluation of present output can be possible. In the initialization of the rung, all four of the branch strings, the branch counter, and column counter. In order to read the instructions the program counter is stored in the register X, and remains in register X except for the timer sequence. By indexing the X register the instructions of the Tuttle1 logic one byte at a time. The first four bits of the byte are the instruction code and the second four bits are the I/O code. All the instruction codes are very straight forward, because the hexadecimal numbers greater than nine are represented by the letters A through F. As illustrated above all the letters are used in Tuttle1 logic. In the Motorola assembly language there are also branches (no connection with the Tuttle1 logic) that are similar to a basic IF THEN GOTO. At the end of the instruction portion of the program there are jumps. These jumps were added because branches can only go for a certain distance.
The AND logic incorporates strings - the brainstorm of the Tuttle1 PLC. After receiving the instruction code such as A4, the AND initializes an input and an output string to register D (which is the combined A&B register) to all ones. A cleared bit is then rotated into the right position from 0 to F. The string AND'ed with the working string, then becomes the new working string
Example of the A1 AA AD A4 Command:
OUTPUTS INPUTS
fedc ba98 7654 3210 bits
1101 1011 1111 1101 A1 AA AD
1111 1111 1110 1111 A4
AND
1101 1011 1110 1101 New Working
(1)
The False (F#) is very similar to the And (A#) command. The False command initializes the working string to zeros. After the set bit is a one, the working strings are OR'ed with the set bit.
NOT OUTPUTS NOT INPUTS
fedc ba98 7654 3210 bits
0010 0100 0000 0010 F1 FA FD
0000 0000 0001 0000 F4
OR
0010 0100 0001 0010 New Working (2)
The branch command (BB) is the storing of the four strings onto the stack. The program may be improved by using variables stored in RAM for the stored working strings. This would require more program memory to be able to store three sets of working strings. The handling of data not used by the operator in the stack is a preferred method of transferring data. Using the stack allows the operator more flexibility. Even though the stack can handle eight branches it is best to keep the number of branches under four. The stack starts at approximately 47 hex and the variables go up to 1A. The stack goes down four bytes for every branch. If the stack is to large it will start overwriting the variables. The micro-controller also uses the stack for holding the registers during interrupts. If more program memory was available it would be a good idea to mask all maskable interrupts.
The instruction code Column (CC) is a little more complicated. Not only because this command pulls information from the stack, initializes the stack and places new data onto the stack. During the column command each of the stored strings is compared to the stored inputs and the actual outputs. The two I/O strings are AND'ed with the excising I/O's. The two False I/O strings are OR'ed with the excising I/O's. All four strings must be true in order for the branch to be true. If any branch is true the true flag is placed onto the stack. If the inputs 1, 3, 5 & 7 and the outputs 8, 9, B, & D are on:
Not Outputs Not Inputs Outputs Inputs
fedc ba98 7654 3210 fedc ba98 7654 3210 bits
0001 0000 0001 0000 1111 0111 1111 1101 A1 AB F4 FC
0010 1011 1010 1010 0010 1011 1010 1010 Excising
AND OR
0000 0000 0000 0000 1111 1111 1111 1111 True (3)
The DO (DD) Command is to control the output. The output logic checks all the columns for a true in order for the output to on. If any of the outputs is not true than the output is turned off. For flexibility the column command does not have to proceed the Do command. The program will automatically perform a column command in order to check to see if the branches are true. The output is turned on similar to the way the False command is accomplished. The double accumulator is cleared and the set bit is rotated into the proper position. The set bit is than is than OR'ed with the present outputs.
If the DO bit is an input an error will happen because the inputs are read only bits. If the present outputs are 8, 9, B, & D, and the command is DA:
OUTPUTS
fedc ba98 bits
0000 0100 DA
0010 1011 Old Outputs
OR
0010 1111 New Outputs (4)
If the rung is not true, the double accumulator is set with ones and the cleared bit is rotated into position. The outputs are then AND'ed with the set bit. This time DA is the command and the rung is found to be false. If the program evaluates a column and determines it to false, all other columns must be removed from the stack. Failure to do this will result in some or all of the variables being overwritten. There are three special cases of Do outputs.
OUTPUTS
fedc ba98 bits
1111 1011 DA
0010 1111 Old Outputs
AND
0010 1011 New Outputs (5)
The first two special outputs are for the counter. DE ## is the command for the counter. The D means that the program evaluates the rung the same as an output 8 through C. The program checks to see if the counter is already complete and the output is turned on. If the counter is not done, the program checks the flags to see if the rung is going from an off to an on transition. The on flag is placed in memory for the following cycles. The program gets the accumulated count from memory and increments it. The accumulated count is reached than the output bit E is set. The same as discussed before for a normal output.
The next is the DD command that is the Do a counter reset. If the rung is true, the output bit E, and the accumulated count value are cleared. The counter can be used many times for different values but never two at the same time. Previous counters must be reset. The program can be improved by placing two bytes of information after the instruction byte. One can be for the setpoint and one can be the accumulated value. Another options is to use an output can be used as a timer sequence.
The last of the special outputs is the Timer (DF). The timer uses a second byte of information in order to get the delay time. The delay time can be reduced by reducing the number loaded into the second loop. The program can not do anything else while the timer is operating. This timer works great for blinking lights or waiting. The Motorola controller has several timing circuits built into the processor. Using the chip's interrupts required much more memory and is more complicated than a do nothing loop. Using the interrupts better simulate a real PLC. Further study in this area is required.
The last command is the END (EE) command. The end of the program command actually sends the program back to the beginning where it stores the inputs resets the program counter and initializes the rung.
The self check feature was a simple addition the computer added two numbers and verified that the answer was correct. If the answer was not correct the program would indicate that an error had happened. If none of the instructions are acknowledged, the program turns all outputs on and stops the program. The program uses an all on instruction to better illustrate the condition. There are often times when the program does not have any outputs on and appears to be working, but is actually off doing something else.
The Tuttle1 PLC uses a very simple for of logic to get the required outputs given a set of inputs. The micro-controller requires a large amount of programming to achieve the outputs that are achievable using Tuttle1 logic. Several alterations are available to the program to customize the logic for advanced programmers. Relay interfacing can be available right on the card itself. The inputs are a little more difficult and if possible require a five volt supply.
AND and the FALSE commands add contacts to a working string, BRANCH stores these strings, COLUMN checks these branches against the I/O's, the DO command provide the proper outputs based on the logic, the counters count and the timers time,
The END starts everything all over.