Friday, March 31, 2023

Address codes

CNC programming involves the use of various codes and symbols to control the movement and behavior of CNC machines. Each code and symbol serves a specific purpose within the CNC program. Here is a summary of the definitions provided:

A, B, and C These letters represent the names of different rotary axes associated with the X, Y, and Z linear axes, respectively. They are used to control the rotational movements of the machine.

D = It specifies the offset value of a cutting tool. The offset value is used to adjust the position of the tooltip relative to the tool holder.

F = This code defines the feed rate of an axis, indicating how fast the movement of the axis should be. A numeric value is used after the F code to specify the feed rate. For example, F100 means the axis movement feed or speed will be 100 mm/minute.

G = It is a preparatory function code used to define various parameters such as the coordinate system, measuring system, work offset, etc. Different G codes are selected by using a numeric value. For example, G90 expresses the Absolute measurement system, and G91 defines the Incremental measurement system.

H = This code is an auxiliary function code used for specific auxiliary functions. It is often used as an alternative to an M code. It can also be used to define the length of a cutting tool.

 

I, J, K = These letters are used to expressing the distance of the arc center from the arc starting point in circular interpolation. I specify the length in a specific direction relative to the X-axis, J for the Y-axis, and K for the Z-axis.

M = It represents a miscellaneous code used for various functions such as tool change, spindle control, coolant control, etc. Different M codes are followed by a numeric character to identify specific functions. For example, M03 defines spindle ON, and M07 represents coolant ON.

N = It is a program block number used to mark each program block in a CNC program. It helps to organize and identify different sections of the program.


O = This symbol followed by a number represents a program number. It is used to define a specific program with a FANUC controller. For example, O1234 or O555.

R = The R parameter is used to represent changeable values in a program, making it easier to perform complex mathematical functions. It can also define the radius for circular interpolation paths.


S = It refers to spindle addressing, followed by a numerical value indicating the spindle's rotation speed in RPM (Revolutions Per Minute). For example, S2000 determines that the spindle will rotate at 2000 RPM.


T = It refers to a cutting tool and is followed by a numeric value that identifies a specific tool. For example, T5 signifies that the number five cutting tool will be in operation for upcoming program blocks.

U, V, W = These letters represent additional linear axes that may be present in some CNC machines. They are used to control the movement of these extra axes.

X, Y, Z = These letters represent the primary axes of a CNC machine. They are associated with the coordinate axes, and the numerical values following each letter indicate the position or distance along the respective axis.


LF or ; = These symbols represent the end of a program block. The LF symbol is used in SIEMENS controllers, while the " ; " symbol is used in FANUC controllers to mark the end of a program block.

These codes and symbols form the basis of CNC programming and allow programmers to control and specify the desired actions and movements of the CNC machine.

Thursday, March 23, 2023

Offsets ​​and Parameters

Reference point

After switching on a CNC machine, the controller does not have any real-time positioning information about the machine's axes. Therefore, all the axes need to be referenced before proceeding with the machining work. Referencing means bringing all the axes to a specific location from where all the axis movement measurements will be carried out. Reference points of machine axes are usually specified by the machine builders and can be changed by the user if required. CNC machines and axes running with "Absolute Encoder" position feedback do not require referencing each time after switching on. An absolute encoder holds its last position value before switching off the machine (detailed information about Absolute Encoders is discussed in the 'Feedback' chapter). The zero positions of all the axes are calculated based on the reference points, and the CNC controller associates them with the coordinate system.

Machine zero

All the axis positions of a CNC machine are related to the coordinate system, and the origin or zero point of the axis measurement is called Machine Zero or Machine Home position. All the axes assume the zero position here and display the actual value as 0.000. Sometimes the reference point and machine zero position may be in the same location, and occasionally they may differ. If the axis position displays 0.000 after referencing the machine, the machine zero, and the reference point will be at the same place. Otherwise, after referencing, the axis position will display the actual range from the zero position, usually defined by machine builders.

Workpiece Zero

Refers to a point on a workpiece that is used for machining, where all the dimensions or coordinate points are assumed for programming. Based on this point, different workpiece dimensions are calculated in accordance with the drawing. In other words, workpiece zero is a temporary coordinate zero point that can be easily exchanged for error-free programming. The distance from the machine zero to the workpiece zero position is called the zero offset. The following image illustrates the reference point, machine zero point, and workpiece zero. Here, the reference and machine zero points are considered two separate points.

 

Zero Offset

