Building a Programmable Logic Controller with a PIC16F648A Microcontroller
eBook - ePub

Building a Programmable Logic Controller with a PIC16F648A Microcontroller

  1. 371 pages
  2. English
  3. ePUB (mobile friendly)
  4. Available on iOS & Android
eBook - ePub

Building a Programmable Logic Controller with a PIC16F648A Microcontroller

About this book

Programmable logic controllers (PLCs) are extensively used in industry to perform automation tasks, with manufacturers offering a variety of PLCs that differ in functions, program memories, and the number of inputs/outputs (I/O). Not surprisingly, the design and implementation of these PLCs have long been a secret of manufacturers. Unveiling the mysteries of PLC technology, Building a Programmable Logic Controller with PIC16F648A Microcontroller explains how to design and use a PIC16F648A-microcontroller-based PLC.

The author first described a microcontroller-based implementation of a PLC in a series of articles published in Electronics World magazine between 2008 and 2010. This book is based on an improved version of the project, including:



  • Updates to the hardware configuration, with a smaller CPU board and two I/O extension boards that now support 16 inputs and 16 outputs instead of 8


  • An increased clock frequency of 20 MHz


  • Improvements to several macros


  • Flowcharts to help you understand the macros (functions)

In this book, the author provides detailed explanations of hardware and software structures. He also describes PIC Assembly macros for all basic PLC functions, which are illustrated with numerous examples and flowcharts. An accompanying downloadable resources contain source files (.ASM) and object files (.HEX) for all of the examples in the book. It also supplies printed circuit board (PCB) (Gerber and .pdf) files so that you can have the CPU board and I/O extension boards produced by a PCB manufacturer or produce your own boards.

Making PLCs more easily accessible, this unique book is written for advanced students, practicing engineers, and hobbyists who want to learn how to build their own microcontroller-based PLC. It assumes some previous knowledge of digital logic design, microcontrollers, and PLCs, as well as familiarity with the PIC16F series of microcontrollers and w

Frequently asked questions

Yes, you can cancel anytime from the Subscription tab in your account settings on the Perlego website. Your subscription will stay active until the end of your current billing period. Learn how to cancel your subscription.
No, books cannot be downloaded as external files, such as PDFs, for use outside of Perlego. However, you can download books within the Perlego app for offline reading on mobile or tablet. Learn more here.
Perlego offers two plans: Essential and Complete
  • Essential is ideal for learners and professionals who enjoy exploring a wide range of subjects. Access the Essential Library with 800,000+ trusted titles and best-sellers across business, personal growth, and the humanities. Includes unlimited reading time and Standard Read Aloud voice.
  • Complete: Perfect for advanced learners and researchers needing full, unrestricted access. Unlock 1.4M+ books across hundreds of subjects, including academic and specialized titles. The Complete Plan also includes advanced features like Premium Read Aloud and Research Assistant.
Both plans are available with monthly, semester, or annual billing cycles.
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Yes! You can use the Perlego app on both iOS or Android devices to read anytime, anywhere — even offline. Perfect for commutes or when you’re on the go.
Please note we cannot support devices running on iOS 13 and Android 7 or earlier. Learn more about using the app.
Yes, you can access Building a Programmable Logic Controller with a PIC16F648A Microcontroller by Murat Uzam in PDF and/or ePUB format, as well as other popular books in Computer Science & Computer Engineering. We have over one million books available in our catalogue for you to explore.

Information

 

