Share this

Explanation of 3 PLC Programming Algorithms

2026-04-06 03:53:34 · · #1

PLC Programming Algorithm (1)

There are essentially three types of large quantities in a PLC: digital signals, analog signals, and pulse signals. Once you understand the relationship between these three, you can master PLC operation.

1. Switching quantities, also known as logic quantities, refer to quantities that have only two values: 0 or 1, ON or OFF (switching quantities have only two states, 0/1, including input and output quantities, reflecting the state). They are the most commonly used control methods, and controlling them is a strength of PLCs and their most basic application.

The purpose of digital input control is to enable the PLC to generate corresponding digital outputs based on the current input combination and the historical input sequence, so that the system can operate in a certain sequence. Therefore, it is sometimes also called sequential control.

Sequential control can be further divided into manual, semi-automatic, or automatic. The control principles employed can be categorized into three types: decentralized, centralized, and hybrid control.

2. Analog quantities refer to continuously changing physical quantities (digital quantities are discontinuous, reflecting electrical measurement values), such as voltage, current, pressure, speed, and flow rate.

PLCs evolved from relay control with the introduction of microprocessor technology and can be conveniently and reliably used for switching control. Since analog signals can be converted into digital signals, and digital signals are simply multi-bit switching signals, PLCs can also reliably process and control the converted analog signals.

Since continuous production processes often involve analog quantities, analog quantity control is sometimes also called process control.

Analog signals are mostly non-electrical quantities, while PLCs can only handle digital signals, specifically electrical quantities. Therefore, sensors are needed to convert analog signals into digital quantities to achieve the conversion between them.

If the electrical quantity is not standard, it needs to 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.

It also requires an analog input unit (A/D) to convert these standard electrical signals into digital signals. An analog output unit (D/A) is also needed to convert the digital signals processed by the PLC back into analog signals—standard electrical signals.

Therefore, various calculations are required for the conversion between standard electrical signals and digital quantities. This necessitates understanding the resolution of analog signal units and standard electrical signals.

For example:

The PLC analog unit has a resolution of 1/32767, corresponding to a standard voltage of 0-10V. The temperature range to be detected is 0-100℃. Therefore, 0-32767 corresponds to a temperature range of 0-100℃. The digital value corresponding to 1℃ is then calculated to be 327.67. To obtain a temperature value accurate to 0.1℃, simply divide 327.67 by 10.

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

3. A pulse quantity is a digital quantity whose value constantly alternates between 0 (low level) and 1 (high level) (a signal quantity in which voltage or current jumps from one value to another instantaneously). The number of pulse alternations per second is called the frequency.

The main purposes of PLC pulse quantity control are position control, motion control, and trajectory control. For example, pulse count is used in angle control. A stepper motor driver with a microstepping of 10,000 revolutions is required to rotate the stepper motor 90 degrees.

Therefore, the required pulse value is 10000/(360/90) = 2500.

PLC Programming Algorithm (2) - Analog Quantity Calculation

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

2. 0-10V. At a voltage of 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. At a current of 0-20mA, it is converted to 0-1770Hex (0-6000) at a resolution of 6000; and to 0-2EE0Hex (0-12000) at a resolution of 12000.

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

The above is just a brief introduction. Different PLCs have different resolutions, and the measurement range of the physical quantity you are measuring may vary. Therefore, the calculation results may differ.

Note: Wiring requirements for analog inputs

1. Use shielded twisted pair cable, but do not connect the shielding layer.

2. When an input is not in use, short-circuit the VIN and COM terminals.

3. Analog signal lines are isolated from 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 supply unit.

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

6. When powering off, first disconnect the power supply to the load, and then disconnect the power supply to the CPU.

PLC Programming Algorithm (3) - Calculation of Pulse Quantity

Pulse quantity control is often used for angle control, distance control, and position control of stepper motors and servo motors. The following uses a stepper motor as an example to illustrate the various control methods.

1. Angle control of stepper motor. First, determine the microstepping setting of the stepper motor, and then determine the total number of pulses required for the stepper motor to complete one revolution.

Calculate "Angle percentage = Set angle / 360° (i.e., one revolution)".

"Angle motion pulse count = total pulse count per revolution * angle percentage"

The formula is:

Number of angle movement pulses = Total number of pulses per revolution * (Set angle / 360°)

2. Stepper motor distance control. First, determine the total number of pulses required for one revolution of the stepper motor. Then, determine the diameter of the stepper motor roller and calculate the roller circumference. Calculate the travel distance per pulse. Finally, calculate the number of pulses required to travel the set distance.

The formula is:

Set distance pulse count = Set distance / [(roller diameter * 3.14) / total number of pulses per revolution]

3. The position control of a stepper motor is a combination of angle control and distance control.

The above is just a simple analysis of the control method of stepper motors, which may differ from the actual situation and is for reference only.

The operation of a servo motor is the same as that of a stepper motor, but the internal electronic gear ratio and the reduction ratio of the servo motor must be considered.


Read next

CATDOLL 136CM Tami (Customer Photos)

Height: 136cm Weight: 23.3kg Shoulder Width: 31cm Bust/Waist/Hip: 60/54/68cm Oral Depth: 3-5cm Vaginal Depth: 3-15cm An...

Articles 2026-02-22