Zero offset refers to the distance from the machine zero to the workpiece zero position, and in other words, it is the coordinate distance from the machine zero to the workpiece zero. Zero offset values are adjusted for different axes and change with workpieces. G54, G55, G56, etc., codes are used in the program to define different zero offset values. Offset values are usually stored in the CNC controller memory and are recalled whenever they are needed for operation. The following picture shows how the zero offset values of a workpiece are considered for X, Y, and Z-axis positions. 

The previous picture shows the distance between the workpiece zero and the machine zero position, where X = 500 mm, Y = 1000 mm, and Z = 400 mm, respectively (all in the negative direction). The zero offset values for this particular workpiece are considered as G54 and will be stored in the controller memory. By using the G54 code within a program, the coordinate zero position (0, 0) will shift to the workpiece zero position, and the X, Y, and Z axes will move 500 mm, 1000 mm, and 400 mm (in the negative direction), respectively, considering all axis positions as the coordinate zero position temporarily. Further movements of the axes will take place based on this zero position only, and to return to the machine zero or cancel the workpiece zero, the G53 code is applied in the programming.

 

Tool Offset

With CNC machines, cutting tools used for machining have different diameters and sizes. It is inconvenient to program and estimates separate lengths and radii for each tool, as the axis movements will be different for individual tool lengths. The program always assumes a standard tool length and radius, and during program execution, the actual tool length and diameter are compensated based on the standard tool. The height and diameter of each tool are stored in the controller memory in a table format as tool offset data. Sometimes, a single tool may have more than one tool offset, depending on the machining conditions. When a particular tool is called in a program for machining, the actual axis movements will be finalized by compensating the tool offset data with the standard tool data. Tool offset data is commonly represented by the letter D, and within a program, T1 D1 represents Tool T1 with an offset value of D1.

   

R-Parameter

R-parameters are used to achieve flexibility in CNC programming, and sometimes instead of using numeric values in a program, R-parameters are used to make the program shorter. With R-parameters, a complex program can be written more efficiently, and any mathematical function inside the program can be expressed effortlessly. R01, R10, R50, etc., are written instead of using numeric values, and the R-values are stored in the CNC controller memory.

 

Logical Functions in PLC

What is a Logical Function?

A logical function is a rule-based operation that is executed sequentially in a continuous loop to perform specific tasks or operations. In the context of programmable logic controllers (PLCs), logical functions are used to make decisions based on the results of these functions. For example, an automatic drill machine will only start when the machine guard is closed. In this case, the machine Start switch and Guard switch are connected using an AND logic. The drill machine will start only when both the start and guard switches are activated and in the logic state 1. There are three basic logical functions: AND, OR, and NOT, and other logical operations are combinations of these three functions. The following sections describe different logical functions and their applications in PLC programming languages.

AND 

AND logic is a basic logical function where the output is activated (ON) when two normally open (NO) contacts are simultaneously activated (ON). In the electrical circuit shown below, a lamp will glow only when both switches, Input A and Input B, are triggered simultaneously. If either switch becomes OFF, the lamp will turn off. In PLC programming languages (LAD, STL, and FBD), Input A and Input B switches are represented as input 'I0.1' and 'I0.2' respectively, and the lamp is represented as PLC output 'Q0.0'. The following programming examples demonstrate the AND logical operation in different languages, and the output status is represented by a truth table.

 

 OR 

OR logic is another basic logical function where the output is activated (ON) when either of the two normally open (NO) contacts is activated (ON). In the electrical circuit shown below, a lamp will light up if either switch, Input A or Input B, is activated, and both switches should be OFF to turn off the lamp. The switches are connected using an OR logic. In PLC programming languages (LAD, STL, and FBD), Input A and Input B switches are represented as 'I0.1' and 'I0.2' respectively, and the lamp is represented as PLC output 'Q0.0'. All programs express the OR logic using different languages, and the output status is represented by a truth table.

 

NOT 

NOT logic operation triggers the output (ON) until an Input is deactivated. In the electrical circuit shown below, a normally closed (NC) contact switch 'Input A' is connected to the lamp. The lamp turns on when the control is activated (pressed), and the lamp voltage supply is interrupted when the control is released. In PLC programming languages (LAD, STL, and FBD), Input A is represented as 'I0.1', and the PLC output 'Q0.0' represents the lamp output. The programs demonstrate the NOT logic using different languages, and the output status is represented by a truth table.

 

NAND 