1 Hardware of the PIC16F648A-Based PLC

 
The hardware of the PIC16F648A-based programmable logic controller (PLC) consists of two parts: the CPU board and the I/O extension board. The schematic diagram and the photograph of the PIC16F648A-based PLC CPU board are shown in Figures 1.1 and 1.2, respectively. The CPU board contains mainly three sections: power, programming, and CPU (central processor unit)
The power section accepts 12 V AC input and produces two DC outputs: 12 V 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 the PIC16F648A microcontroller For programming the PIC16F648A in circuit, it is necessary to use PIC programmer hardware and software with In Circuit Serial Programming (ICSP) capability For related hardware and software to be used for programming the PIC16F648A-based PLC, please visit the following web page: http://www.meliksah.edu.tr/muzam/. For other types of USB, serial, or parallel port PIC programmers the reader is expected to make necessary arrangements The ICSP connector takes the lines VPP(MCLR), VDD, VSS(GND), DATA (RB7), and CLOCK (RB6) from the PIC programmer hardware through a properly prepared cable, and it connects them to a four-pole double-throw (4PDT) switch There are two positions of the 4PDT switch As seen from Figure 1.1, in one position of the 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 In the project reported in this book, the PLC is fixed to run at 20 MHz with an external oscillator. This frequency is fixed because time delays are calculated based on this speed By means of two switches, SW1 and SW2, it is also possible to use another internal or external oscillator with different crystal frequencies When doing so, time delay functions must be calculated accordingly SW3 connects the RA5 pin either to one pole of the 4PDT switch or to the future extension connector When programming PIC16F648A, RA5 should be connected to the 4PDT switch RB0, RB6, and RB7 pins are all reserved to be used for 8-bit parallel-to-serial converter register 74HC/LS165. Through these three pins and with added 74HC/LS165 registers, we can describe as many inputs as necessary. RB0, RB6, and RB7 are the data in, clock in, and 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,
Images
FIGURE 1.1
Schematic diagram of the CPU board.
Images
FIGURE 1.2
Photograph of the CPU board.
we can describe as many outputs as necessary. RB3, RB4, and RB5 are the clock out, data out, and latch out pins, respectively. The remaining unused pins of the PIC16F648A are connected to the future extension connector. PIC16F648A provides the following: flash program memory (words), 4096; RAM data memory (bytes), 256; and EEPROM data memory (bytes), 256. The PIC16F648A-based 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: flash program memory (words), 2048; RAM data memory (bytes), 224; and EEPROM data memory (bytes), 128. In that case, it is necessary to take care of the usage of RAM data memory
Figures 1.3 and 1.4 show the schematic diagram and photograph of the I/O extension board, respectively. The I/O extension board contains mainly two sections: eight discrete inputs and eight discrete outputs The I/O extension connector DB9M seen on the left connects the I/O extension board to the CPU board or to a previous I/O extension board. Similarly, the I/O extension
Images
FIGURE 1.3
Schematic diagram of the I/O extension board.
Images
FIGURE 1.4
Photograph of the I/O extension board.
connector DB9F seen on the right connects the I/O extension board to a next I/O extension board. In this way we can connect as many I/O extension boards as necessary. Five-volt DC and 12 V DC are taken from the CPU board or from a previous I/O extension board, and they are passed to the next I/O extension boards. All I/O data are sent to and taken from all the connected extension I/O boards by means of I/O extension connectors DB9M and DB9F.
The inputs section introduces eight discrete inputs for the PIC16F648A-based PLC (called I0.0, I0.1, I0.7 for the first I/O extension board). Five-volt DC or 24 V DC input signals can be accepted by each input 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 onboard push buttons as temporary inputs and slide switches as permanent inputs In the beginning of each PLC scan cycle (get_inputs) the 74HC/LS165 is loaded (RB7 (shift/load) = 0) with the level of eight inputs and then these
Images
FIGURE 1.5
Schematic diagram of the CPU board plus two I/O extension boards.
Images
FIGURE 1.6
Photograph of the CPU board plus two I/O extension boards.
Images
FIGURE 1.7
Photograph of the CPU board plus two I/O extension boards and a USB PIC programmer.
data are serially clocked in (when RB7 = 1; through RB0 data in and RB6 clock in pins). If there is only one I/O extension board used, then eight clock_in signals are enough to get the eight input signals. For each additional I/O extension board, eight more clock_in signals are necessary. The serial data coming from the I/O extension board(s) are taken from the SI input of the 74HC/LS165
The outputs section introduces eight discrete relay outputs for the PIC16F648A-based PLC (called Q0.0, Q0.1, Q0.7 for the first I/O extension board). Each relay operates with 12 V DC and is driven by an 8-bit serial-to-parallel converter register/driver TPIC6B595 Relays have single-pole double-throw (SPDT) 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 are serially clocked out (through RB3 clock out and RB4 data out pins) and finally latched within the TPIC6B595. If there is only one I/O extension board used, then eight clock_out signals are enough to send the eight output signals. For each additional I/O extension board, eight more clock_out signals are necessary The serial data going to the I/O extension board(s) are sent out from the SER OUT (pin 18) of the TPIC6B595
The PCB design files of both the CPU board and the I/O extension board can be obtained from the CD-ROM attached to this book Note that in the PCB design of the CPU board and the I/O extension board, some lines of I/O extension connectors DB9M and DB9F are different from the ones shown in Figures 1.1 and 1.3.
The project reported in this book makes use of a CPU board and two I/O extension boards, as can be seen from the schematic diagram and photograph depicted in Figures 1.5 and 1.6, respectively. Thus, in total there are 16 inputs and 16 outputs. Figure 1.7 shows the PIC16F648A-based PLC consisting of a CPU board, I/O extension boards, 12 V DC adapter, and USB PIC programmer.

2 Basic Software

In this chapter, the basic software of the PIC16F648A-based PLC is explained A PLC scan cycle includes the following: obtain the inputs, run the user program, and update the outputs. It is also necessary to define and initialize all variables used within a PLC Necessary functions are all described as PIC assembly macros to be used in the PIC16F648A-based PLC The macros described in this chapter could be summarized as follows: HC16 5 (for handli...

Table of contents

  1. Cover Page
  2. Half title
  3. Supplementary Resources Disclaimer
  4. Title Page
  5. Copyright Page
  6. Dedication Page
  7. Table of Contents
  8. Preface
  9. Acknowledgments
  10. Background and Use of the Book
  11. About the Author
  12. 1 Hardware of the PIC16F648A-Based PLC
  13. 2 Basic Software
  14. 3 Contact and Relay-Based Macros
  15. 4 Flip-Flop Macros
  16. 5 Timer Macros
  17. 6 Counter Macros
  18. 7 Comparison Macros
  19. 8 Arithmetical Macros
  20. 9 Logical Macros
  21. 10 Shift and Rotate Macros
  22. 11 Multiplexer Macros
  23. 12 Demultiplexer Macros
  24. 13 Decoder Macros
  25. 14 Priority Encoder Macros
  26. 15 Application Example
  27. About the CD-ROM
  28. References
  29. Index