Here we give a brief overview of the PLC programming. The description is based on popular Micro PLC, but it is similar also for other conventional PLC controllers.
Let’s start by recapitulating the main features of the Micro PLC system. All inputs are electrically isolated, and have a range of 8 V to +16 V (typical: 0 to 12 Vdc). The inputs are numbered 0 through 5. The outputs are numbered 6 through 11, and have an open-collector structure. Each of them is capable of switching currents of up to 0.5 A, and voltages of up to 50 Vdc. Furthermore, the Micro PLC has available six bit memories (locations 12-17), and a program memory with a size of exactly 48 bytes (locations 16- 63). In practice, this offers enough room for a program consisting of 30 lines. An integrated counter is available with a count range of 0-250, along with a programmable delay capable of generating delays from 0.1 s to 25 s in steps of 0.1 s.
The Micro PLC is programmed via JTAG interface or a serial (RS232) link with a PC running the Micro PLC software. The Micro PLC has two modes: ‘program’ and ‘run’. When in program mode (e.g., after a reset pulse), the user is allowed to copy a program into the programming memory. Interestingly, this mode also allows the Micro PLC to be used as an external I/O device for the PC. In ‘run’ mode, the Micro PLC executes the program available in its memory. The Micro PLC indicates its status via two LEDs, a green one and a red one.
When the mains voltage disappears, the PLC automatically switches over to a back-up supply. The battery contains enough energy to cover a period of three to four hours. When the mains voltage suddenly disappears while a program is being executed, all program output is halted, and all outputs are switched off. Next, the green LED starts to flash. The instant the mains voltage reappears, the green LED stops flashing, and the system starts to execute the program again. If the mains voltage disappears while the PLC is in programming mode, you may simply continue programming. In other words, the PLC may also be programmed while it is disconnected from the mains.
PLC programming bears great resemblance to machine code programming. Each line of instruction code consists of three fields: line number, opcode and operand. Labels are not used. Consequently, all branch instructions (‘jumps’) relate to line numbers. When PLC programs are printed on paper, comment may be added. Just as with code for microcontrollers and microprocessors, opcodes may be represented by mnemonics.
To save memory space, the Micro PLC uses memory locations instead of line numbers as on conventional PLCs. Because of this, instructions with an operand take up only two memory locations, and an instruction without an operand, only one. In practice, the 48 available memory locations allow 30-odd program lines to be stored.
Besides its obvious function as a Programmable Logic Controller with a limited instruction set, the Micro PLC offers the functionality of an intelligent I/O card for PCs. As long as the Micro PLC is in ‘programming’ mode, it considers all characters with an ASCII value smaller than 250 as data, while characters in the range 251 through 255 are interpreted as commands.