Monday, February 14, 2011

Binary People: Learning your 1's and 0's



Introduction 

"There are 10 types of people in the world: Those who understand binary, and those who don't."
If you don't get this joke then hopefully by the end of the chapter you'll get a chuckle out of it. You see, in the binary number system 10 = 2. How? Consider if you had no choice but to count with only a zero or a one. Pretend that the evil goblin of number snatchers had taken every number from two to nine. How would you count anything? You'd have to do it like 0, 1, 10, 11, 100, 101, 110, 111 and so on. You get the point?  Therefore, if you had three apples then the third apple would be designated as 10 when in reality you only have three apples to eat.
When it comes to computers and therefore PLCs they can only store in memory a 0 or a 1.  That's the beauty of our digital age, it's either "on" or it's "off".  Those memory chips in computers are actually made of rows upon rows of circuits that are either on at some voltage or off at some voltage.  Therefore a computer at it's very basic level can only count using a 0 (off) or a 1 (on).
That's why it's called binary because there are only two numbers like there are only two wheels on a bicycle.  The number system we are used to using is called decimal (dec = 10) and therefore we get to use ten numbers from 0 to 9.  When you think about it, it's truly arbitrary how we count.  You could also use an octal system (by 8) or hexidecimal (by 16) numbering system which we'll talk about a little later.

Base 10: An Old Familiar Friend 

Let's start off by looking closer at our all too familiar base 10 decimal system and then compare it to binary.  Decimal, like all these other number systems, is based on place-value system.  This means that the value of a digit depends both on the digit itself and it's position within the number.  The following figure shows the weights of a decimal number broken down into columns.

Place-Value number systems
 
That much is obvious right?  So with a number like 9876 we add it up like this: 
 
01-01 combining digits with column weights

The value of the number is computed by multiplying each digit by the weight of its position and adding up the results. 

Now for Binary People: Learning your 1s and 0s.">Binary

Remember that for a base 10 system the weights are 1, 10, 100, 1000 and so on.  For a binary system the weights are 1, 2, 4, 8, 16, 32, 64, etc.
01-03 place value number systems for binary
 
To figure out the value of a binary system we do the same as with the decimal but with different weights. 
 
01-04 combining digits with column weights binary
 
The base of the number is usually expressed in a subscript so that in our examples 111112 = 3110 and 101012 = 2110.  It sure is a little cumbersome to count in binary but at least it's easier then Roman numerals Laughing.

Word, Byte and Bit

What do you call a group of binary digits?  The geeks who first thought this stuff up decided to call a binary digit a bit (b-inary dig-it).  This is not to be confused with Tim-bits.  After some time they decided that it would be good to call a group of 8 bits a byte.  Funny bunch of geeks that they were the term nibble became used for 4 bits being a subset of byte.  Finally, a group of 16 bits are referred to as a word.  Here's a picture to drive home the point.
01-05 word bytes bits
 



HOW PLC WORKS


How PLCs Work

A programmable logic controller is a specialized computer used to control machines and processes.  It therefore shares common terms with typical PCs like central processing unit, memory, software and communications.  Unlike a personal computer though the PLC is designed to survive in a rugged industrial atmosphere and to be very flexible in how it interfaces with inputs and outputs to the real world.
The components that make a PLC work can be divided into three core areas.
  • The power supply and rack
  • The central processing unit (CPU)
  • The input/output (I/O) section
PLCs come in many shapes and sizes.  They can be so small as to fit in your shirt pocket while more involved controls systems require large PLC racks.  Smaller PLCs (a.k.a. “bricks”) are typically designed with fixed I/O points.  For our consideration, we’ll look at the more modular rack based systems.  It’s called “modular” because the rack can accept many different types of I/O modules that simply slide into the rack and plug in.

PLC angled with doors closed and text
 

The Power Supply and Rack

So let’s start off by removing all our modules which leaves us with a naked PLC with only the power supply and the rack. 

PLC empty rack with text


The rack is the component that holds everything together.  Depending on the needs of the control system it can be ordered in different sizes to hold more modules.  Like a human spine the rack has a backplane at the rear which allows the cards to communicate with the CPU.  The power supply plugs into the rack as well and supplies a regulated DC power to other modules that plug into the rack.  The most popular power supplies work with 120 VAC or 24 VDC sources.