NAND logic operation triggers the output when both inputs are deactivated or turned off. In the electrical circuit shown below, a lamp will glow only if either switch, Input A or Input B, is deactivated. If both switches are activated, the lamp will turn off. The switches are connected using NAND logic. In PLC programming languages (LAD, STL, and FBD), Input A and Input B switches are represented as 'I0.1' and 'I0.2' respectively, and the lamp is represented as PLC output 'Q0.0'. The programs demonstrate the NAND logical operation using different languages, and the output status is represented by a truth table.

 

NOR 

NOR logic operation triggers the output when both inputs are deactivated together. In the electrical circuit shown below, the lamp will light up only if both switches, Input A and Input B, are deactivated. If either switch is activated, the lamp will turn off. The switches are connected using NOR logic. In PLC programming languages (LAD, STL, and FBD), Input A and Input B switches are represented as 'I0.1' and 'I0.2' respectively, and the lamp is represented as PLC output 'Q0.0'. The programs demonstrate the NOR logical operation in different languages, and the output status is represented by a truth table.

 

Exclusive OR 

The Exclusive OR (XOR) logic function activates the output when either of the inputs is activated, but both inputs must be activated or deactivated together to trigger the output in the off state. In the electrical circuit shown below, the lamp will light up when either switch, Input A or Input B, is activated. The lamp turns off when both switches are either activated or deactivated together. The switches are treated as "Dual-contact" where one is a normally closed (NC) contact and the other is a normally open (NO) contact for individual control. When a switch is activated, the NC contact opens, and the NO contact makes a connection. The lamp is supplied through any combination of switching contacts when either switch is activated. The electrical diagram represents the deactivated state of the lamp and the activation of both switches, cutting off the electrical supply. The timing diagram shows the output status of the lamp. In PLC programming languages (LAD, STL, and FBD), Input A and Input B switches are represented as 'I0.1' and 'I0.2' respectively, and the lamp is represented as PLC output 'Q0.0'. All programs demonstrate the XOR logic using different languages, and the output status is represented by a truth table.

 

Exclusive NOR 

NOR Exclusive NOR (XNOR) logic operation activates the output when both inputs are activated or deactivated. In the electrical circuit shown below, the lamp will light up when both switches, Input A and Input B, are activated or deactivated together. The lamp turns off when either switch is activated. The switches are also treated as "Dual-contact" with one normally closed (NC) contact and one normally open (NO) contact, but the configuration is different from XOR logic. When a switch is activated, the NC contact opens, and the NO contact makes a connection. The electrical diagram represents the deactivated state of both switches, and the lamp will glow. The electrical supply will lead the lamp through another path when the switches are activated. The switches are connected in XNOR logic, and the timing diagram describes the output status of the lamp. In PLC programming languages (LAD, STL, and FBD), Input A and Input B switches are represented as 'I0.1' and 'I0.2' respectively, and the lamp is represented as PLC output 'Q0.0'. All programs demonstrate the XNOR logic using different languages, and the output status is represented by a truth table.

 

Writing a PLC program using Logical Functions:

We are already familiar with different types of logical functions associated with PLCs. Here are some simple examples that illustrate various electrical circuits and their representation in PLC languages using logical functions. As mentioned earlier, ladder programming is the simplest way to represent a PLC program, resembling an electrical wiring diagram.

 

Example - 1



Example - 2



Example - 3


Example - 4


Thursday, March 9, 2023

Elements of PLC

A PLC unit simulates the harmonious functioning of multiple devices or components, which can vary in size and input/output handling capacity. In small PLCs, all devices are integrated into a single unit, while in larger or medium-sized PLCs, different modules operate independently and are interconnected via cables, connected to a bus unit. This flexibility allows for the addition of further modules or units. The basic working principle is almost the same for all types of PLCs. The pictures below depict a small and medium-sized PLC.


A complete PLC unit consists of the following primary elements:

  • Power supply unit
  • A central processing unit (CPU)
  • Input module
  • Output module
  • Analog input and output module

Power supply unit

The power supply unit generates a regulated DC voltage to supply other elements such as the CPU and input/output modules. Most PLCs operate with only 24V DC and 220V AC input voltages. The power supply unit provides separate low-rating DC voltages to various modules. In a small PLC, the power supply unit, input/output modules, and CPU are fabricated on the same base without separate cabling connections. In medium or large PLCs, different units or modules are connected to the power supply unit using ribbon cables to obtain the necessary voltage. The current rating of a power supply unit increases when managing more sensors and actuators.

 

Central processing unit or CPU

