Вы находитесь на странице: 1из 81

i

Automation with
PLC





Dr. Mohammad Ababneh
Department of Mechatronics Engineering
The Hashemite University










ii
Table of Contents

Table of Contents....................................................................................................................... ii
Preface ............................................................................................................................................ 1
Chapter 1: Introduction.......................................................................................................... 2
1.1 Introduction.......................................................................................................................... 2
1.2 Why PLC?............................................................................................................................. 3
1.3 PLC Hardware.................................................................................................................... 4
1.5 PLC Mixer Process Control Example ......................................................................... 7
Chapter 2: Digital Systems Review.................................................................................... 9
2.1 Introduction.......................................................................................................................... 9
2.2 Logical Gates..................................................................................................................... 11
2.2.1 The Logical AND function........................................................................................... 11
2.2.2 The Logical OR function.............................................................................................. 12
2.2.3 The Logical NOT function........................................................................................... 12
2.2.4 The Logical NAND function........................................................................................ 13
2.2.5 The Logical NOR function........................................................................................... 13
2.2.6 The Logical XOR function........................................................................................... 14
Chapter 3: Hard Wired versus Programmed Logic..................................................... 15
2.1 Hardwired Stop/Start Motor Control Circuit............................................................ 15
2.2 Examples of Hard Wired versus Programmed Logic ............................................. 16
Chapter 4: Bit Logic Instructions..................................................................................... 21
1.1 Normally Open Contact .................................................................................................. 21
1.2 Normally Closed Contact ............................................................................................... 22
1.3 Output Coil ......................................................................................................................... 23
1.4 Midline Output .................................................................................................................. 23
1.5 Output Invert Power Flow.............................................................................................. 23
1.6 Save RLO into BR Memory............................................................................................ 24
1.7 XOR function ..................................................................................................................... 24
1.8 Set Coil ................................................................................................................................ 25
iii
1.9 Reset Coil ........................................................................................................................... 25
1.10 Set-Reset Flip Flop ........................................................................................................ 26
1.11 Reset-Set Flip Flop ........................................................................................................ 26
Chapter 5 Timers ..................................................................................................................... 28
5.1 Introduction........................................................................................................................ 28
5.2 Time Base .......................................................................................................................... 28
5.3 Bit Configuration in the Time Cell ............................................................................... 29
5.4 Choosing the right Timer................................................................................................ 29
5.5 Timers ................................................................................................................................. 30
5.5.1: Pulse S5 Timer (S_PULSE) ........................................................................................ 31
5.5.2: Extended Pulse S5 Timer ( S_PEXT) ...................................................................... 33
5.5.3: On-Delay S5 Timer (S_ S_ODT) ............................................................................... 34
5.5.4: Retentive On Delay S5 Timer (S_ODTS)................................................................ 36
5.5.5: Retentive On-Delay S5 Timer (S_ODTS)................................................................ 38
Chapter 6: Counters................................................................................................................ 40
6.1: Up-Down Counter ........................................................................................................... 41
6.2: Up Counter........................................................................................................................ 42
6.3: Down Counter.................................................................................................................. 44
Chapter 7: Data Types ........................................................................................................... 46
7.1 Overview of the Data Types.......................................................................................... 46
7.2 Elementary Data Types ................................................................................................. 47
Chapter 8: More PLC Instructions.................................................................................... 50
8.1 Overview of All Ladder Instructions........................................................................... 50
8.2 Add double integer instruction (ADD_DI) .................................................................. 53
8.3 Compare integer instruction.......................................................................................... 54
8.4 Shift right integer instruction........................................................................................ 55
8.5 SQRT Square Root Instruction...................................................................................... 56
8.6 Subtract Real (SUB_R) .................................................................................................... 56
8.7 WAND_W (Word) AND Word........................................................................................ 57
Chapter 9: Computer Numerical Control (CNC).......................................................... 59
9.1 Introduction........................................................................................................................ 59
9.2 Fundamentals of CNC.................................................................................................... 61
iv
9.3 Motion control - the heart of CNC ................................................................................ 62
9.4 Understanding absolute versus incremental motion............................................. 64
9.5 Assigning program zero ................................................................................................. 64
9.6 Telling the machine what to do - the CNC program............................................... 65
9.7 Decimal point programming.......................................................................................... 67
9.7 Know your machine ........................................................................................................ 67
9.8 What is G-Code Programming? (CNC Machine)....................................................... 69
9.9 Directions of motion (axes) ............................................................................................ 72
References................................................................................................................................... 77

1
Preface


In these days Programmable Logic Controller (PLC) plays a main in industrial
control. Except for power systems, Logic Relay Control is something from the
past, and PLC is used in most of the industrial automation. In fact, it is said that
if you use more than six relays in machine, then it is more cost effective to
replace them with a PLC.

We believe that Siemens PLC has the loin share in the PLC market worldwide.
Therefore, it is very beneficial to provide our students with this expertise. In
addition, learning PLC is like learning computer programming, in that if you
master one PLC system, it is easy to understand other PLC systems.

The book is divided into nine chapters; Chapters one through three
introduces the PLC subject, digital logic and logic relay. These three chapters are
based on reference [1].Chapters four through present programming material
about bit logic, timers, counters, data types and rest of Siemens PLC
instructions. These five chapters are based on references [2] and [3]. Chapter
nine present the CNC material and based on references [4], [5], and [6].

This textbook is designed for undergraduate course in PLC automation using
Siemens PLC. The lack of textbooks in this field was huge motivation to produce
this book.
2
Chapter 1: Introduction



This chapter introduces the subject of the Programmable Logic Controller
(PLC). The PLC is simply a microprocessor-based device that is used mainly to
control industrial processes. Unlike the personal computer, the PLC is designed
for multiple inputs and multiple outputs, and is designed for the harsh industrial
environment. It reads process variables through sensors (like pressure,
temperature, weight, etc), these inputs are used based on a digital-controller
(saved in the PLC) to output certain outputs (like actuator, motor relay, horn,
etc) to control the industrial processes. The figure below shows a PLC cabinet.


Figure 1: PLC inside a control cabinet

1.1 Introduction

PLC is widespread in the industry and is the corner stone for almost all
industrial machines and equipment. It used in many applications, such
packaging, extruding, slitting, winding, defect-detection etc. And it hard to find
a plant without PLCs in it.
PLC are available from many manufacturers such Seimens, Allen Bradley,
Omron, Mitsubishi and Telemechanique. Seimens PLCs are most spread
worldwide. And Allen Bradley PLCs are more popular in the North America
market. Omron and Mitsubishi some portion of the international market. And
telemechanique the least popular among the above brands. This book will cover
the material that are common to PLCs and will use examples that applicable to
Seimens PLCs.
3
1.2 Why PLC?

A programmable logic controller (PLC) is a specialized computer used to
control machines and process. It uses a programmable memory to store
instructions and execute specific functions that include On/Off control, timing,
counting, sequencing, arithmetic, and data handling.

A big advantage of a PLC Control System is it eliminates much of the hard
wiring that was associated with conventional relay control circuits. Where the
program takes the place of much of the external wiring that would be required for
control of a process.

Also increased reliability is another important advantage of PLC. Once a
program has been written and tested it can be downloaded to other PLCs. Since
all the logic is contained in the PLCs memory, there is no chance of making a
logic wiring error.
Figure 2: An industrial process

In addition PLCs are more flexible than traditional controllers, where original
equipment manufacturers (OEMs) can provide system updates for a process by
simply sending out a new program. And it is easier to create and change a
program in a PLC than to wire and rewire a circuit. End-users can modify the
program in the field.

Furthermore lower cost is a huge benefit. Originally PLCs were designed to
replace relay control logic. The cost savings using PLCs have
been so significant that relay control is becoming obsolete, except for power
applications. Generally, if an application requires more than about 6 control
relays, it will usually be less expensive to install a PLC.

4


Figure 3: A control relay

A PLC can communicate with other controllers or computer equipment.
They can be networked to perform such functions as: supervisory control, data
gathering, monitoring devices and process parameters, and downloading and
uploading of programs.

PLCs have faster response time and they operate in real-time which means
that an event taking place in the field will result in an operation or output taking
place. Machines that process thousands of items per second and objects that
spend only a fraction of a second in front of a sensor require the PLCs quick
response capability. PLCs are easier to troubleshoot and have resident diagnostic
and override functions that allow users to easily trace and correct software and
hardware problems.

1.3 PLC Hardware

In general a PLC has four main components, these are power supply,
processor, input cards, output cards. Furthermore, a programming device is
used to enter and troubleshoot programs and problems as shown in the figure
below.
5

Figure 4: PLC System

The CPU is the brain of the PLC. It consists of a microprocessor for
implementing the logic, and controlling the communications among the modules.
Designed so the desired circuit can be entered in relay ladder logic form. The
processor accepts input data from various sensing devices, executes the stored
user program, and sends appropriate output commands to control devices.

The DC supply provides DC power to other
modules that plug into the PLC rack. In large
PLC systems, this power supply does not
normally supply power to the field devices. In
small and micro PLC systems, the power
supply is also used to power field devices.
I/O section consists of input modules and
output modules. Input card forms the
interface by which input field devices are
connected to the controller. The terms field
and real world are used to distinguish actual
external devices that exist and must be
physically wired into the system.


Figure 5: Input interface










6
Output modules forms the interface
by which output field devices are
connected to the controller. PLCs
employ an optical isolator which uses
light to electrically isolate the internal
components from the input and
output terminals.

A personal computer (PC) is the
most commonly used programming
device.
The personal computer communicates
with the PLC processor via a serial or
parallel data communications link.

The computer monitor is used to
display the logic on the screen.
Figure 6: Output interface

The software allows users to create, edit, document, store and troubleshoot
programs. If the programming unit is not in use, it may be unplugged and
removed. Removing the programming unit will not affect the operation of the user
program.

PLC Operating Cycle

During each operating cycle,
the controller examines the status
of input devices, executes the user
program, and changes outputs
accordingly. The completion of one
cycle of this sequence is called a
scan. The scan time, the time
required for one full cycle,
provides a measure of the speed of
response of the PLC.

Figure 7: PLC operating cycle






7


1.5 PLC Mixer Process
Control Example

Mixer motor to automatically
stir the liquid in the tank when the
temperature and pressure reach
preset values. Alternate manual
pushbutton control of the motor to
be provided.

The temperature and pressure
sensor switches close their
respective contacts when conditions
reach their preset values.







Figure 8: Mixer process Control




Process Control Relay Ladder Diagram


Figure 9: Relay ladder diagram
8

Motor starter coil is energized when
both the pressure and temperature switches
are closed or when the manual pushbutton is
pressed.

PLC Input Module Connections

The same input field devices are used. These
devices are wired to the input module
according to the manufacturers labeling
scheme as shown in the figure on the side.














PLC Output Module Connections

Same output field device is used and wired
to the output module as shown in the figure
on the side
PLC program



where
---| |--- (Normally Open Contact)
--| / |--- (Normally Closed Contact)
---( ) (Output Coil).

9



Chapter 2: Digital Systems Review



Digital systems have been in used since the mid of last century. And since the
1980s the digital revolution have been started and affected all the industrial
aspects, one important aspect is the introduction of PLC which nothing but a
special digital computer.

This chapter covers the basics for digital systems, this is necessary to
understand subject of PLCs.

2.1 Introduction

The radix or base of a number system determines the total number of
different symbols or digits used by the system. The decimal system has a base of
10. In the decimal system, 10 unique numbers or digits ( 0 through 9) are used:
the total number of symbols is the same as the base, and the symbol with the
largest value is 1 less than the base.

The decimal system can be summarized as follows:

Ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Base: 10

Weights: 1, 10, 100, 1000, (powers of base 10)

The binary system has a base of 2. The only allowable digits are 0 and 1.
Digital Signal Waveform: with digital circuits it is easy to distinguish between two
voltage levels - +5 V and 0 V, which can be related to the binary digits 1 and 0.


Figure 1: Binary waveform

The binary system can be summarized as follows:
10

Two digits: 0, 1

Base: 2

Weights: 1, 2, 4, 8, 16, 32, (powers of base 2)







