PLC Programming Algorithm
(1): Discrete Signals
In PLC systems, there are primarily three types of signals: discrete (or digital), analog, and pulse. Understanding the relationships among these three types is essential for mastering PLC control.
- Discrete Signals: Also known as logical signals, these involve binary states, 0 or 1, ON or OFF. Discrete signal control is fundamental to PLCs and represents the basic application of PLC technology.The goal of discrete signal control is to generate corresponding output signals based on the current combination of input signals and their historical sequence, enabling the system to operate in a predetermined order. This is often referred to as sequential control.Sequential control can be manual, semi-automatic, or fully automatic. The control strategies can be decentralized, centralized, or hybrid.
- Analog Signals: These refer to continuously varying physical quantities such as voltage, current, pressure, speed, and flow rate.PLCs, originally developed from relay control systems using microprocessor technology, handle discrete signals efficiently. Analog signals, after conversion to digital signals (which are essentially multi-bit discrete signals), can also be reliably processed by PLCs.Because many continuous processes involve analog signals, this type of control is sometimes called process control.When the target signals are not standard, they must be converted into standard electrical signals such as 4-20mA, 1-5V, or 0-10V. Analog input units (A/D converters) convert these standard electrical signals into digital signals, while analog output units (D/A converters) convert digital signals back into standard electrical signals for control.The conversion between standard electrical signals and digital signals involves various calculations. Understanding the resolution of the analog units and the standard electrical signals is necessary.For example, if a PLC analog unit has a resolution of 1/32767 and corresponds to a standard electrical range of 0-10V, to measure a temperature range of 0-100°C, the digital value 0-32767 corresponds to 0-100°C. Hence, each degree Celsius corresponds to 327.67 digital units. If you want to measure to 0.1°C accuracy, you would use 327.67 / 10.Analog signal control includes feedback control, feedforward control, proportional control, and fuzzy control.
- Pulse Signals: These signals alternate continuously between 0 (low) and 1 (high). The frequency, or the number of pulses per second, is a key characteristic.Pulse signal control is mainly used for position control, motion control, and trajectory control. For example, in angle control of a stepper motor with 10,000 pulses per revolution, to rotate 90 degrees, the required number of pulses = 10000 / (360 / 90) = 2500.
(2): Analog Signal Calculation
- Voltage Range -10V to 10V: At a resolution of 6000, it converts to F448—0BB8Hex (-3000—3000); at 12000 resolution, it converts to E890—1770Hex (-6000—6000).
- Voltage Range 0V to 10V: At a resolution of 6000, it converts to 0—1770Hex (0—6000); at 12000 resolution, it converts to 0—2EE0Hex (0—12000).
- Current Range 0mA to 20mA: At a resolution of 6000, it converts to 0—1770Hex (0—6000); at 12000 resolution, it converts to 0—2EE0Hex (0—12000).
- Current Range 4mA to 20mA: At a resolution of 6000, it converts to 0—1770Hex (0—6000); at 12000 resolution, it converts to 0—2EE0Hex (0—12000).
The above examples illustrate the general principle. Different PLCs may have different resolutions and physical measurement units, leading to slight variations in the calculation results.
Note on Analog Input Wiring Requirements:
- Use shielded twisted-pair cables, but do not connect the shielding layer.
- If an input is not used, short the VIN and COM terminals.
- Isolate the analog signal lines from power lines (AC power lines, high-voltage lines, etc.).
- If there is interference on the power lines, install a filter between the input section and the power unit.
- After confirming the correct wiring, first power the CPU unit, then the load.
- When powering off, first cut off the load power, then the CPU power.
(3): Pulse Signal Calculation
Pulse signal control is commonly used for the angle, distance, and position control of stepper motors and servo motors. Here are examples using stepper motors:
- Angle Control: Determine the stepper motor’s subdivision number and the total number of pulses required for one revolution. Calculate the angle percentage = set angle / 360° (one revolution), and the pulse count for the angle = total pulses per revolution * angle percentage.Formula: Pulse count for angle = total pulses per revolution * (set angle / 360°).
- Distance Control: Determine the total pulses required for one revolution of the stepper motor, the roller diameter, and the roller circumference. Calculate the distance per pulse and then the pulse count for the set distance.Formula: Pulse count for set distance = set distance / [(roller diameter * 3.14) / total pulses per revolution].
- Position Control: This is a combination of angle control and distance control.
Servo motors operate similarly to stepper motors but require consideration of the internal electronic gear ratio and the reduction ratio of the servo motor.