The CPU can be considered the brain of a PLC, as it supervises and controls all the work performed by the PLC. The CPU contains a microprocessor unit that controls the output devices or actuators associated with the PLC. It is compatible with a program stored in memory and the state of input devices or sensors. The CPU module is connected to input/output modules either through cables or a common bus. It features LED indicators that display the status of the PLC, such as Ready, Run, Stop, and Fault. A small toggle switch is also provided on the CPU module, allowing switching between the "Program" and "Run" modes of the PLC. The CPU module is equipped with a "Communication port" that enables the PLC to communicate with external programming devices or computers. This port is used for uploading or downloading programs to the PLC memory. The CPU unit also includes two different types of memory: ROM and RAM. Additionally, the CPU can be further subdivided into the following categories:

  • Executive memory
  • System Memory
  • Input / Output status memory
  • Data memory
  • User program memory 

Executive memory – The PLC operating system is stored in a ROM-type executive memory, which defines how the PLC unit will function. This memory is specified by the PLC manufacturer and does not need to be modified. Along with the operating system, the PLC program is scanned and processed by the microprocessor, which also monitors the status of all input and output elements.

System memory – A portion of memory stores temporary results and information while the PLC operating system is functioning. This RAM memory is specific to the operating system and cannot be used by the user for PLC programming.

Input / Output Status Memory – Another part of the RAM memory stores the input/output status of different sensors and actuators associated with the PLC unit. It contains an image table that represents a specific location for each input and output module of the PLC. During PLC program execution, the state of different sensors is retrieved from the image table instead of directly registering from the input module. Similarly, the output status of the PLC program is not sent directly to the output module but rather transferred to the image table in the input/output status memory.

Data memory – A portion of RAM memory is used independently as data memory, storing values related to timers, counters, and other process parameters applied in the PLC program. Some PLC manufacturers allocate this data memory into fixed and variable data segments.

User program memory – During the development of a new PLC program, PLC users manage the user program memory in RAM, allowing for the rectification of any errors within the program. Once the PLC program is error-free and successfully tested, it is copied to an EPROM module, which the PLC subsequently runs.

 

Input Module

An input module interfaces different sensors or input elements with the PLC unit. It allows the PLC to monitor the state (active or inactive) of all sensors and interfaces them with the microelectronics of the PLC in the real world. Most PLCs operate with 5V to 15V DC, while the sensors used may have different voltage ratings such as 24V DC and 220V AC. The input module plays a crucial role in isolating input elements or sensors with different voltage ratings from the PLC. Each input terminal within the input module uses an Opto-Isolator circuit, which allows only the signal voltage while preventing any surge voltage from sensors, thus protecting the PLC from damage.

PLC manufacturers produce different input modules to handle input elements or sensors, such as 8-point, 16-point, and 32-point modules. The basic operating principle of all input modules is nearly the same. Input elements or sensors connected to an input module are assigned input addresses, which consist of an alphabet (e.g., I, X) followed by a numeric number (e.g., I1.5, X4.7). For instance, SIEMENS PLCs designate input addresses with an "I," while FANUC PLCs use the alphabet "X." The picture below illustrates how to input elements or sensors are designated and connected to an input module. 

The previous image shows an "8-point" input module, which can accommodate eight input elements or sensors (represented by three input switches, a push-button switch, and a sensor). All input elements receive a 24V DC voltage. The input addresses for the switch, push-button, and sensor are I0.1, I0.4, and I0.7, respectively. The state of switches or sensors (active or inactive) is recognized by the PLC based on the logic 0 or logic 1 status of these input addresses. If more than eight sensors need to be interfaced with the PLC, instead of using multiple 8-point input modules, a 16-point or 32-point module can be utilized. Several input modules with different input channel numbers can interface with the CPU.

Inputs are addressed as byte addresses (where one byte equals 8 bits). At the end of one byte address, the next byte address is acknowledged. For example, if the input module starts with input address I0.0 (as shown in the previous picture), it will address up to I0.7. The addressing of subsequent input modules will start from I1.0 and continue up to I1.7. Similarly, the addressing of the following input module will start from I2.0 and so on. It is not necessary for the addressing of input modules to always start from I0.0; this depends on the choice of the PLC manufacturer. However, the addressing number will always be the next number of the previous address number. For example, if I32.0 is the starting address of an input module, the subsequent module addressing will start with I33.0. This addressing method is also applicable to 16-point or 32-point input modules. The picture below explains the addressing procedure for two 16-point input modules, where the first 16 points are addressed from I0.0 to I1.7 (representing two input channels together), and the second module starts addressing from I2.0 to I3.7.


