PLC With Pic16F648A: Microcontroller (PART 1)
PLC With Pic16F648A: Microcontroller (PART 1)
PLC With Pic16F648A: Microcontroller (PART 1)
PLC/MCU
ASSOCIATE PROFESSOR DR MURAT UZAM FROM NIGDE UNIVERSITY IN TURKEY KICK-STARTS A SERIES OF ARTICLES ON A PROJECT THAT FOCUSES ON A MICROCONTROLLER-PLC
9. Logical Macros: The following logical macros are described in this article: inv_R, AND, NAND, OR, NOR, XOR, XNOR. These macros are applied to an 8 bit register (R1) with another register (R2) or an 8 bit constant (K). 10. Shift&Rotate Macros: The following Shift&Rotate macros are described in this article: SHIFT_R (shift right the contents of register R), SHIFT_L (shift left the contents of register R), ROTATE_R (rotate right the contents of register R), ROTATE_L (rotate left the contents of register R), SWAP (swap the nibbles of the register). 11. Multiplexer Macros: The following multiplexer macros are described in this article: mux_2_1 (2x1 MUX), mux_2_1_E (2x1 MUX with Enable input), mux_4_1 (4x1 MUX), mux_4_1_E (4x1 MUX with Enable input), mux_8_1 (8x1 MUX), mux_8_1_E (8x1 MUX with Enable input). 12. DeMultiplexer Macros: The following demultiplexer macros are described in this article: Dmux_1_2 (1x2 DMUX), Dmux_1_2_E (1x2 DMUX with Enable input), Dmux_1_4 (1x4 DMUX), Dmux_1_4_E (1x4 DMUX with Enable input), Dmux_1_8 (1x8 DMUX), Dmux_1_8_E (1x8 DMUX with Enable input). 13. Decoder Macros: The following decoder macros are described in this article: decod_1_2 (1x2 decoder), decod_1_2_E (1x2 decoder with Enable input), decod_2_4 (2x4 decoder), decod_2_4_E (2x4 decoder with Enable input), decod_3_8 (3x8 decoder), decod_3_8_E (3x8 decoder with Enable input). 14. Priority Encoder Macros: The following priority encoder macros are described in this article: encod_4_2_p (4x2 priority encoder), encod_4_2_p_E (4x2 priority encoder with Enable input), encod_8_3_p (8x3 priority encoder), encod_8_3_p_E (8x3 priority encoder with Enable input), encod_dec_bcd_p {decimal to BCD (Binary Coded Decimal) priority encoder}, encod_dec_bcd_p_E (decimal to BCD priority encoder with Enable input). 15. An Example: This article describes an example of a remotelycontrolled model gate system and makes use of UZAM_PLC to control it for different control scenarios. The reader is expected to be familiar with PLCs, PIC microcontrollers and PIC Assembly language. UZAM_PLC macros are developed by using PIC Assembly language. The program development environment used is that of MPLAB IDE (www.microchip.com).
www.electronicsworld.co.uk
21
PLC/MCU
Feature
rogrammable Logic Controllers (PLCs) have been extensively used in industry for the past five or six decades. PLC manufacturers offer different devices in terms of functions, program memories and the number of inputs/outputs (I/O), ranging from a few to thousands of I/Os. The design and implementation of PLCs have long been a secret of the PLC manufacturers. As a microprocessor-based technology, the functionality of a PLC is well known from the end-user/programmer point of view, but by now no serious work has been reported to describe a microprocessor/microcontroller based implementation of a PLC. With a series of articles I aim to describe a PIC microcontroller based design and implementation of a PLC, called
UZAM_PLC with PIC16F648A. First in the series is this article, which describes the hardware of UZAM_PLC with PIC16F648A.
macros. In addition, many new features have been included within UZAM_PLC project to make it more of an engulfing PLC. However, this project does not include graphical interface PC software as in PICBIT or in other PLCs for developing PLC programs. Rather, PLC programs are developed by using macros as done in the Instruction List (IL) PLC programming language. An interested and skilled reader could well and encouraged to develop graphical interface PC software for easy use of UZAM_PLC.
22
Feature
PLC/MCU
board is shown in Figure 1. The main board contains mainly five sections: power, programming, CPU (Central Processor Unit), inputs and outputs. The power section accepts 12V AC input and produces as outputs 12V DC to be used as the operating voltage of relays, and 5 V DC to be used for ICs, inputs, etc. The programming section deals with the programming of PIC16F648A microcontroller. For programming the PIC16F648A in circuit, it is necessary to use a PIC programmer hardware and software with ICSP (In Circuit Serial Programming) capability. For those who have a PC with serial port, PCB files for a PIC programmer hardware, called JDM programmer, and related software can be downloaded (please contact the editorial office of
www.electronicsworld.co.uk
Electronics World for details). For other types of USB or parallel port PIC programmers the reader is expected to make necessary arrangements. ICSP connector takes the lines VPP(MCLR), VDD, VSS(GND), DATA (RB7), CLOCK (RB6) from the PIC programmer hardware through a properly prepared cable and it serves them to a 4PDT (four pole double throw) switch. There are two positions of the 4PDT switch. As seen in Figure 1, in one position of 4PDT switch, PIC16F648A is ready to be programmed and in the other position the loaded program is run. For properly programming the PIC16F648A by means of a PIC programmer and the 4PDT switch, it is also a necessity to switch off the power switch. The CPU section consists of the
PIC16F648A microcontroller. Although it can run up to 20MHz, in UZAM_PLC it is fixed to run at 4MHz with its internal oscillator. This frequency is fixed because time-delays are calculated based on this speed. However, by means of two switches, namely SW1 and SW2, it is also possible to use an external oscillator with different crystal frequencies. When doing so, time-delay functions must be calculated accordingly. SW3 directs the RA5 pin either to one pole of 4PDT switch or to the future extension connector.
PROGRAMMING PICS
When programming PIC16F648A, RA5 should be connected to 4PDT switch. RB0, RB6 and RB7 pins are all reserved to be used for an 8-bit parallel to serial converter
Electronics World - November 08
23
PLC/MCU
Feature
register 74HC/LS165. Through these three pins and with added 74HC/LS165 registers we can describe as many inputs as we wish. RB0, RB6, and RB7 are the data in, the clock in and the shift/load pins, respectively. Similarly, RB3, RB4 and RB5 pins are all reserved to be used for 8-bit serial to parallel converter register/driver TPIC6B595. Through these three pins and with added TPIC6B595 registers we can describe as many outputs as we wish. RB3, RB4 and RB5 are the clock out, the data out and the latch out pins, respectively. The remaining unused pins of the PIC16F648A are connected to the future extension connector.
PIC16F648A provides the following: 4096 words of Flash program memory; 256 bytes of RAM data memory and 256 bytes of EEPROM data memory. The UZAM_PLC macros make use of registers defined in RAM data memory. Note that it may be possible to use PIC16F628A as the CPU, but one has to bear in mind that PIC16F628A provides the following: 2048 words of Flash program memory; 224 bytes of RAM data memory and 128 bytes of EEPROM data memory. In this case it is necessary to take care of the usage of RAM data memory. The inputs section introduces 8 discrete inputs for the UZAM_PLC, called I0.0, I0.1, ..., I0.7. Each input can accept 5V DC or 24V
DC signals. These external input signals are isolated from the other parts of the hardware by using NPN type opto-couplers (e.g. 4N25). For simulating input signals, one can use on board push-buttons as temporary inputs and slide switches as permanent inputs. In the beginning of each PLC scan cycle (get_inputs) 74HC/LS165 is loaded (RB7 (shift/load) = 0) with the level of 8 inputs and then this data is serially clocked in (when RB7 = 1; through RB0 data in and RB6 clock in pins). If there is no I/O extension board used, then 8 clock_in signals are enough to get the 8 input signals. For each I/O extension board, 8 more clock_in signals are necessary.
Figure 3: Photographs of (a) the UZAM_PLC main board, (b) UZAM_PLC I/O extension board, (c) UZAM_PLC main board with a PIC programmer, (d) UZAM_PLC main board plus an I/O extension board and a USB PIC programmer, (e) UZAM_PLC main board plus two I/O extension boards and a USB PIC programmer
Feature
PLC/MCU
DATA INPUT
The serial data coming from the I/O extension board is taken from the SI input of 74HC/LS165. The outputs section introduces 8 discrete relay outputs for the UZAM_PLC, called Q0.0, Q0.1, ..., Q0.7. Each relay operates with 12V DC and is driven by an 8-bit serial to parallel converter register/driver TPIC6B595. Relays have SPDT (single pole double throw) contacts with C (common), NC (normally closed) and NO (normally open) terminals. At the end of each PLC scan cycle (send_outputs) the output data is serially clocked out (through RB3 clock out and RB4 data out pins) and finally latched within TPIC6B595. If there is no I/O extension board used, then 8 clock_out signals are enough to send the 8 output signals. For each I/O extension board, 8 more clock_out signals are necessary. The serial data going to the I/O extension board is sent out from the SER OUT (pin 18) of TPIC6B595. In addition, there is also an I/O extension connector DB9F for conveying the I/O data to and from all the connected extension I/O boards. The PCB design files of the main board can be received from the editorial offices of Electronics World. Note that in the PCB design of the main board, some lines of I/O extension connector are different from the ones shown in Figure 1.
As shown in Figure 2, the I/O extension board contains mainly two sections: discrete inputs (8 of them) and discrete outputs (also 8 of them). They are similar to the ones as described for the main board. The I/O extension connector DB9M seen on the left connects the I/O extension board to the main board or to a previous I/O extension board. Similarly, the I/O extension connector DB9F seen on the right connects the I/O extension board to an adjacent I/O extension board. In this way we can connect as many I/O extension boards as necessary. The 12V DC power is taken from the main board or from a previous I/O extension board and it is passed to the next I/O extension boards. The 5V DC voltage is taken from the main board or from a previous I/O extension board through the DB9M connector and it is passed on to the next I/O extension boards through the DB9F connector. The PCB design files of the I/O extension board can be had from the editorial offices of the magazine. Note that in the PCB design of the I/O extension board, some lines of I/O extension connectors DB9M and DB9F are different from the ones shown in Figure 2. Figure 3 is a selection of photos of the UZAM_PLC main board and I/O extension board with and without a PIC programmer.
www.electronicsworld.co.uk
25