The CPU

The brain of the whole PLC is the CPU module.  This module typically lives in the slot beside the power supply.  Manufacturers offer different types of CPUs based on the complexity needed for the system.
The CPU consists of a microprocessor, memory chip and other integrated circuits to control logic, monitoring and communications.  The CPU has different operating modes.  In programming mode it accepts the downloaded logic from a PC.  The CPU is then placed in run mode so that it can execute the program and operate the process. 

SLC500 CPU components


Since a PLC is a dedicated controller it will only process this one program over and over again.  One cycle through the program is called a scan time and involves reading the inputs from the other modules, executing the logic based on these inputs and then updated the outputs accordingly.  The scan time happens very quickly (in the range of 1/1000th of a second).  The memory in the CPU stores the program while also holding the status of the I/O and providing a means to store values.

CPU operating cycle


I/O System

The I/O system provides the physical connection between the equipment and the PLC.  Opening the doors on an I/O card reveals a terminal strip where the devices connect. 

PLC face with doors open


There are many different kinds of I/O cards which serve to condition the type of input or output so the CPU can use it for it’s logic.  It's simply a matter of determining what inputs and outputs are needed, filling the rack with the appropriate cards and then addressing them correctly in the CPUs program.

PLC inserting card


Inputs
Input devices can consist of digital or analog devices.  A digital input card handles discrete devices which give a signal that is either on or off such as a pushbutton, limit switch, sensors or selector switches.  An analog input card converts a voltage or current (e.g. a signal that can be anywhere from 0 to 20mA) into a digitally equivalent number that can be understood by the CPU.  Examples of analog devices are pressure transducers, flow meters and thermocouples for temperature readings
Outputs
Output devices can also consist of digital or analog types.  A digital output card either turns a device on or off such as lights, LEDs, small motors, and relays.  An analog output card will convert a digital number sent by the CPU to it’s real world voltage or current.  Typical outputs signals can range from 0-10 VDC or 4-20mA and are used to drive mass flow controllers, pressure regulators and position controls.

Programming a PLC

In these modern times a PC with specially dedicated software from the PLC manufacturer is used to program a PLC.  The most widely used form of programming is called ladder logic.  Ladder logic uses symbols, instead of words, to emulate the real world relay logic control, which is a relic from the PLC's history.  These symbols are interconnected by lines to indicate the flow of current through relay like contacts and coils.  Over the years the number of symbols has increased to provide a high level of functionality. 
The completed program looks like a ladder but in actuality it represents an electrical circuit.  The left and right rails indicate the positive and ground of a power supply.  The rungs represent the wiring between the different components which in the case of a PLC are all in the virtual world of the CPU.  So if you can understand how basic electrical circuits work then you can understand ladder logic.
In this simplest of examples a digital input (like a button connected to the first position on the card) when it is pressed turns on an output which energizes an indicator light.

Simple ladder logic example

PLC Definition


What is a PLC? 

A Programmable Logic Controller, or PLC for short, is simply a special computer device used for industrial control systems. They are used in many industries such as oil refineries, manufacturing lines, conveyor systems and so on. Where ever there is a need to control devices the PLC provides a flexible way to "softwire" the components together.
The basic units have a CPU (a computer processor) that is dedicated to run one program that monitors a series of different inputs and logically manipulates the outputs for the desired control.  They are meant to be very flexible in how they can be programmed while also providing the advantages of high reliability (no program crashes or mechanical failures), compact and economical over traditional control systems.

A Simple Example 

Consider something as simple as a switch that turns on a light.  In this system with a flick of the switch the light would turn on or off.  Beyond that though there is no more control.  If your boss came along and said I want that light to turn on thirty seconds after the switch has been flipped, then you would need to buy a timer and do some rewiring.  So it is time, labor and money for any little change.
00-01 switch to light
 

A PLC Saves the Day 

Now consider the same device with a PLC in the middle.  The switch is fed as an input into the PLC and the light is controlled by a PLC output.  Implementing a delay in this system is easy since all that needs to be changed is the program in the PLC to use a delay timer.
 
00-02 switch to plc to light

This is a rather simple example but in a larger system with many switchs and lights (and a host of other devices) all interacting with each other this kind of flexibility is not only nice but imperitive.  Hopefully a light bulb has now turned on over your head.