Output Module

Actuators or output elements that function with PLC-operated machines or automated systems usually interface with the PLC through an output module. The output module supplies a 24V DC voltage to activate different actuators. Low current rating elements, such as relays or LEDs, directly connect to the output module. However, higher voltage or current rating actuators like solenoid coils and motor contactors interface with the output module through a relay unit. Similar to the input module, the actuators also interface with the output module through an optoisolator circuit, which reduces electrical noise and prevents damage to the electronic circuits inside the output module.

Output modules come in different types, such as 8 points and 16 points. The PLC manages separate output addresses for the actuators or output elements connected to the output module. Output addresses are defined with alphabets Q, Y, or O, followed by a numerical number. For example, Y1.5 or Q4.7. SIEMENS PLCs use the letter Q, while FANUC PLCs use the letter Y to define output addresses. The diagram below illustrates how actuators or output elements interface with an output module and how they are addressed. 

The diagram above shows an '8 point' output module, which can connect up to eight actuators or output elements. In this example, three output elements are used: a light, a relay, and a solenoid coil. The first two elements (Q0.1 and Q0.4) directly connect to the output module, as they have lower current ratings, and are activated with a 24V DC supply. The solenoid coil, which has a higher current rating, is triggered by a separate 24V DC supply that passes through a relay. The relay is interfaced and controlled by the PLC output module (Q0.7). When the output address is set to Logic 1, a 24V DC supply is present at the corresponding output terminal, which energizes or activates the respective actuator. Each output terminal is equipped with an LED indicator to indicate its activation. A Logic 0 status of an output address represents the deactivation of the corresponding element or actuator. For higher voltage ratings actuators, such as those requiring 110V AC or 220V AC, the relay unit is used to manage the required voltages. In cases where more than eight output elements need to be interfaced with the PLC, a 16 points or 32 points output module can be used instead of multiple 8 points output modules.

Outputs are also addressed byte-wise (one byte with 8 bits), similar to input addresses. After the end of the one-byte address, the subsequent address byte is used. Since the output module starts from output address Q0.0, it is addressed up to Q0.7 (as shown in the diagram). The addressing of subsequent output modules will start from Q1.0 and extend up to Q1.7. The addressing of the following output modules will continue in the same manner. It is not mandatory for the output module addressing to always start from Q0.0; it depends on the preference of the PLC manufacturer. The addressing can start from any output address number, such as Q32.0. However, regardless of the starting address number, the subsequent output modules will always have consecutive address numbers. For example, if Q32.0 is the starting address of the output modules, the next module's address will start with Q33.0. This addressing method is also applicable for 16 points or 32 points output modules. The following diagram illustrates the addressing procedure of a 16-point output module. In this example, the first 16-point output module addresses Q0.0 to Q1.7 (two output channels together), and the second module starts addressing from Q2.0 to Q3.7. 


Analog Input and Output Module

Most PLCs are also capable of functioning with analog input and output signals. Analog inputs come from various sensors and transmitters that measure events such as liquid level, flow, temperature, distance, and velocity. The sensor or transmitter converts these events into an electrical signal and feeds them to the PLC's analog card. An analog signal is a continuous signal and typically ranges from 4 to 20 milliamperes or 0 to 10 volts. When the analog input signal reaches the PLC, it passes through an A/D (Analog-to-Digital) converter circuit, and the PLC's analog input card converts this analog signal into a 16-bit digital signal. In the PLC, an analog signal is represented by a word, which is a binary sequence of 16 zeros (e.g., '00000000 00000000'). However, programming with analog input and output in a PLC can be challenging.

A field device or analog sensor is usually connected to a transducer, and the transducer's output is provided to the PLC's analog input card. In the following example, a measuring scale or weighing machine is equipped with a load cell (not shown in the picture). The load cell translates changes in weight into a variable voltage or current output. In this case, the load cell converts the weight value into a 0-10V DC output, representing a 0-50 Kg input. This voltage is then connected to the PLC's analog expansion module.

Analog outputs are used to control appliances that require continuous voltage or current levels. Different equipment such as control valves, chart recorders, electric motor drives, and pressure transducers are managed by analog outputs. Similar to analog inputs, analog outputs are connected to the controlled devices through a transducer unit. The transducer receives a voltage signal from the PLC, amplifies, reduces, or changes it into another voltage signal, which controls the device. The following example shows a 0-10V DC signal used to control the opening of an analog valve.



Popular Posts