The size of the programmable
controller relates to the amount
of user program that can be
stored. The 1 K word memory
size shown can store 1,024
words, or 16,380 (1,024 x 16)
bits of information using 16-bit
words or 32,768 (1,024 x 32)
using 32 bit words.


Figure 2: PLC Processor Memory Size

Utilizing binary concept, many things can be thought of as existing in one of
two states. These two states can be defined as high or low, on or off, yes
or no, and 1 or 0.













Figure 3: Binary concept
11





2.2 Logical Gates

In this section we will presents the most common logical gates such as AND,
OR, NOT, NAND, NOR and XOR. Examples will be provided to demonstrate some
applications of these logical gates.

2.2.1 The Logical AND function










The outcome or output is called Y and the input signals are called A, B, C,
etc. Binary 1 represents the presence of a signal or the occurrence of some
event, while binary 0 represents the absence of the signal or nonoccurrence of
the event.

AND Gate Example





The AND gate operates like a series circuit.
The light will be on only when both switch
A and switch B are closed.



12



2.2.2 The Logical OR function



An OR gate can have any number of inputs but only one output. The OR gate
output is 1 if one or more inputs are 1.


OR Gate Example




The OR gate operates like a parallel circuit.
The light will be on if switch A or switch B
is closed.



2.2.3 The Logical NOT function



The NOT function has only one input and one output.
13
The NOT output is 1 if the input is 0.
The NOT output is 0 if the input is 1.
Since the output is always the reverse of the input it is called an inverter.



NOT Gate Example

Acts like a normally closed pushbutton in series
with the output.

The light will be on if the pushbutton is not
pressed.

The light will be off if the pushbutton is n
pressed.





2.2.4 The Logical NAND function



The NAND gate functions like an AND gate with an inverter connected to its
output. The only time the NAND gate output is 0 is when all inputs are binary 1.

2.2.5 The Logical NOR function



14
The NOR gate functions like an OR gate with an inverter connected to its output.
The only time the NAND gate output is 1 is when all inputs are binary 0.

2.2.6 The Logical XOR function



The XOR function has two inputs and one output. The output of this gate is
HIGH only when one input or the other is HIGH, but not both. It is commonly
used for comparison of two binary numbers.

Example: Write down the final equation for the following digital circuit


15


Chapter 3: Hard Wired versus Programmed Logic


The term hardwired logic refers to logic control functions that are determined
by the way devices are interconnected. Hardwired logic can be implemented
using relays and relay ladder schematics. Hardwired logic is fixed and it is
changeable only by altering the way devices are connected.

2.1 Hardwired Stop/Start Motor Control Circuit
Stop/start motor control circuit is one of the most used circuit in the
industry. The figure below shows a picture of the cabinet and relay ladder
schematic


Figure 1: Stop/start motor control circuit and its relay ladder schematics

The input and output field devices remain the same as those required for the
hardwired circuit. A rung is the contact symbolism required to control an output.
Each rung is a combination of input conditions connected from left to right with
the symbol that represents the output at the far right. The instructions used are
the relay equivalent of normally open (NO) and normally closed (NC) contacts and
coils

16

Figure 2: Ladder logic for stop/start motor control circuit

2.2 Examples of Hard Wired versus Programmed Logic
Example 1:















17
Example 2:



Example 3:






18
Example 4:


Example 5:







19
Example 6:


Example 7:













20
Example 8 (Interlock System):





Example 9:


21
Chapter 4: Bit Logic Instructions


Bit logic instructions work with two digits, 1 and 0. These two digits form the
base of a number system called the binary system. The two digits 1 and 0 are
called binary digits or bits. In the world of contacts and coils, a 1 indicates
activated or energized, and a 0 indicates not activated or not energized.

The bit logic instructions interpret signal states of 1 and 0 and combine them
according to Boolean logic. These combinations produce a result of 1 or 0 that is
called the result of logic operation (RLO).

The logic operations that are triggered by the bit logic instructions perform a
variety of functions.

There are bit logic instructions to perform the following functions:

