Comprehensive PLC Programming Algorithms Summarized by Senior Electrical Engineers

In PLC, there are three main quantities: digital signals, analog signals, and pulse signals. Once you understand the relationship between these three, you can master PLC proficiently.

01 PLC Programming Algorithms (1)

1. Digital signals, also known as logic signals, refer to values that can only be 0 or 1, ON or OFF. This is the most common control, and controlling it is the advantage of PLC, as well as its most basic application.

The purpose of digital signal control is to generate corresponding digital signal outputs based on the current input combinations and historical input sequences, allowing the system to operate in a specific order. Therefore, it is sometimes referred to as sequential control.

Sequential control can be manual, semi-automatic, or automatic. The control principles used can be decentralized, centralized, or mixed control.

2. Analog signals refer to continuous varying physical quantities, such as voltage, current, pressure, speed, and flow.

PLC has developed from relay control with the introduction of microprocessor technology, allowing for convenient and reliable digital signal control. Since analog signals can be converted into digital signals, which are just multi-bit digital signals, PLC can reliably handle the converted analog signals for control.

As continuous production processes often involve analog signals, analog signal control is sometimes referred to as process control.

Analog signals are mostly non-electrical quantities, while PLC can only handle digital and electrical quantities. Therefore, to achieve conversion between them, sensors are needed to convert analog signals into digital quantities. If the electrical quantity is not standard, it must go through a transmitter to convert the non-standard electrical quantity into a standard electrical signal, such as 4–20mA, 1–5V, 0–10V, etc.

Additionally, there must be an analog input unit (A/D) to convert these standard electrical signals into digital signals; and an analog output unit (D/A) to convert the processed digital quantities back into analog signals—standard electrical signals.

Thus, the conversion between standard electrical signals and digital quantities requires various calculations. It is crucial to understand the resolution of the analog signal unit and the standard electrical signals.

For example:

If the resolution of the PLC analog unit is 1/32767, and the corresponding standard electrical quantity is 0–10V, and the temperature range to be detected is 0–100℃. Then 0–32767 corresponds to the temperature value of 0–100℃. The digital quantity corresponding to 1℃ is calculated as 327.67. If you want to achieve a temperature value accurate to 0.1℃, simply divide 327.67 by 10.

Analog signal control includes feedback control, feedforward control, proportional control, fuzzy control, etc. These are all calculation processes of digital quantities within the PLC.

3. Pulse signals are digital quantities that continuously alternate between 0 (low level) and 1 (high level). The number of times pulses alternate per second is called frequency.

The main purpose of PLC pulse signal control is position control, motion control, trajectory control, etc. For example, the application of pulse counts in angle control. If the stepper motor driver has a subdivision of 10000, and it is required for the stepper motor to rotate 90 degrees, then the number of pulses needed for the action = 10000/(360/90) = 2500.

02 PLC Programming Algorithms (2) – Calculation of Analog Signals

1. -10—10V. When the voltage is -10V—10V, it is converted to F448—0BB8Hex (-3000—3000) at a resolution of 6000; at a resolution of 12000, it is converted to E890—1770Hex (-6000—6000).

2. 0—10V. When the voltage is 0—10V, it is converted to 0—1770Hex (0—6000) at a resolution of 12000; at a resolution of 12000, it is converted to 0—2EE0Hex (0—12000).

3. 0—20mA. When the current is 0—20mA, it is converted to 0—1770Hex (0—6000) at a resolution of 6000; at a resolution of 12000, it is converted to 0—2EE0Hex (0—12000).

4. 4—20mA. When the current is 4—20mA, it is converted to 0—1770Hex (0—6000) at a resolution of 6000; at a resolution of 12000, it is converted to 0—2EE0Hex (0—12000).

The above is just a simple introduction; different PLCs have different resolutions, and the range of physical quantities you measure may vary. The calculation results may have some discrepancies.

Note: Wiring Requirements for Analog Inputs

1. Use shielded twisted pair cables, but do not connect the shield layer. 2. When an input is not used, short-circuit the V IN and COM terminals.

3. Isolate the analog signal wires from the power lines (AC power lines, high voltage lines, etc.).

4. When there is interference on the power line, install a filter between the input section and the power unit.

5. After confirming the correct wiring, power on the CPU unit first, then power on the load.

6. When cutting power, first cut off the load power, then cut off the CPU power.

03 PLC Programming Algorithms (3) – Calculation of Pulse Signals

Pulse signal control is mainly used for the angle control, distance control, and position control of stepper motors and servo motors. The following explains the control methods using stepper motors as an example.

1. Angle control of the stepper motor. First, clarify the subdivision number of the stepper motor, then determine the total number of pulses required for the stepper motor to complete one rotation. Calculate “angle percentage = set angle/360° (i.e., one rotation)” and “angle action pulse count = total pulse count for one rotation * angle percentage.”

The formula is: angle action pulse count = total pulse count for one rotation * (set angle/360°).

2. Distance control of the stepper motor. First, clarify the total number of pulses required for the stepper motor to complete one rotation. Then determine the diameter of the stepper motor wheel and calculate the circumference of the wheel. Calculate the distance traveled per pulse. Finally, calculate the number of pulses needed to cover the set distance.

The formula is: set distance pulse count = set distance/[(wheel diameter * 3.14)/total pulses for one rotation].

3. Position control of the stepper motor is a combination of angle control and distance control.

The above is just a simple analysis of the control methods for stepper motors, and it may differ from actual practice, for reference only.

The operation of the servo motor is similar to that of the stepper motor, but the internal gear ratio of the servo motor and the reduction ratio of the servo motor must be considered.

This article is sourced from the internet, and the copyright belongs to the original author. If there is any infringement, please contact for removal!


Fan Exclusive
【Siemens Complete Data】

Comprehensive PLC Programming Algorithms Summarized by Senior Electrical Engineers

Previous Recommendations

The electrician laid the wires crookedly, but the owner was very satisfied and paid an extra 500 yuan!

A single article to easily learn various numeral system conversions

Electrical automation control professional terminology, saved!

How to achieve OPC communication between KingView and WinCC (2)

Does emergency stop cut off all output power or the entire device’s power? This principle is unknown to at least 90% of electricians.

How to achieve OPC communication between KingView and WinCC (1)

Electricians can find more than five errors in the distribution box they wired. They are all veteran electricians!

Solidworks modeling case 2 – Spiral Dragon Blade

Siemens S7-200SMART encoder speed measurement program, ready to use! Save it first!

[PLC Essentials] Mitsubishi L Series communication module serial communication example

Leave a Comment