+(86)0752-5103606 E-mail：info@hytech-cn.com

# PLC programming algorithm

Last Updated on 2020-11-16 Hits:8132

There are three large quantities in PLC: switch quantity, analog quantity and pulse quantity. Only by figuring out the relationship between the three, you can master PLC proficiently.

1. Switch quantity is also called logical quantity, which means that there are only two values, 0 or 1, ON or OFF. It is the most commonly used control. Controlling it is the advantage of PLC and the most basic application of PLC.

The purpose of the switch control is to make the PLC produce the corresponding switch output according to the current input combination of the switch and the historical input sequence, so that the system can work in a certain order. Therefore, it is sometimes called sequential control.

The sequence control is divided into manual, semi-automatic or automatic. The control principles adopted include decentralized, centralized and mixed control.

2. Analog quantity refers to some continuously changing physical quantity, such as voltage, current, pressure, speed, flow, etc.

PLC is developed from the introduction of micro-processing technology in relay control, and can be conveniently and reliably used for switch control. Since the analog quantity can be converted into a digital quantity, the digital quantity is only a multi-digit switch quantity, so the converted analog quantity can be processed and controlled reliably by the PLC.

Since there are often analogs in continuous production processes, analog control is sometimes called process control.

Analog quantity is mostly non-electricity, while PLC can only handle digital quantity and electric quantity. All the conversion between them must have sensors to convert analog quantities into digital quantities. If this power is not standard, it must be passed through a transmitter to turn the non-standard power into a standard electrical signal, such as 4-20mA, 1-5V, 0-10V and so on.

At the same time, there is also an analog input unit (A/D) to convert these standard electrical signals into digital signals; an analog output unit (D/A) to convert the digital quantity processed by the PLC into an analog quantity-standard Electrical signal.

Therefore, the conversion between standard electrical signals and digital quantities requires various operations. This requires clarifying the resolution of the analog unit and the standard electrical signal. E.g:

The resolution of the PLC analog unit is 1/32767, the corresponding standard power is 0-10V, and the temperature value to be detected is 0-100°C. Then 0-32767 corresponds to a temperature value of 0-100°C. Then calculate the digital quantity corresponding to 1℃ is 327.67. If you want to make the temperature value accurate to 0.1℃, just set 327.67/10.

Analog control includes: feedback control, feedforward control, proportional control, fuzzy control, etc. These are the calculation processes of the digital quantities inside the PLC.

3. The pulse quantity is a digital quantity whose value always alternates between 0 (low level) and 1 (high level). The number of alternating pulses per second is called frequency.

The main purpose of PLC pulse control is position control, motion control, trajectory control, etc. For example: the application of pulse number in angle control. The subdivision of the stepper motor driver is 10,000 per revolution, requiring the stepper motor to rotate 90 degrees. Then the pulse value to be actuated=10000/(360/90)=2500.

PLC programming algorithm (2)-calculation of analog quantity

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

2. 0-10V. When the voltage is 0-10V, it will be converted to 0-1770Hex (0-6000) at 12000 resolution; it will be converted to 0-2EE0Hex (0-12000) at 12000 resolution.

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

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

The above is only a brief introduction. Different PLCs have different resolutions, and the range of physical quantities you measure is different. The calculation results may have certain differences.

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

3. The analog signal line is isolated from the power line (AC power line, high voltage line, etc.).

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

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

6. When power off, first cut off the power supply of the load, and then cut off the power supply of the CPU.

PLC programming algorithm (3)-calculation of pulse volume

Pulse control is mostly used for angle control, distance control, position control of stepper motors and servo motors. The following takes a stepper motor as an example to illustrate each control method.

1. Angle control of stepping motor. First of all, we must clarify the number of subdivisions of the stepper motor, and then determine the total number of pulses required for the stepper motor to make one revolution. Calculate "angle percentage = set angle/360° (ie one circle)" "angle action pulse number = total pulse number of one circle * angle percentage."

The formula is:

Angle action pulse number = total pulse number in a circle * (set angle/360°).

2. Distance control of stepping motor. First clarify 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 circumference of the roller. Calculate the travel distance of each pulse. Finally, calculate the number of pulses to be run for the set distance.

The formula is:

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

3. The 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 method of the stepper motor, which may be different from the actual situation, for your reference only.

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