1. ---| |--- Normally Open Contact (Address)
2. ---| / |--- Normally Closed Contact (Address)
3. ---( ) Output Coil
4. ---( # )--- Midline Output
5. ---|NOT|--- Invert Power Flow
6. ---(SAVE) Save RLO into BR Memory
7. XOR Bit Exclusive OR


The following instructions react to an RLO of 1:

1. ---( S ) Set Coil
2. ---( R ) Reset Coil
3. SR Set-Reset Flip Flop
4. RS Reset-Set Flip Flop

Other instructions react to a positive or negative edge transition to perform
the following functions:

1. ---(N)--- Negative RLO Edge Detection
2. ---(P)--- Positive RLO Edge Detection
3. NEG Address Negative Edge Detection
4. POS Address Positive Edge Detection

These instructions are discussed in details in the following sections.
1.1 Normally Open Contact

---| |--- (Normally Open Contact) is closed when the bit value stored at the
specified <address> is equal to "1". When the contact is closed, ladder rail power
flows across the contact and the result of logic operation (RLO) = "1".
22

Otherwise, if the signal state at the specified <address> is "0", the contact is
open. When the contact is open, power does not flow across the contact and the
result of logic operation (RLO) = "0".

When used in series, ---| |--- is linked to the RLO bit by AND logic. When
used in parallel, it is linked to the RLO by OR logic.

Example


Power flows if one of the following conditions exists:
The signal state is "1" at inputs I0.0 and I0.1
Or the signal state is "1" at input I0.2 Industrial control

1.2 Normally Closed Contact

--| / |--- (Normally Closed Contact) is closed when the bit value stored at the
specified <address> is equal to "0". When the contact is closed, ladder rail power
flows across the contact and the result of logic operation (RLO) = "1".

Otherwise, if the signal state at the specified <address> is "1", the contact is
opened. When the contact is opened, power does not flow across the contact and
the result of logic operation (RLO) = "0".

When used in series, ---| / |--- is linked to the RLO bit by AND logic. When
used in parallel, it is linked to the RLO by OR logic.

Example



Power flows if one of the following conditions exists:
The signal state is "1" at inputs I0.0 and I0.1
Or the signal state is "1" at input I0.2
23

1.3 Output Coil

---( ) (Output Coil) works like a coil in a relay logic diagram. If there is power
flow to the coil (RLO = 1), the bit at location <address> is set to "1". If there is no
power flow to the coil (RLO = 0), the bit at location <address> is set to "0". An
output coil can only be placed at the right end of a ladder rung. Multiple output
elements (max. 16) are possible (see example). A negated output can be created
by using the ---|NOT|--- (invert power flow) element.

Example

The signal state of output Q4.0 is "1" if one of the following conditions exists:
The signal state is "1" at inputs I0.0 and I0.1
Or the signal state is "0" at input I0.2.
The signal state of output Q4.1 is "1" if one of the following conditions exists:
The signal state is "1" at inputs I0.0 and I0.1
Or the signal state is "0" at input I0.2 and "1" at input I0.3

1.4 Midline Output

---( # )--- (Midline Output) is an intermediate assigning element which saves the
RLO bit (power flow status) to a specified <address>. The midline output element
saves the logical result of the preceding branch elements. In series with other
contacts, ---( # )--- is inserted like a contact. A ---( # )--- element may never be
connected to the power rail or directly after a branch connection or at the end of
a branch. A negated ---( # )--- can be created by using the ---|NOT|--- (invert
power flow) element.

Example

1.5 Output Invert Power Flow

24
--|NOT|--- (Invert Power Flow) negates the RLO bit.

Example


The signal state of output Q4.0 is "0" if one of the following conditions exists:
The signal state is "1" at input I0.0
Or the signal state is "1" at inputs I0.1 and I0.2.

1.6 Save RLO into BR Memory

---(SAVE) (Save RLO into BR Memory) saves the RLO to the BR bit of the status
word. The first check bit /FC is not reset.

Example

The status of the rung (=RLO) is saved to the BR bit.

1.7 XOR function

For the XOR function, a network of normally open and normally closed contacts
must be created as shown in the example below.

XOR (Bit Exclusive OR) creates an RLO of "1" if the signal state of the two
specified bits is different.

Example

The output Q4.0 is "1" if (I0.0 = "0" AND I0.1 = "1") OR (I0.0 = "1" AND I0.1 = "0").
25

1.8 Set Coil

---( S ) (Set Coil) is executed only if the RLO of the preceding instructions is "1"
(power flows to the coil). If the RLO is "1" the specified <address> of the element
is set to "1".
An RLO = 0 has no effect and the current state of the element's specified address
remains unchanged.

Example

The signal state of output Q4.0 is "1" if one of the following conditions exists:
The signal state is "1" at inputs I0.0 and I0.1
Or the signal state is "0" at input I0.2.
If the RLO is "0", the signal state of output Q4.0 remains unchanged.

1.9 Reset Coil

---( R ) (Reset Coil) is executed only if the RLO of the preceding instructions is "1"
(power flows to the coil). If power flows to the coil (RLO is "1"), the specified
<address> of the element is reset to "0". A RLO of "0" (no power flow to the coil)
has no effect and the state of the element's specified address remains
unchanged. The <address> may also be a timer (T no.) whose timer value is reset
to "0" or a counter (C no.) whose counter value is reset to "0".

Example


The signal state of output Q4.0 is reset to "0" if one of the following conditions
exists:
The signal state is "1" at inputs I0.0 and I0.1
Or the signal state is "0" at input I0.2.
If the RLO is "0", the signal state of output Q4.0 remains unchanged.
The signal state of timer T1 is only reset if:
26
the signal state is "1" at input I0.3.
The signal state of counter C1 is only reset if:
the signal state is "1" at input I0.4.

1.10 Set-Reset Flip Flop

SR (Set-Reset Flip Flop) is set if the signal state is "1" at the S input, and "0" at
the R input. Otherwise, if the signal state is "0" at the S input and "1" at the R
input, the flip flop is reset. If the RLO is "1" at both inputs, the order is of
primary importance. The SR flip flop executes first the set instruction then the
reset instruction at the specified <address>, so that this address remains reset
for the remainder of program scanning.

The S (Set) and R (Reset) instructions are executed only when the RLO is "1".
RLO "0" has no effect on these instructions and the address specified in the
instruction remains unchanged.


Parameter Data Type Memory Area Description
<address> BOOL I, Q, M, L, D Set or reset bit
S BOOL I, Q, M, L, D Enable set instruction
R BOOL I, Q, M, L, D Enable reset instruction
Q BOOL I, Q, M, L, D Signal state of <address>


Example


If the signal state is "1" at input I0.0 and "0" at I0.1, memory bit M0.0 is set and
output Q4.0 is "1". Otherwise, if the signal state at input I0.0 is "0" and at I0.1 is
"1", memory bit M0.0 is reset and output Q4.0 is "0". If both signal states are "0",
nothing is changed. If both signal states are "1", the reset instruction dominates
because of the order; M0.0 is reset and Q4.0 is "0".

1.11 Reset-Set Flip Flop

RS (Reset-Set Flip Flop) is reset if the signal state is "1" at the R input, and "0" at
the S input. Otherwise, if the signal state is "0" at the R input and "1" at the S
input, the flip flop is set. If the RLO is "1" at both inputs, the order is of primary
27
importance. The RS flip flop executes first the reset instruction then the set
instruction at the specified <address>, so that this address remains set for the
remainder of program scanning.

The S (Set) and R (Reset) instructions are executed only when the RLO is "1".
RLO "0" has no effect on these instructions and the address specified in the
instruction remains unchanged.



Example



If the signal state is "1" at input I0.0 and "0" at I0.1, memory bit M0.0 is set and
output Q4.0 is "0". Otherwise, if the signal state at input I0.0 is "0" and at I0.1 is
"1", memory bit M0.0 is reset and output Q4.0 is "1". If both signal states are "0",
nothing is changed. If both signal states are "1", the set instruction dominates
because of the order; M0.0 is set and Q4.0 is "1".

28

Chapter 5 Timers


This chapter introduces the subject of Timers to the reader. Timers
have an area reserved for them in the memory of your CPU. This memory
area reserves one 16-bit word for each timer address. The ladder logic
instruction set supports 256 timers.

5.1 Introduction
Bits 0 through 9 of the timer word contain the time value in binary
code. The time value specifies a number of units. Time updating
decrements the time value by one unit at an interval designated by the
time base. Decrementing continues until the time value is equal to zero.

You can pre-load a time value using either of the following formats:
W#16#wxyz
Where w = the time base (that is, the time interval or resolution)
Where xyz = the time value in binary coded decimal format
S5T#aH_bM_cS_dMS
Where H = hours, M = minutes, S = seconds, and MS = milliseconds;
a, b, c, d are defined by the user.

The time base is selected automatically, and the value is rounded to
the next lower number with that time base. The maximum time value that
you can enter is 9,990 seconds, or 2H_46M_30S.
S5TIME#4S = 4 seconds
s5t#2h_15m = 2 hours and 15 minutes
S5T#1H_12M_18S = 1 hour, 12 minutes, and 18 seconds

5.2 Time Base

Bits 12 and 13 of the timer word contain the time base in binary code.
The time base defines the interval at which the time value is decremented
by one unit. The smallest time base is 10 ms; the largest is 10 s.
Time Base Binary Code for the Time Base
10 ms 00
100 ms 01
1 s 10
10 s 11
29

Values that exceed 2h46m30s are not accepted. A value whose
resolution is too high for the range limits (for example, 2h10ms) is
truncated down to a valid resolution. The general format for S5TIME has
limits to range and resolution as shown below:
Resolution Range
0.01 second 10MS to 9S_990MS
0.1 second 100MS to 1M_39S_900MS
1 second 1S to 16M_39S
10 seconds 10S to 2H_46M_30S

5.3 Bit Configuration in the Time Cell

When a timer is started, the contents of the timer cell are used as the
time value. Bits 0 through 11 of the timer cell hold the time value in
binary coded decimal format (BCD format: each set of four bits contains
the binary code for one decimal value). Bits 12 and 13 hold the time base
in binary code.

The following figure shows the contents of the timer cell loaded with
timer value 127 and a time base of 1 second:

Each timer box provides two outputs, BI and BCD, for which you can
indicate a word location. The BI output provides the time value in binary
format. The BCD output provides the time base and the time value in
binary coded decimal (BCD) format.

5.4 Choosing the right Timer

This overview is intended to help you choose the right timer for your
timing job.

30

S_PULSE (Pulse timer): The maximum time that the output signal remains
at 1 is the same as the programmed time value t. The output signal stays
at 1 for a shorter period if the input signal changes to 0.
S_PEXT (Extended pulse timer): The output signal remains at 1 for the
programmed length of time, regardless of how long the input signal stays
at 1.
S_ODT (On-delay timer): The output signal changes to 1 only when the
programmed time has elapsed and the input signal is still 1.
S_ODTS (Retentive on-delay timer): The output signal changes from 0 to 1
only when the programmed time has elapsed, regardless of how long the
input signal stays at 1.
S_OFFDT (Off-delay timer): The output signal changes to 1 when the input
signal changes to 1 or while the timer is running. The time is started when
the input signal changes from 1 to 0.

5.5 Timers

In the subsection will discuss the five timers in details.


31
5.5.1: Pulse S5 Timer (S_PULSE)

S_PULSE (Pulse S5 Timer) as shown in the figure below starts the
specified timer if there is a positive edge at the start (S) input. A signal
change is always necessary in order to enable a timer. The timer runs as
long as the signal state at input S is "1", the longest period, however, is
the time value specified by input TV. The signal state at output Q is "1" as
long as the timer is running. If there is a change from "1" to "0" at the S
input before the time interval has elapsed the timer will be stopped. In this
case the signal state at output Q is "0".

The timer is reset when the timer reset (R) input changes from "0" to
"1" while the timer is running. The current time and the time base are also
set to zero. Logic "1" at the timer's R input has no effect if the timer is not
running.

The current time value can be scanned at the outputs BI and BCD. The
time value at BI is binary coded, at BCD it is BCD coded. The current time
value is the initial TV value minus the time elapsed since the timer was
started.

Figure 5.1: Pulse Timer

Parameter Data
Type
Memory
Area
Description
T no. Timer T Timer identification number; range
depends on CPU
S BOOL I, Q, M, L, D Start input
TV S5TIME I, Q, M, L, D Preset time value
R BOOL I, Q, M, L, D Reset input
BI WORD I, Q, M, L, D Remaining time value, integer format
BCD WORD I, Q, M, L, D Remaining time value, BCD format
Q BOOL I, Q, M, L, D Status of the timer
Table: Pulse Timer


Example

32


If the signal state of input I0.0 changes from "0" to "1" (positive edge in
RLO), the timer T5 will be started. The timer will continue to run for the
specified time of two seconds (2 s) as long as I0.0 is "1". If the signal state
of I0.0 changes from "1" to "0" before the timer has expired the timer will
be stopped. If the signal state of input I0.1 changes from "0" to "1" while
the timer is running, the time is reset.

The output Q4.0 is logic "1" as long as the timer is running and "0" if
the time has elapsed or was reset.

Pulse Timer Coil ( SP )
In addition timer can be use by using Pulse Timer Coil. ( SP ) (Pulse Timer
Coil) starts the specified timer with the <time value> when there is a
positive edge on the RLO state. The timer continues to run for the
specified time interval as long as the RLO remains positive ("1"). The signal
state of the counter is 1 as long as the timer is running. If there is a
change from "1" to "0" in the RLO before the time value has elapsed, the
timer will stop. In this case, a scan for "1" always produces the result "0".

Example:



If the signal state of input I0.0 changes from "0" to "1" (positive edge in
RLO), the timer T5 is started. The timer continues to run with the
specified time of two seconds as long as the signal state of input I0.0 is
"1". If the signal state of input I0.0 changes from "1" to "0" before the
specified time has elapsed, the timer stops.

33
The signal state of output Q4.0 is "1" as long as the timer is running. A
signal state change from "0" to "1" at input I0.1 will reset timer T5 which
stops the timer and clears the remaining portion of the time value to "0".

5.5.2: Extended Pulse S5 Timer ( S_PEXT)

S_PEXT (Extended Pulse S5 Timer) starts the specified timer if there is a positive
edge at the start (S) input. A signal change is always necessary in order to enable
a timer. The timer runs for the preset time interval specified at input TV even if
the signal state at the S input changes to "0" before the time interval has elapsed.
The signal state at output Q is "1" as long as the timer is running. The timer will
be restarted ("re-triggered") with the preset time value if the signal state at input
S changes from "0" to "1" while the timer is running.

The timer is reset if the reset (R) input changes from "0" to "1" while the timer is
running. The current time and the time base are set to zero.

The current time value can be scanned at the outputs BI and BCD. The time
value at BI is binary coded, at BCD is BCD coded. The current time value is the
initial TV value minus the time elapsed since the timer was started.



Parameter Data
Type
Memory
Area
Description
T no. Timer T Timer identification number; range
depends on CPU
S BOOL I, Q, M, L, D Start input
TV S5TIME I, Q, M, L, D Preset time value
R BOOL I, Q, M, L, D Reset input
BI WORD I, Q, M, L, D Remaining time value, integer format
BCD WORD I, Q, M, L, D Remaining time value, BCD format
Q BOOL I, Q, M, L, D Status of the timer

Example


34

If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the
timer T5 will be started. The timer will continue to run for the specified time of
two seconds (2 s) without being affected by a negative edge at input S. If the
signal state of I0.0 changes from "0" to "1" before the timer has expired the timer
will be re-triggered. The output Q4.0 is logic "1" as long as the timer is running.



Extended Pulse Timer Coil ( SE )

( SE ) (Extended Pulse Timer Coil) starts the specified timer with the specified
<time value> when there is a positive edge on the RLO state. The timer continues
to run for the specified time interval even if the RLO changes to "0" before the
timer has expired. The signal state of the counter is 1 as long as the timer is
running. The timer will be restarted (re-triggered) with the specified time value if
the RLO changes from "0" to "1" while the timer is running.

Example

If the signal state of input I0.0 changes from "0" to "1"
(positive edge in RLO), the timer T5 is started. The
timer continues to run without regard to a negative
edge of the RLO. If the signal state of I0.0 changes from
"0" to "1" before the timer has expired, the timer is re-
triggered.

The signal state of output Q4.0 is "1" as long as the
timer is running. A signal state change from "0" to "1"
at input I0.1 will reset timer T5 which stops the timer
and clears the remaining portion of the time value to
"0".



5.5.3: On-Delay S5 Timer (S_ S_ODT)

S_ODT (On-Delay S5 Timer) starts the specified timer if there is a positive
edge at the start (S) input. A signal change is always necessary in order to
enable a timer. The timer runs for the time interval specified at input TV
as long as the signal state at input S is positive. The signal state at output
Q is "1" when the timer has elapsed without error and the signal state at
the S input is still "1". When the signal state at input S changes from "1"
to "0" while the timer is running, the timer is stopped. In this case the
signal state of output Q is "0".

35


The timer is reset if the reset (R) input changes from "0" to "1" while the
timer is running. The current time and the time base are set to zero. The
signal state at output Q is then "0". The timer is also reset if there is a
logic "1" at the R input while the timer is not running and the RLO at
input S is "1".

The current time value can be scanned at the outputs BI and BCD. The
time value at BI is binary coded, at BCD is BCD coded. The current time
value is the initial TV value minus the time elapsed since the timer was
started.

Example



If the signal state of I0.0 changes from "0" to "1" (positive edge in RLO), the
timer T5 will be started. If the time of two seconds elapses and the signal
state at input I0.0 is still "1", the output Q4.0 will be "1". If the signal state
of I0.0 changes from "1" to "0", the timer is stopped and Q4.0 will be "0" (if
the signal state of I0.1 changes from "0" to "1", the time is reset regardless
of whether the timer is running or not).

On Delay Timer Coil (SD)

On Delay Timer Coil (SD) starts the specified timer with the <time value> if
there is a positive edge on the RLO state. The signal state of the timer is
"1" when the <time value> has elapsed without error and the RLO is still
"1". When the RLO changes from "1" to "0" while the timer is running, the
timer is reset. In this case, a scan for "1" always produces the result "0".
Example


36


If the signal state of input I0.0 changes from "0" to "1" (positive edge in
RLO), the timer T5 is started. If the time elapses and the signal state of
input I0.0 is still "1", the signal state of output Q4.0 will be "1".

If the signal state of input I0.0 changes from "1" to "0", the timer remains
idle and the signal state of output Q4.0 will be "0". A signal state change
from "0" to "1" at input I0.1 will reset timer T5 which stops the timer and
clears the remaining portion of the time value to "0".

5.5.4: Retentive On Delay S5 Timer (S_ODTS)

S_ODTS (Retentive On-Delay S5 Timer) starts the specified timer if there is a
positive edge at the start (S) input. A signal change is always necessary in order
to enable a timer. The timer runs for the time interval specified at input TV even
if the signal state at input S changes to "0" before the time interval has elapsed.
The signal state at output Q is "1" when the timer has elapsed without regard to
the signal state at input S. The timer will be restarted (re-triggered) with the
specified time if the signal state at input S changes from "0" to "1" while the timer
is running.



The timer is reset if the reset (R) input changes from "0" to "1" without regard to
the RLO at the S input. The signal state at output Q is then "0".

37
The current time value can be scanned at the outputs BI and BCD. The time
value at BI is binary coded, at BCD it is BCD coded. The current time value is
the initial TV value minus the time elapsed since the timer was started.

Example



If the signal state of I0.0 changes from "0" to "1" (positive edge in RLO), the timer
T5 will be started. The timer runs without regard to a signal change at I0.0 from
"1" to "0". If the signal state at I0.0 changes from "0" to "1" before the timer has
expired, the timer will be re-triggered. The output Q4.0 will be "1" if the timer
elapsed. (If the signal state of input I0.1 changes from "0" to "1", the time will be
reset irrespective of the RLO at S.)

Retentive On-Delay Timer Coil (SS)
Retentive On-Delay Timer Coil (SS) starts the specified timer if there is a positive
edge on the RLO state. The signal state of the timer is "1" if the time value has
elapsed. A restart of the timer is only possible if it is reset explicitly. Only a reset
causes the signal state of the timer to be set to "0".

The timer restarts with the specified time value if the RLO changes from "0" to "1"
while the timer is running.

Example




If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the
timer T5 is started. If the signal state of input I0.0 changes from "0" to "1" before
the timer has expired, the timer is re-triggered. The output Q4.0 will be "1" if the
38
timer elapsed. A signal state "1" at input I0.1 will reset timer T5, which stops the
timer and clears the remaining portion of the time value to "0".

5.5.5: Retentive On-Delay S5 Timer (S_ODTS)

S_OFFDT (Off-Delay S5 Timer) starts the specified timer if there is a negative
edge at the start (S) input. A signal change is always necessary in order to enable
a timer. The signal state at output Q is "1" if the signal state at the S input is "1"
or while the timer is running. The timer is reset when the signal state at input S
goes from "0" to "1" while the timer is running. The timer is not restarted until
the signal state at input S changes again from "1" to "0".


The timer is reset when the reset (R) input changes from "0" to "1" while the timer
is running.

The current time value can be scanned at the outputs BI and BCD. The time
value at BI is binary coded, at BCD it is BCD coded. The current time value is
the initial TV value minus the time elapsed since the timer was started.

Example




If the signal state of I0.0 changes from "1" to "0", the timer is started.

Q4.0 is "1" when I0.0 is "1" or the timer is running. (if the signal state at I0.1
changes from "0" to "1" while the time is running, the timer is reset).

Off-Delay Timer Coil (SF)

Off-Delay Timer Coil (SF) starts the specified timer if there is a negative edge on
the RLO state. The timer is "1" when the RLO is "1" or as long as the timer is
running during the <time value> interval. The timer is reset when the RLO goes
39
from "0" to "1" while the timer is running. The timer is always restarted when the
RLO changes from "1" to "0".

Example


If the signal state of input I0.0 changes from "1" to "0" the timer is started.

The signal state of output Q4.0 is "1" when input I0.0 is "1" or the timer is
running. A signal state change from "0" to "1" at input I0.1 will reset timer T5
which stops the timer and clears the remaining portion of the time value to "0".





Example 5.1:

Mixing tank is used prepare a medicine of two ingredients as follows:
1. The first pump will be turn from start/stop station to sump the first
ingredient and will stay on until the medium level switch is reached.
2. Immediately a second pump is turned on until high level is reached.
3. A mixer is turned on for 32 seconds.
4. Then the liquid is dumped until a low level switch.
Write a PLC code to represent this process.
40

Chapter 6: Counters


Counters have an area reserved for them in the memory of your CPU. This
memory area reserves one 16-bit word for each counter address. The ladder logic
instruction set supports 256 counters. The counter instructions are the only
functions that have access to the counter memory area.

Bits 0 through 9 of the counter word contain the count value in binary code. The
count value is moved to the counter word when a counter is set. The range of the
count value is 0 to 999.

Bit Configuration in the Counter is shown in the figure below. You provide a
counter with a preset value by entering a number from 0 to 999, for example
127, in the following format: C#127. The C# stands for binary coded decimal
format (BCD format: each set of four bits contains the binary code for one
decimal value).

Bits 0 through 11 of the counter contain the count value in binary coded decimal
format. The following figure shows the contents of the counter after you have
loaded the count value 127, and the contents of the counter cell after the counter
has been set.


There are three types of counters as follows
1. Up-Down Counter (S_CUD)
2. Down Counter (S_CD)
3. Up Counter (S_CU)
These types are discussed in details in the next three sections.
41
6.1: Up-Down Counter

A positive edge (i.e. a change in signal state from 0 to 1) at input S of the Up-
Down Counter instruction sets the counter with the value at the Preset Value
(PV) input.

A signal state of 1 at input R resets the counter. Resetting the counter places
the value of the count at 0. The counter is incremented by 1 if the signal state at
input CU changes from 0 to 1 (that is, there is a positive edge) and the value of
the counter is less than 999.

The counter is decremented by 1 if the signal state at input CD changes from
0 to 1 (that is, there is a positive edge) and the value of the counter is more than
0. If there is a positive edge at both count inputs, both operations are executed
and the count remains the same.

A signal state check for 1 at output Q produces a result of 1 when the count
is greater than 0; the check produces a result of 0 when the count is equal to 0.
The range of the count value is 0 to 999. You can vary the count value within
this range by using the Up-Down Counter, Up Counter, and Down Counter
instructions.

You provide a counter with a preset value by entering a number from 0 to
999, for example 127, in the following format:C#127.



Example:

42

A change in signal state from 0 to 1 at input I
0.2 sets counter C 10 with the value 55 in
binary coded decimal format.

If the signal state of input I 0.0 changes from 0
to 1, the value of counter C 10 is increased by 1,
except when the value of counter C 10 is equal
to 999.

If input I 0.1 changes from 0 to 1, counter C 10
is decreased by 1, except when the value of
counter C 10 is equal to 0.

If I 0.3 changes from 0 to 1, the value of C 10 is
set to 0. Q 4.0 is 1, when C 10 is not equal to
0.

Set Counter Value (SC)
Set Counter Value (SC) executes only if there is a positive edge in RLO. At that
time, the preset value transferred into the specified counter.

Example



The counter C5 is preset with the value of 100 if there is a positive edge at input
I0.0 (change from "0" to "1"). If there is no positive edge, the value of counter C5
remains unchanged.6.2:

6.2: Up Counter

The up-counter parameters are described in the table below.
43

Example:


A change in signal state from 0 to 1 at input I 0.2
sets counter C 10 with the value 901 in binary
coded decimal format.

If the signal state of I 0.0 changes from 0 to 1,
the value of counter C 10 is
increased by 1, unless the value of C 10 is equal
to 999.

If I 0.3 changes from 0 to 1, the value of C 10 is
set to 0. The signal state of output Q 4.0 is 1 if C
10 is not equal to 0.

Up Counter Coil (CU)
Up Counter Coil (CU) increments the value of the specified counter by one if
there is a positive edge in the RLO and the value of the counter is less than
"999". If there is no positive edge in the RLO or the counter already has the value
"999", the value of the counter will be unchanged.

Example



44
If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the
preset value of 100 is loaded to counter C10.

If the signal state of input I0.1 changes from "0" to "1" (positive edge in RLO),
counter C10 count value will be incremented by one unless the value of C10 is
equal to "999". If there is no positive edge in RLO, the value of C10 will be
unchanged.

If the signal state of I0.2 is "1", the counter C10 is reset to "0".

6.3: Down Counter

The down-counter parameters are described in the table below.



Example:


A change in signal state from 0 to 1 at input I
0.2 sets counter C 10 with the value 901 in
binary coded decimal format.

If the signal state of I 0.0 changes from 0 to 1,
the value of counter C 10 is
increased by 1, unless the value of C 10 is equal
to 999.

If I 0.3 changes from 0 to 1, the value of C 10 is
set to 0. The signal state of output Q 4.0 is 1 if C
10 is not equal to 0.

Off-Delay Timer Coil (SF)

-( CD ) (Down Counter Coil) decrements the value of the specified counter by one,
if there is a positive edge in the RLO state and the value of the counter is more
45
than "0". If there is no positive edge in the RLO or the counter has already the
value "0", the value of the counter will be unchanged.

Example



If the signal state of input I0.0 changes from "0" to "1" (positive edge in RLO), the
preset value of 100 is loaded to counter C10.

If the signal state of input I0.1 changes from "0" to "1" (positive edge in RLO),
counter C10 count value will be decremented by one unless the value of C10 is
equal to "0". If there is no positive edge in RLO, the value of C10 will be
unchanged.

If the count value = 0, then Q4.0 is turned on. If the signal state of input I0.2 is
"1", the counter C10 is reset to "0".


Example: Count starting from zero when I1.0 start is pressed and I1.2 is
energized.




46
Chapter 7: Data Types


7.1 Overview of the Data Types

A data type is the combination of value ranges and operations in a single unit.
The data types decide:
the type and interpretation of the data elements,
the permitted ranges for the data elements,
the permitted operations that can be executed on an address of a data type
the notation of the constants of the data type.

Elementary Data Types

Elementary data types define the structure of data elements that cannot be
subdivided into smaller units. They correspond to the definition in the DIN EN
1131-3 standard. An elementary data type describes a memory area with a
fixed length and stands for bit, integer, real, time period, time-of-day and
character values. The following data types are predefined in S7.

Group Data Types Explanation
Bit Data Types BOOL
BYTE
WORD
DWORD
Date elements of this type occupy either 1
bit, 8 bits, 16 bits or 32 bits

Character Types CHAR Data elements of this type occupy exactly
1 character in the ASCII character set
Numeric Types INT
DINT
REAL
Data elements of this type are available
for processing numeric values.
Time Types TIME
DATE
TIME_OF_DAY
S5TIME
Data elements of this type represent the
various time and date values in STEP 7.










Complex Data Types

S7 supports the following complex data types:
47

Data Type Explanation
DATE_AND_TIME
DT
Defines an area of 64 bits (8 bytes). This data type stores
date and time (as a binary coded decimal) and is a
predefined data type in S7.
STRING Defines an area for a character string of up to 254
characters (data type CHAR).
ARRAY Defines an array consisting of elements of one data type
(either elementary or complex).
STRUCT Defines a group of data types in any combination of
types. It can be an array of structures or a structure
consisting of structures and arrays.

User-Defined Data Types
You can create your own user-defined data types in the data type declaration.
Each one is assigned a unique name and can be used any number of times. Once
it has been defined, a user-defined data type can be used to generate a number
of data blocks with the same structure.

Parameter Types

Parameter types are special data types for timers, counters and blocks that can
be used as formal parameters.

Data Type Explanation
TIMER This is used to declare timer functions as parameters.
COUNTER This is used to declare counter functions as parameters.
BLOCK_xx This is used to declare FCs, FBs, DBs and SDBs as
parameters.
ANY This is used to allow an address of any data type as a
parameter.
POINTER This is used to allow a memory area as a parameter.

ANY Data Type

In S7, you can use variables of the ANY data type as formal parameters of a
block. You can also create temporary variables of this type and use them in value
assignments.

7.2 Elementary Data Types

Bit Data Types

Data of this type are bit combinations occupying either 1 bit (data type BOOL), 8
bits, 16 bits or 32 bits. A numeric range of values cannot be specified for the
data types: byte, word, and double word. These are bit combinations that can be
used only to formulate Boolean expressions.


48
Type Keyword Bit Width Alignment Value Range
Bit BOOL 1 bit Begins at the least
significant bit in the byte
0, 1 or FALSE,
TRUE
Byte BYTE 8 8 bits Begins at the least
significant byte in the
word.
-
Word WORD 16 bits Begins at a WORD
boundary.
-
Double
word
DWORD 32 bits Begins at a WORD
boundary.
-

Character Types

Data elements of this type occupy exactly one character of the ASCII character
set.

Type Keyword Bit Width Value Range

Single character CHAR 8 Extended ASCII character set















Numeric Data Types
These types are available for processing numeric values (for example for
calculating arithmetic expressions).

Type Keyword Bit Width Alignment Value Range
Integer INT 16 Begins at a WORD
boundary.

-32_768 to 32_767

Double
integer
DINT 32 Begins at a WORD
boundary.
-2_147_483_648 to
2_147_483_647
Floating-
point
number
(IEEE
floating-
REAL 32 Begins at a WORD
boundary.

-3.402822E+38 to -1.175495E-38
+/- 0
1.175495E-38 to 3.402822E+38

49
point
number)

Time Types

Data of this type represent the various time and date values within STEP 7 (for
for setting the date or for entering the time value for a time).

Type Keyword Bit
Width
Alignment Value Range

S5 time S5TIME
S5T
16 Begins at a
WORD
boundary.
T#0H_0M_0S_10MS to
T#2H_46M_30S_0MS
Time period:
IEC time in
steps of
1 ms.
TIME
T

32 Begins at a
WORD
boundary.

-T#24D_20H_31M_23S_647MS
to
T#24D_20H_31M_23S_647MS

Date
IEC data in
steps of
1 day
DATE
D

16 Begins at a
WORD
boundary.

D#1990-01-01 to
D#2168-12-31

Time of day
time in steps
of 1
ms.
TIME_OF_DAY
TOD
32 Begins at a
WORD
boundary.

TOD#0:0:0.0 to
TOD#23:59:59.999



If the set value is higher than the upper limit of the range, the upper limit value
is used.
With variables of the data type S5TIME, the resolution is limited, in other words,
only the time bases 0.01 s, 0.1 s, 1 s, 10 s are available. The compiler rounds the
values accordingly. If the set value is higher than the upper limit of the range,
the upper limit value is used.




50
Chapter 8: More PLC Instructions


8.1 Overview of All Ladder Instructions

All Ladder Instructions are sorted according to Siemens International
Mnemonics in the table below. Quite many instructions were discussed in earlier
chapters. However, in the following sections we shall discuss samples of the rest
of instruction that were not addressed earlier.


English
Mnemonics
Program Elements
Catalog
Description

---| |--- Bit logic Instruction Normally Open Contact (Address)
---|/|--- Bit logic Instruction Normally Closed Contact (Address)
---( ) Bit logic Instruction Output Coil
---(#) Bit logic Instruction Midline Output
==0 ---| |--- Status bits Result Bit Equal 0
>0 ---| |--- Status bits Result Bit Greater Than 0
>=0 ---| |--- Status bits Result Bit Greater Equal 0
<=0 ---| |--- Status bits Result Bit Less Equal 0
<0 ---| |--- Status bits Result Bit Less Than 0
<>0 ---| |--- Status bits Result Bit Not Equal 0
ABS Floating point ABS Instruction Establish the Absolute
Value of a Floating-Point Number
ACOS Floating point Instruction Establish the Arc Cosine
Value
ADD_DI Integer Math
Instruction
Add Double Integer
ADD_I Integer Math
Instruction
Add Integer
ADD_R Floating point
Instruction
Add Real
ASIN Floating point
Instruction
Establish the Arc Sine Value

ATAN Floating point
Instruction
Establish the Arc Tangent Value

BCD_DI Convert BCD to Double Integer
BCD_I Convert BCD to Integer
BR ---| |--- Status bits Exception Bit Binary Result
----(CALL) Program control Call FC SFC from Coil (without
Parameters)
CALL_FB Program control Call FB from Box
CALL_FC Program control Call FC from Box
51
English
Mnemonics
Program Elements
Catalog
Description

CALL_SFB Program control Call System FB from Box
CALL_SFC Program control Call System FC from Box
----(CD) Counters Down Counter Coil
CEIL Convert Ceiling
CMP >=D Compare Compare Double Integer
(==, <>, >, <, >=, <=)
CMP >=I Compare Compare Integer (==, <>, >, <, >=, <=)
CMP >=R Compare Compare Real (==, <>, >, <, >=, <=)
COS Floating point Instruction Establish the Cosine Value
----(CU) Counters Up Counter Coil
DI_BCD Convert Double Integer to BCD
DI_R Convert Double Integer to Floating-Point
DIV_DI Integer Math Instruction Divide Double Integer
DIV_I Integer Math Instruction Divide Integer
DIV_R Floating point Instruction Divide Real
EXP Floating point
Instruction
Establish the Exponential Value
FLOOR Convert Floor
I_BCD Convert Integer to BCD
I_DI Convert Integer to Double Integer
INV_I Convert Ones Complement Integer
INV_DI Convert Ones Complement Double Integer
---(JMP) Jumps Unconditional Jump
---(JMP) Jumps Conditional Jump
---(JMPN) Jumps Jump-If-Not
LABEL Jumps Label
LN Floating point Instruction Establish the Natural
Logarithm
---(MCR>) Program control Master Control Relay Off
---(MCR<) Program control Master Control Relay On
---(MCRA) Prgram control Master Control Relay Activate
---(MCRD) Program control Master Control Relay Deactivate
MOD_DI Integer Math
Instruction
Return Fraction Double Integer
MOVE Move Assign a Value
MUL_DI Integer Math
Instruction
Multiply Double Integer
MUL_I Integer Math
Instruction
Multiply Integer
MUL_R Floating point
Instruction
Multiply Real
---( N )--- Bit logic Instruction Negative RLO Edge Detection
NEG Bit logic Instruction Address Negative Edge Detection
NEG_DI Convert Twos Complement Double Integer
NEG_I Convert Twos Complement Integer
NEG_R Convert Negate Floating-Point Number
52
English
Mnemonics
Program Elements
Catalog
Description

---| NOT |--- Bit logic Instruction Invert Power Flow
---( OPN ) DB call Open Data Block: DB or DI
OS ---| |--- Status bits Exception Bit Overflow Stored
OV ---| |--- Status bits Exception Bit Overflow
---( P )--- Bit logic Instruction Positive RLO Edge Detection
POS Bit logic Instruction Address Positive Edge Detection
---( R ) Bit logic Instruction Program control Return
ROL_DW Shift/Rotate Rotate Left Double Word
ROR_DW Shift/Rotate Rotate Right Double Word
ROUND Convert Round to Double Integer
RS Bit logic Instruction Reset-Set Flip Flop
---( S ) Bit logic Instruction Set Coil
---( SAVE ) Bit logic Instruction Save RLO into BR Memory
---( SC ) Counters Set Counter Value
S_CD Counters Down Counter
S_CU Counters Up Counter
S_CUD Counters Up-Down Counter
---( SD ) Timers On-Delay Timer Coil
---( SE ) Timers Extended Pulse Timer Coil
---( SF ) Timers Off-Delay Timer Coil
SHL_DW Shift/Rotate Shift Left Double Word
SHL_W Shift/Rotate Shift Left Word
SHR_DI Shift/Rotate Shift Right Double Integer
SHR_DW Shift/Rotate Shift Right Double Word
SHR_I Shift/Rotate Shift Right Integer
SHR_W Shift/Rotate Shift Right Word
SIN Floating point
Instruction
Establish the Sine Value
S_ODT Timers On-Delay S5 Timer
S_ODTS Timers Retentive On-Delay S5 Timer
S_OFFDT Timers Off-Delay S5 Timer
---( SP ) Timers Pulse Timer Coil
S_PEXT Timers Extended Pulse S5 Timer
S_PULSE Timers Pulse S5 Timer
SQR Floating point
Instruction
Establish the Square
SQRT Floating point
Instruction
Establish the Square Root
SR Bit logic Instruction Set-Reset Flip Flop
---( SS ) Timers Retentive On-Delay Timer Coil
SUB_DI Integer Math
Instruction
Subtract Double Integer

SUB_I Integer Math
Instruction
Subtract Integer
SUB_R Floating point
Instruction
Subtract Real
53
English
Mnemonics
Program Elements
Catalog
Description

TAN Floating point
Instruction
Establish the Tangent Value
TRUNC Convert Truncate Double Integer Part
UO ---| |--- Status bits Exception Bit Unordered
WAND_DW Word logic
Instruction
AND Double Word
WAND_W Word logic
Instruction
AND Word
WOR_DW Word logic
Instruction
OR Double Word
WOR_W WOR_W OR Word
WXOR_DW Word logic
Instruction
Exclusive OR Double Word
WXOR_W Word logic
Instruction
Exclusive OR Word



8.2 Add double integer instruction (ADD_DI)

The block diagram for the ADD_DI is shown in the figure below



The inputs and outputs are described in the table below.

Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN1 DINT I, Q, M, L, D
or constant
First value for addition
IN2 DINT I, Q, M, L, D
or constant
Second value for addition
OUT DINT I, Q, M, L, D Result of addition

ADD_DI (Add Double Integer) is activated by a logic "1" at the Enable (EN)
Input. IN1 and IN2 are added and the result can be scanned at OUT. If the result
is outside the permissible range for a double integer (32-bit), the OV bit and OS
bit will be "1" and ENO is logic "0", so that other functions after this math box
which are connected by the ENO (cascade arrangement) are not executed.




54
Example:


The ADD_DI box is activated if I0.0 = "1". The result of the addition MD0 + MD4
is output to MD10. If the result was outside the permissible range for a double
integer, the output Q4.0 is set.

8.3 Compare integer instruction

The block diagrams for different Compare Integer instructions are shown in the
figure below



The inputs and outputs are described in the table below.


IN1 INT I, Q, M, L, D
or constant
IN2 INT I, Q, M, L, D
or constant
Parameter Data Type Memory Area Description
box input BOOL I, Q, M, L, D Result of the previous logic operation
box output BOOL I, Q, M, L, D Result of the comparison, is only
processed further if the RLO at the
box input = 1
IN1 INT I, Q, M, L, D
or constant
First value to compare
IN2 INT I, Q, M, L, D
or constant
Second value to compare

IN1 and IN2 are compared according to the type of comparison you choose:

== IN1 is equal to IN2
<> IN1 is not equal to IN2
> IN1 is greater than IN2
< IN1 is less than IN2
55
>= IN1 is greater than or equal to IN2
<= IN1 is less than or equal to IN2
If the comparison is true, the RLO of the function is "1". It is linked to the RLO of
a rung network by AND if the compare element is used in series, or by OR if the
box is used in parallel.

Example:



Output Q4.0 is set if the following conditions exist:
There is a signal state of "1" at inputs I0.0 and at I0.1
AND MW0 >= MW2

8.4 Shift right integer instruction

The block diagram for the Shift Right Double Integer instruction is shown in the
figure below



The inputs and outputs are described in the table below.

Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN DINT I, Q, M, L, D Value to shift
N WORD I, Q, M, L, D Number of bit positions to shift
OUT DINT I, Q, M, L, D Result of shift instruction

SHR_DI (Shift Right Double Integer) is activated by a logic "1" at the Enable
(EN) Input. The SHR_DI instruction is used to shift bits 0 to 31 of input IN bit by
bit to the right. The input N specifies the number of bits by which to shift. If N is
larger than 32, the command acts as if N were equal to 32. The bit positions
shifted in from the left to fill vacated bit positions are assigned the logic state of
bit 31 (sign bit for the double integer). This means these bit positions are
assigned "0" if the integer is positive and "1" if the integer is negative. The result
of the shift instruction can be scanned at output OUT. The CC 0 bit and the OV
bit are set to "0" by SHR_DI if N is not equal to 0.
ENO has the same signal state as EN.

Example:

56

The SHR_DI box is activated by logic "1" at I0.0. MD0 is loaded and shifted right
by the number of bits specified with MW4. The result is written to MD10. Q4.0 is
set. 8.5 Subtract real instruction

8.5 SQRT Square Root Instruction

The block diagram for the SQRT instruction is shown in the figure below




The inputs and outputs are described in the table below.

OUT REAL I, Q, M, L, D
Description


Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN REAL I, Q, M, L, D
or constant
Input value: floating-point
OUT REAL I, Q, M, L, D Output value: square root
of floating-point number

SQRT establishes the square root of a floating-point number. This instruction
issues a positive result when the address is greater than "0". Sole exception: the
square root of -0 is -0.

8.6 Subtract Real (SUB_R)

The block diagram for the Subtract Real is shown in the figure below


The inputs and outputs are described in the table below.

57

Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN1 REAL I, Q, M, L, D
or constant
First value for subtraction
IN2 REAL I, Q, M, L, D
or constant
Value to subtract
OUT REAL I, Q, M, L, D Result of subtraction

SUB_R (Subtract Real) is activated by a logic "1" at the Enable (EN) Input. IN2
is subtracted from IN1 and the result can be scanned at OUT. If the result is
outside the permissible range for a floating-point number (overflow or underflow),
the OV bit and OS bit will be "1" and ENO is logic "0", so that other functions
after this math box which are connected by the ENO (cascade arrangement) are
not executed.

Example:


The SUB_R box is activated by logic "1" at I0.0. The result of the subtraction
MD0 - MD4 is output to MD10. If the result was outside the permissible range
for a floating-point number or if the program statement was not processed, the
output Q4.0 is set.

8.7 WAND_W (Word) AND Word

The block diagram for the WAND_W (Word) AND Word is shown in the figure
below.



The inputs and outputs are described in the table below.

Parameter Data Type Memory Area Description
EN BOOL I, Q, M, L, D Enable input
ENO BOOL I, Q, M, L, D Enable output
IN1 WORD I, Q, M, L, D First value for logic operation
IN2 WORD I, Q, M, L, D Second value for logic operation
OUT WORD I, Q, M, L, D Result word of logic operation

58

WAND_W (AND Words) is activated by signal state "1" at the enable (EN) input
and ANDs the two word values present at IN1 and IN2 bit by bit. The values are
interpreted as pure bit patterns. The result can be scanned at the output OUT.
ENO has the same logic state as EN.

Example:



The instruction is executed if I0.0 is "1". Only bits 0 to 3 of MW0 are relevant, the
rest of MW0 is masked by the IN2 word bit pattern:

MW0 = 01010101 01010101
IN2 = 00000000 00001111
MW0 AND IN2 = MW2 = 00000000 00000101
Q4.0 is "1" if the instruction is executed.



59
Chapter 9: Computer Numerical Control (CNC)

The abbreviation CNC stands for computer numerical control, and refers
specifically to a computer "controller" that reads G-code instructions and drives a
machine tool, a powered mechanical device typically used to fabricate
components by the selective removal of material. CNC does numerically directed
interpolation of a cutting tool in the work envelope of a machine. The operating
parameters of the CNC can be altered via software load program. A picture of
basic CNC machine is shown below



Figure 1: A miniature mill showing the basic parts of a mill.


9.1 Introduction

60
While most people never heard of this term, CNC has touched almost every
form of manufacturing process in one way or another. If you are working in
manufacturing, it's likely that you are dealing with CNC on a regular basis.

CNC machines typically replace some existing manufacturing processes. Take
one of the simplest manufacturing processes, drilling holes, for example. A drill
press can of course be used to machine holes. (It's likely that almost everyone
has seen some form of drill press, even if you don't work in manufacturing.) A
person can place a drill in the drill chuck that is secured in the spindle of the
drill press. They can then (manually) select the desired speed for rotation
(commonly by switching belt pulleys), and activate the spindle. Then they
manually pull on the quill lever to drive the drill into the workpiece being
machined.

As you can easily see, there is a lot of manual intervention required to use a
drill press to drill holes. A person is required to do something almost every step
along the way. While this manual intervention may be acceptable for
manufacturing companies if but a small number of holes or workpieces must be
machined, as quantities grow, so does the likelihood for fatigue due to the
tediousness of the operation. And do note that we've used one of the simplest
machining operations (drilling) for our example. There are more complicated
machining operations that would require a much higher skill level (and increase
the potential for mistakes resulting in scrap workpieces) of the person running
the conventional machine tool. (We commonly refer to the style of machine that
CNC is replacing as the conventional machine). The figure shows a picture of a
typical CNC machine.



Figure 2: Typical CNC machine.
By comparison, the CNC equivalent for a drill press (possibly a CNC
machining center or CNC drilling & tapping center) can be programmed to
perform this operation in a much more automatic fashion. Everything that the
drill press operator was doing manually will now be done by the CNC machine,
61
including: placing the drill in the spindle, activating the spindle, positioning the
workpiece under the drill, machining the hole, and turning off the spindle.

Everyone involved in the manufacturing environment should be well aware of
what is possible with these sophisticated machine tools. The design engineer, for
example, must possess enough knowledge of CNC to perfect dimensioning and
tolerancing techniques for workpieces to be machined on CNC machines. The
tool engineer must understand CNC in order to design fixtures and cutting tools
for use with CNC machines. Quality control people should understand the CNC
machine tools used within their company in order to plan quality control and
statistical process control accordingly. Production control personnel should be
abreast of their company's CNC technology in order to make realistic production
schedules. Managers, foremen, and team leaders should understand CNC well
enough to communicate intelligently with fellow workers. And, it goes without
saying that CNC programmers, setup people, operators, and others working
directly with the CNC equipment must have an extremely good understanding of
CNC.

In this chapter, we will explore the basics of CNC, showing you much of what
is involved with using these sophisticated machine tools. At the completion of
this chapter, you should have a good understanding of how and why CNC
functions as it does and know those things you must learn more about in order
to work with any style of CNC machine tool. Furthermore, you should be quite
comfortable with the fundamentals of CNC and be able to communicate
intelligently with others about your CNC machine tools.

9.2 Fundamentals of CNC

While the specific intention and application for CNC machines vary from one
machine type to another, all forms of CNC have common benefits. It helps to
understand why these sophisticated machines have become so popular. Here are
but a few of the more important benefits offered by CNC equipment.

The first benefit offered by all forms of CNC machine tools is improved
automation. The operator intervention related to producing workpieces can be
reduced or eliminated. Many CNC machines can run unattended during their
entire machining cycle, freeing the operator to do other tasks. This gives the CNC
user several side benefits including reduced operator fatigue, fewer mistakes
caused by human error, and consistent and predictable machining time for each
workpiece. Since the machine will be running under program control, the skill
level required of the CNC operator (related to basic machining practice) is also
reduced as compared to a machinist producing workpieces with conventional
machine tools.

The second major benefit of CNC technology is consistent and accurate
workpieces. Today's CNC machines show almost unbelievable accuracy and
repeatability specifications. This means that once a program is verified, two, ten,
or one thousand identical workpieces can be easily produced with precision and
consistency.
62

A third benefit offered by most forms of CNC machine tools is flexibility. Since
these machines are run from programs, running a different workpiece is almost
as easy as loading a different program. Once a program has been verified and
executed for one production run, it can be easily recalled the next time the
workpiece is to be run. This leads to yet another benefit, fast change-overs. Since
these machines are very easy to setup and run, and since programs can be easily
loaded, they allow very short setup time.

9.3 Motion control - the heart of CNC

The most basic function of any CNC machine is automatic, precise, and
consistent motion control. Rather than applying completely mechanical devices
to cause motion as is required on most conventional machine tools, CNC
machines allow motion control in a revolutionary manner. All forms of CNC
equipment have two or more directions of motion, called axes. These axes can be
precisely and automatically positioned along their lengths of travel. The two most
common axis types are linear (driven along a straight path) and rotary (driven
along a circular path).

Instead of causing motion by turning cranks and handwheels as is required
on conventional machine tools, CNC machines allow motions to be commanded
through programmed commands. Generally speaking, the motion type (rapid,
linear, and circular), the axes to move, the amount of motion and the motion rate
(feedrate) are programmable with almost all CNC machine tools.

Accurate positioning is accomplished by the operator counting the number of
revolutions made on the handwheel plus the graduations on the dial. The drive
motor is rotated a corresponding amount, which in turn drives the ball screw,
causing linear motion of the axis. A feedback device confirms that the proper
amount of ball screw revolutions have occurred.

A CNC command executed within the control (commonly through a program)
tells the drive motor to rotate a precise number of times. The rotation of the drive
motor in turn rotates the ball screw. And the ball screw causes drives the linear
axis. A feedback device at the opposite end of the ball screw allows the control to
confirm that the commanded number of rotations has taken place.

How axis motion is commanded - understanding coordinate systems It would
be infeasible for the CNC user to cause axis motion by trying to tell each axis
drive motor how many times to rotate in order to command a given linear motion
amount. (This would be like having to figure out how many turns of the handle
on a table vise will cause the movable jaw to move exactly one inch!) Instead, all
CNC controls allow axis motion to be commanded in a much simpler and more
logical way by utilizing some form of coordinate system. The two most popular
coordinate systems used with CNC machines are the rectangular coordinate
system and the polar coordinate system. By far, the most popular of these two is
the rectangular coordinate system.

63
One very common application for the rectangular coordinate system is
graphing. Almost everyone has had to make or interpret a graph. Since the need
to utilize graphs is so commonplace, and since it closely resembles what is
required to cause axis motion on a CNC machine, let's review the basics of
graphing.

As with any two dimensional graph, this graph has two base lines. Each base
line is used to represent something. What the base line represents is broken into
increments. Also, each base line has limits. In our productivity example, the
horizontal base line is being used to represent time. For this base line, the time
increment is in months. Remember this base line has limits - it starts at January
and end with December. The vertical base line is representing productivity.
Productivity is broken into ten percent increments and starts at zero percent
productivity and ends with one hundred percent productivity.

Let's take what we now know about graphs and relate it to CNC axis motion.
Instead of plotting theoretical points to represent conceptual ideas, the CNC
programmer is going to be plotting physical end points for axis motions. Each
linear axis of the machine tool can be thought of as like a base line of the graph.
Like graph base lines, axes are broken into increments. But instead of being
broken into increments of conceptual ideas like time and productivity, each
linear axis of a CNC machine's rectangular coordinate system is broken into
increments of measurement. In the inch mode, the smallest increment is usually
0.0001 inch. In the metric mode, the smallest increment is 0.001 millimeter. (By
the way, for rotary axes the increment is 0.001 degrees.)

Just like the graph, each axis within the CNC machine's coordinate system
must start somewhere. With the graph, the horizontal baseline started at
January and the vertical base line started at zero percent productivity. This place
where the vertical and horizontal base lines come together is called the origin
point of the graph. For CNC purposes, this origin point is commonly called the
program zero point (also called work zero, part zero, and program origin).

For this example, the two axes we happen to be showing are labeled as X and
Y but keep in mine that program zero can be applied to any axis. Though the
names of each axes will change from one CNC machine type to another (other
common names include Z, A, B, C, U, V, and W), this example should work nicely
to show you how axis motion can be commanded.

The program zero point establishes the point of reference for motion
commands in a CNC program. This allows the programmer to specify movements
from a common location. If program zero is chosen wisely, usually coordinates
needed for the program can be taken directly from the print.

With this technique, if the programmer wishes the tool to be sent to a position
one inch to the right of the program zero point, X1.0 is commanded. If the
programmer wishes the tool to move to a position one inch above the program
zero point, Y1.0 is commanded. The control will automatically determine how
many times to rotate each axis drive motor and ball screw to make the axis reach
64
the commanded destination point. This lets the programmer command axis
motion in a very logical manner.

With the examples given so far, all points happened to be up and to the right
of the program zero point. This area up and to the right of the program zero point
is called a quadrant (in this case, quadrant number one). It is not uncommon on
CNC machines that end points needed within the program fall in other
quadrants. When this happens, at least one of the coordinates must be specified
as minus.


9.4 Understanding absolute versus incremental motion

All discussions to this point assume that the absolute mode of programming
is used. The most common CNC word used to designate the absolute mode is
G90. In the absolute mode, the end points for all motions will be specified from
the program zero point. For beginners, this is usually the best and easiest
method of specifying end points for motion commands. However, there is another
way of specifying end points for axis motion.

In the incremental mode (commonly specified by G91), end points for motions
are specified from the tool's current position, not from program zero. With this
method of commanding motion, the programmer must always be asking "How far
should I move the tool?" While there are times when the incremental mode can
be very helpful, generally speaking, this is the more cumbersome and difficult
method of specifying motion and beginners should concentrate on using the
absolute mode.

Be careful when making motion commands. Beginners have the tendency to
think incrementally. If working in the absolute mode (as beginners should), the
programmer should always be asking "To what position should the tool be
moved?" This position is relative to program zero, NOT from the tools current
position.

Aside from making it very easy to determine the current position for any
command, another benefit of working in the absolute mode has to do with
mistakes made during motion commands. In the absolute mode, if a motion
mistake is made in one command of the program, only one movement will be
incorrect. On the other hand, if a mistake is made during incremental
movements, all motions from the point of the mistake will also be incorrect.

9.5 Assigning program zero

Keep in mind that the CNC control must be told the location of the program
zero point by one means or another. How this is done varies dramatically from
one CNC machine and control to another. One (older) method is to assign
program zero in the program. With this method, the programmer tells the control
how far it is from the program zero point to the starting position of the machine.
65
This is commonly done with a G92 (or G50) command at least at the beginning of
the program and possibly at the beginning of each tool.

Another, newer and better way to assign program zero is through some form
of offset. Commonly machining center control manufacturers call offsets used to
assign program zero fixture offsets. Turning center manufacturers commonly call
offsets used to assign program zero for each tool geometry offsets. More on how
program zero can be assigned will be presented during key concept number four.

To this point, our primary concern has been to show you how to determine
the end point of each motion command. As you have seen, doing this requires an
understanding of the rectangular coordinate system. However, there are other
concerns about how a motion will take place. Fore example, the type of motion
(rapid, straight line, circular, etc.), and motion rate (feedrate), will also be of
concern to the programmer. We'll discuss these other considerations during key
concept number three.

9.6 Telling the machine what to do - the CNC program

Almost all current CNC controls use a word address format for programming.
(The only exceptions to this are certain conversational controls.) By word address
format, we mean that the CNC program is made up of sentence-like commands.
Each command is made up of CNC words. Each CNC word has a letter address
and a numerical value. The letter address (X, Y, Z, etc.) tells the control the kind
of word and the numerical value tells the control the value of the word. Used like
words and sentences in the English language, words in a CNC command tell the
CNC machine what it is we wish to do at the present time.

One very good analogy to what happens in a CNC program is found in any set
of step by step instructions. Say for example, you have some visitors coming in
from out of town to visit your company. You need to write down instructions to
get from the local airport to your company. To do so, you must first be able to
visualize the path from the airport to your company. You will then, in sequential
order, write down one instruction at a time. The person following your
instructions will perform the first step and then go on to the next until he or she
reaches your facility.

In similar manner, a manual CNC programmer must be able to visualize the
machining operations that are to be performed during the execution of the
program. Then, in step by step order, the programmer will give a set of
commands that makes the machine behave accordingly.

Though slightly off the subject at hand, we wish to make a strong point about
visualization. Just as the person developing travel directions MUST be able to
visualize the path taken, so MUST the CNC programmer be able to visualize the
movements the CNC machine will be making BEFORE a program can be
successfully developed. Without this visualization ability, the programmer will
not be able to develop the movements in the program correctly. This is one
66
reason why machinists make the best CNC users. An experienced machinist
should be able to easily visualize any machining operation taking place.

Just as each concise travel instruction will be made up of one sentence, so
will each instruction given within a CNC program be made up of one command.
Just as the travel instruction sentence is made up of words (in English), so is the
CNC command made up of CNC words (in CNC language).

The person following your set of travel instructions will execute them
explicitly. If you make a mistake with your set of instructions, the person will get
lost on the way to your company. In similar fashion, the CNC machine will
execute a CNC program explicitly. If there is a mistake in the program, the CNC
machine will not behave correctly.

O - Program number (Used for program identification)
X- absolute X position
Y- absolute Y position
Z- absolute Z position
A- position (rotary around X)
B- position (rotary around Y)
C- position (rotary around Z)
U- Relative axis parallel to X
V- Relative axis parallel to Y
W- Relative axis parallel to Z
M- code (another "action" register or Machine code(*)) (otherwise referred to as a
"Miscellaneous" function")
F- feed rate
S- spindle speed
N- line number
R- Arc radius or optional word passed to a subprogram/canned cycle
P- Dwell time or optional word passed to a subprogram/canned cycle
T- Tool selection
I- Arc data X axis
J- Arc data Y axis.
K- Arc data Z axis, or optional word passed to a subprogram/canned cycle
D- Cutter diameter/radius offset
H- Tool length offset

As you can see, many of the letter addresses are chosen in a rather logical
manner (T for tool, S for spindle, F for feedrate, etc.). A few require memorizing.
There are two letter addresses (G and M) which allow special functions to be
designated. The preparatory function (G) specifies is commonly used to set
modes. We already introduced absolute mode, specified by G90 and incremental
mode, specified by G91. These are but two of the preparatory functions used.
You must reference your control manufacturer's manual to find the list of
preparatory functions for your particular machine.

Like preparatory functions, miscellaneous functions (M words) allow a variety
of special functions. Miscellaneous functions are typically used as programmable
switches (like spindle on/off, coolant on/off, and so on). They are also used to
67
allow programming of many other programmable functions of the CNC machine
tool.

To a beginner, all of this may seem like CNC programming requires a great
deal of memorization. But rest assured that there are only about 30-40 different
words used with CNC programming. If you can think of learning CNC manual
programming as like learning a foreign language that has only 40 words, it
shouldn't seem too difficult.

9.7 Decimal point programming

Certain letter addresses (CNC words) allow the specification of real numbers
(numbers that require portions of a whole number). Examples include X axis
designator (X), Y axis designator (Y), and radius designator (R). Almost all current
model CNC controls allow a decimal point to be used within the specification of
each letter address requiring real numbers. For example, X3.0625 can be used to
specify a position along the X axis.

On the other hand, some letter addresses are used to specify integer
numbers. Examples include the spindle speed designator (S), the tool station
designator (T), sequence numbers (N), preparatory functions (G), and
miscellaneous functions (M). For these word types, most controls do NOT allow a
decimal point to be used. The beginning programmer must reference the CNC
control manufacturer's programming manual to find out which words allow the
use of a decimal point.

Here we discuss other programmable functions. All but the very simplest CNC
machines have programmable functions other than just axis motion. With
today's full blown CNC equipment, almost everything about the machine is
programmable. CNC machining centers, for example, allow the spindle speed and
direction, coolant, tool changing, and many other functions of the machine to be
programmed. In similar fashion, CNC turning centers allow spindle speed and
direction, coolant, turret index, and tailstock to be programmed. And all forms of
CNC equipment will have their own set of programmable functions. Additionally,
certain accessories like probing systems, tool length measuring systems, pallet
changers, and adaptive control systems may also be available that require
programming considerations.

The list of programmable functions will vary dramatically from one machine
to the next, and the user must learn these programmable functions for each CNC
machine to be used. In key concept number two, we will take a closer look at
what is typically programmable on different forms of CNC machine tools.

9.7 Know your machine

A CNC user MUST understand the makeup of the CNC machine tool being
utilized. While this may sound like a basic statement, a CNC user must be able
to view the machine from two distinctly different perspectives. Here in key
concept number two, we will be viewing the machine from a programmer's
68
perspective. Much later, in key concept number seven, we will look at the
machine from an operator's viewpoint.

Many forms of CNC machines are designed to enhance or replace what is
currently being done with more conventional machines. The first goal of any CNC
beginner should be to understand the basic machining practice that goes into
using the CNC machine tool. The more the beginning CNC user knows about
basic machining practice, the easier it will be to adapt to CNC.

Think of it this way. If you already know basic machining practice as it relates
to the CNC machine you will be working with, you already know what it is you
want the machine to do. It will be a relatively simple matter of learning how to
tell the CNC machine what it is you want it to do (learning to program). This is
why machinists make the best CNC programmers, operators, and setup
personnel. Machinists already know what it is the machine will be doing. It will
be a relatively simple matter of adapting what they already know to the CNC
machine.

For example, a beginner to CNC turning centers should understand the basic
machining practice related to turning operations like rough and finish turning,
rough and finish boring, grooving, threading, and necking. Since this form of
CNC machine can perform multiple operations in a single program (as many CNC
machines can), the beginner should also know the basics of how to process
workpieces machined by turning so a sequence of machining operations can be
developed for workpieces to be machined.

This point cannot be overstressed. Trying to learn about a particular CNC
machine without understanding the basic machining practice related to the
machine would be like trying to learn how to fly an airplane without
understanding the basics of aerodynamics and flight. Just as a beginning pilot
will be in for a great number of problems without understanding aerodynamics,
so is the beginning CNC user have difficulty learning how to utilize CNC
equipment without an understanding of basic machining practice.

From a programmer's standpoint, as you begin to learn about any new CNC
machine, you should concentrate on four basic areas. First, you should
understand the machine's most basic components. Second, you should become
comfortable with your machine's directions of motion (axes). Third, you should
become familiar with any accessories equipped with the machine. And fourth,
you should find out what programmable functions are included with the machine
and learn how they are programmed.

While you do not have to be a machine designer to work with CNC equipment,
it is important to know how your CNC machine is constructed. Understanding
your machine's construction will help you to gauge the limits of what is possible
with your machine. Just as the race car driver should understand the basics of
suspension systems, breaking systems, and the workings of internal combustion
engines (among other things) in order to get the most out of a given car, so must
the CNC programmer understand the basic workings of the CNC machine in
order to get the most from the CNC machine tool.
69

For a universal style slant bed turning center, for example, the programmer
should know the most basic machine components, including bed, way system,
headstock & spindle, turret construction, tailstock, and work holding device.
Information regarding the machine's construction including assembly drawings
is usually published right in the machine tool builder's manual. As you read the
machine tool builder's manual, here are some of the machine capacity and
construction questions to which you should find answers.
What is the machine's maximum RPM?
How many spindle ranges does the machine have (and what are the cut-off
points for each range?
What is the spindle and axis drive motor horsepower?
What is the maximum travel distance in each axis?
How many tools can the machine hold?
What way construction does the machine incorporate (usually square
ways, dovetail, and/or linear bearing ways)?
What is the machine's rapid rate (fastest traverse rate)?
What is the machine's fastest cutting feedrate?

These are but a few of the questions you should be asking yourself as you
begin working with any new CNC machine. Truly, the more you know about your
machine's capacity and construction, the easier it will be to get comfortable with
the machine.

9.8 What is G-Code Programming? (CNC Machine)

G-code is a common name for the programming language that drives NC and
CNC machine tools. It was developed by EIA in the early 1960s, a final revision
was approved in February 1980 as RS274D.

Due to the lack of further development, the sheer variety of machine tool
configurations, and little demand for interoperability, few machine tool
controllers (CNCs) adhere to this standard. Extensions and variations have been
added to it independently by manufacturers, meaning that operators have to
know the dialects and quirks of the particular machines they use, and CAM
systems have had to limit themselves to the lowest common denominator of all
the tools that they support.

Many manufacturers tried to overcome this difficulty of remaining compatible
by following the lead of a machine tool controller built by Fanuc. Unfortunately,
Fanuc does not remain consistent with RS-274 or its own previous standard, and
has been slow at adding new features and exploiting the increase in computing
power. For example, they changed g70/g71 to g20/21; they used parentheses for
comments which caused difficulty when they introduced mathematical
calculations; they started to use nanometers just recently (requires 64 bit); they
introduced the nurbs to overcome slow fetching of blocks from memory (instead
of caching).

70
G-code is also the name of any word in a CNC program that begins with the
letter G, and generally is a code telling the machine tool what type of action to
perform, such as:

Rapid move controlled feed move in a straight line or arc series of controlled
feed moves that would result in a hole being bored, a workpiece cut (routed) to a
specific dimension, or a decorative profile shape added to the edge of a
workpiece.

Common Fanuc G Codes G00 Fast positioning
G01 Linear interpolation
G02 CW circular interpolation
G03 CCW circular interpolation
G10/G11 Data writing/Data write cancel
G17 X-Y plane selection
G18 X-Z plane selection
G19 Y-Z plane selection
G20 Programming in inches
G21 Programming in mm
G28 Return to home position
G31 Skip function (used for probes and tool length measurement systems)
G33 Constant pitch threading
G34 Variable pitch threading
G40 Tool radius compensation off
G41 Tool radius compensation left
G42 Tool radius compensation right
G90 Absolute programming
G91 Incremental programming
G94/G95 Inch per minute/Inch per revolution feed
G96/G97 Constant cutting speed (Constant surface speed)/Constant rotation
speed (constant RPM)

A standardized version of G-code known as BCL is used, but only on very few
machines.

G-code is understood by Gerber photoplotters, machine tool controls, and
CNC machinists. CNC is written by hand for volume production jobs. In this
environment, the inherent inefficiency of CAM-generated g-code is unacceptable.

G-code files may be generated by CAM software such as Alphacam, Artcam,
Edgecam, Featurecam, GibbsCAM, Mastercam, OneCNC, Plasma cam, Router-
CIM, SmartCAM, Surfcam, etc. Those applications typically use translators called
post-processors to output code optimized for a particular machine type or family.
Post-processors are often user-editable to enable further customization, if
necessary. G-code is also output by specialized CAD systems used to design
printed circuit boards. Such software must be customized for each type of
machine tool that it will be used to program.
Some CNC machines use "Conversational" programming, which is a wizard-
like programming mode that either hides G-code or completely bypasses the use
71
of G-code. Some popular examples are Mazak's Mazatrol, Hurco's Ultimax and
Mori Seiki's CAPS conversational software.

Example
This is a generic program that demonstrates the use of G-Code to turn a 1"
diameter X 1" long part. Assume that a bar of material is in the machine and that
the bar is slightly oversized in length and diameter and that the bar protrudes by
more than 1" from the face of the chuck. (Caution: This is generic, it might not
work on any real machine! Pay particular attention to point 5 below.)



Tool Path for program

Line Code Description
N01 M216 Turn on load monitor
N02 G00 X20 Z20
Rapid move away from the part, to ensure the starting
position of the tool
N03 G50 S2000 Set Maximum spindle speed
N04 M01 Optional stop
N05 T0303 M6
Select tool #3 from the carousel, use tool offset values
located in line 3 of the program table, index the turret to
select new tool
N06
G96 S854
M42 M03
M08
Variable speed cutting, 854 ft/min, High spindle gear,
Start spindle CW rotation, Turn the flood coolant on
N07
G00 X1.1
Z1.1
Rapid feed to a point 0.1" from the end of the bar and 0.05"
from the side
N08
G01 Z1.0
F.05
Feed in horizontally until the tool is standing 1" from the
datum
N09 X0.0
Feed down until the tool is on center - Face the end of the
bar
N10 G00 Z1.1 Rapid feed 0.1" away from the end of the bar
72
N11 X1.0 Rapid feed up until the tool is standing at the finished OD
N12 G01 Z0.0
Feed in horizontally cutting the bar to 1" diameter all the
way to the datum
N13 M05 M09 Stop the spindle, Turn off the coolant
N14 G28 G91 X0
Home X axis in the machine coordinate system, then home
all other axes
N15 M215 Turn the load monitor off
N16 M30
Program stop, pallet change if applicable, rewind to
beginning of the program


9.9 Directions of motion (axes)

The CNC programmer MUST know the programmable motion directions (axes)
available for the CNC machine tool. The axes names will vary from one machine
tool type to the next. They are always referred to with a letter address. Common
axis names are X, Y, Z, U, V, and W for linear axes and A, C, and C for rotary
axes. However, the beginning programmer should confirm these axis
designations and directions (plus and minus) in the machine tool builder's
manual since not all machine tool builders conform to the axis names we show.

As discussed in key concept number one, whenever a programmer wishes to
command movement in one or more axes, the letter address corresponding to the
moving axes as well as the destination in each axis are specified. X3.5, for
example tells the machine to move the X axis to a position of 3.5 inches from the
program zero point in X (assuming the absolute mode of programming is used.

Most CNC machines utilize a very accurate position along each axis as a
starting point or reference point for the axis. Some control manufacturers call
this position the zero return position. Others call it the grid zero position. Yet
others call it the home position. Regardless of what it is called, the reference
position is required by many controls to give the control an accurate point of
reference. CNC controls that utilize a reference point for each axis require that
the machine be manually sent to its reference point in each axis as part of the
power up procedure. Once this is completed, the control will be in sync with the
machine's position.

The third area a beginning CNC user should address is related to other
possible additions to the basic machine tool itself. Many CNC machine tools are
equipped with accessories designed to enhance what the basic machine tool can
do. Some of these accessories may be made and supported by the machine tool
builder. These accessories should be well documented in the machine tool
builder's manual. Other accessories may be made by an after-market
manufacturer, in which case a separate manual may be involved.

73
Examples of CNC accessories include probing systems, tool length measuring
devices, post process gauging systems, automatic pallet changers, adaptive
control systems, bar feeders for turning centers, live tooling and C axis for
turning centers, and automation systems. Truly, the list of potential accessory
devices goes on and on.

The programmer must also know what functions of the CNC machine are
programmable (as well as the commands related to programmable functions).
With low cost CNC equipment, often times many machine functions must be
manually activated. With some CNC milling machines, for example, about the
only programmable function is axis motion. Just about everything else may have
to be activated by the operator. With this type of machine, the spindle speed and
direction, coolant and tool changes may have to be activated manually by the
operator.

With full blown CNC equipment, on the other hand, almost everything is
programmable and the operator may only be required to load and remove
workpieces. Once the cycle is activated, the operator may be freed to do other
company functions.

Reference the machine tool builder's manual to find out what functions of
your machine are programmable. To give you some examples of how many
programmable functions are handled, here is a list a few of the most common
programmable functions along with their related programming words.

An "S" word is used to specify the spindle speed (in RPM for machining
centers). An M03 is used to turn the spindle on in a clockwise (forward) manner.
M04 turns the spindle on in a counter clockwise manner. M05 turns the spindle
off. Note that turning centers also have a feature called constant surface speed
which allows spindle speed to also be specified in surface feet per minute (or
meters per minute)

A "T" word is used to tell the machine which tool station is to be placed in the
spindle. On most machines, an M06 tells the machine to actually make the tool
change. Tool change (on turning centers) A four digit "T" word is used to
command tool changes on most turning centers. The first two digits of the T word
specify the turret station number and the second two digits specify the offset
number to be used with the tool. T0101, for example specifies tool station
number one with offset number one.

M08 is used to turn on flood coolant. If available M07 is used to turn on mist
coolant. M09 turns off the coolant.
Automatic pallet changer. An M60 command is commonly used to make pallet
changes. An M60 command is commonly used to make pallet changes.

As stated, programmable functions will vary dramatically from one machine
to the next. The actual programming commands needed will also vary from
builder to builder. Be sure to check the M codes list (miscellaneous functions)
given in the machine tool builder's manual to find out more about what other
functions may be programmable on your particular machine. M codes are
74
commonly used by the machine tool builder to give the user programmable
ON/OFF switches for machine functions. In any case, you must know what you
have available for activating within your CNC programs.

For turning centers, for example, you may find that the tailstock and tailstock
quill is programmable. The chuck jaw open and close may be programmable. If
the machine has more than one spindle range, commonly the spindle range
selection is programmable. And if the machine has a bar feeder, it will be
programmable. You may even find that your machine's chip conveyor can be
turned on and off through programmed commands. All of this, of course, is
important information to the CNC programmer.

You Must Understand The Motion Types Available On Your CNC Machine.
During key concept number one, we discussed how end points for axis motion
are commanded utilizing the rectangular coordinate system. We are concerned
with describing how the CNC machine determines the END POINT position for
each motion. To effectively command motion on most CNC machines requires
more than just specifying end points for positioning movements.

CNC control manufacturers try to make it as easy as possible to make
movement commands within the program. For those styles of motion that are
commonly needed, they give the CNC user interpolation types.

To understanding interpolation, say for example, you wish to move only one
linear axis in a command. Say you wish to move the X axis to a position one inch
to the right of program zero. In this case, the command X1. would be given
(assuming the absolute mode is instated). The machine would move along a
perfectly straight line during this movement (since only one axis is moving). Now
let's say you wish to include a Y axis movement to a position one inch above
program zero in Y (with the X movement). We'll say you are trying to machine a
tapered or chamfered surface of your workpiece in this command. For the control
to move along a perfectly straight line to get to the programmed end point, it
must perfectly synchronize the X and Y axis movements. Also, if machining is to
occur during the motion, a motion rate (feedrate) must also be specified. This
requires linear interpolation.

During linear interpolation commands, the control will precisely and
automatically calculate a series of very tiny single axis departures, keeping the
tool as close to the programmed linear path as possible. With today's CNC
machine tools, it will appear that the machine is forming a perfectly straight line
motion. However, Figure 3.1 shows what the CNC control is actually doing
during linear interpolation. Figure 3.1 - Actual motion generated with linear
interpolation. Notice the series of very tiny single axis movements. The step size
is equal to the machine's resolution, usually 0.0001 in or 0.001 mm.

In similar fashion, many applications for CNC machine tools require that the
machine be able to form circular motions. Applications for circular motions
include forming radii on turned workpieces between faces and turns and milling
radii on contours of machining center workpieces. This kind of motion requires
75
circular interpolation. As with linear interpolation, the control will do its best to
generate as close to a circular path as possible.

While your particular CNC machine may have more motion types (depending
on your application), let's concentrate on becoming familiar with the three most
common types of motion. These three motion types are available on almost all
forms of CNC equipment. After briefly introducing each type of motion, we'll show
an example program that stresses the use of all three.

These motion types share two things in common. First, they are all modal.
This means they remain in effect until changed. If for example, several motions of
the same kind are to be given consecutively, the corresponding G code need only
be specified in the first command. Second, the END POINT of the motion is
specified in each motion command. The current position of the machine will be
taken as the starting point.

Rapid motion (also called positioning). This motion type (as the name implies)
is used to command motion at the machine's fastest possible rate. It is used to
minimize non-productive time during the machining cycle. Common uses for
rapid motion include positioning the tool to and from cutting positions, moving to
clear clamps and other obstructions, and in general, any non-cutting motion
during the program.

You must check in the machine tool builder's manual to determine a
machine's rapid rate. Usually this rate is extremely fast (some machines boast
rapid rates of well over 1000 IPM!), meaning the operator must be cautious when
verifying programs during rapid motion commands. Fortunately, there is a way
for the operator to override the rapid rate during program verification.

The command almost all CNC machines use to command rapid motion is
G00. Within the G00 Command, the end point for the motion is given. Control
manufacturers vary with regard to what actually happens if more than one axis
is included in the rapid motion command. With most controls, the machine will
move as fast as possible in all axes commanded. In this case, one axis will
probably reach its destination point before the other/s. With this kind of rapid
command, straight line movement will NOT occur during rapid and the
programmer must be very careful if there are obstructions to avoid. With other
controls, straight line motion will occur, even during rapid motion commands.

Straight line motion (also called linear interpolation). This motion type allows
the programmer to command perfectly straight line movements as discussed
earlier during our discussion of linear interpolation. This motion type also allows
the programmer to specify the motion rate (feedrate) to be used during the
movement. Straight line motion can be used any time a straight cutting
movement is required, including when drilling, turning a straight diameter, face
or taper, and when milling straight surfaces. The method by which feedrate is
programmed varies from one machine type to the next. Generally speaking,
machining centers only allow the feedrate to be specific in per minute format
(inches or millimeters per minute). Turning centers also allow feedrate to be
specified in per revolution format (inches or millimeters per revolution).
76

A G01 word is commonly used to specify straight line motion. Within the G01,
the programmer will include the desired end point in each axis. Circular motion
causes the machine to make movements in the form of a circular path. This
motion type is used to generate radii during machining. All feedrate related
points made during our discussion of straight line motion still apply.

Two G codes are used with circular motion. G02 is commonly used to specify
clockwise motion while G03 is used to specify counter clockwise motion. To
evaluate which to use, you simply view the movement from the same perspective
the machine will view the motion. For example, if making a circular motion in XY
on a machining center, simply view the motion from the spindle's vantage point.
If making a circular motion in XZ on a turning center, simply view the motion
from above the spindle. In most cases, this is as simple as viewing the print from
above.

Additionally, circular motion requires that, by one means or another, the
programmer specifies the radius of the arc to be generated. With newer CNC
controls this is handled by a simple "R" word. The R word within the circular
command simply tells the control the radius of the arc being commanded. With
older controls, directional vectors (specified by I, J, and K) tell the control the
location of the arc's center point. Since controls vary with regard to how
directional vectors are programmed, and since the R word is becoming more and
more popular for radius designation, our examples will show the use of the R
word. If you wish to learn more about directional vectors, you must reference
your control manufacturer's manual.


77
References

[1] Petruzella, Frank, Programming Logic Controller, Third Edition, 2005.
[2] Siemens, Ladder Logic (LAD) for S7-300 and S7-400 Programming, Edition
03/2006.
[3] Siemens, SIMATIC Manager Software STEP 7 S7/M7/C7, Version V5.3
+SP3.
[4] www.cncbookstore.com.
[5] www.cncci.com.
[6] www.midwestwirechicago.com.

Вам также может понравиться