PLC Programming Algorithm

Siemens PLC

(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.

  1. 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.
  2. 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.
  3. 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

  1. 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).
  2. 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).
  3. 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).
  4. 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:

  1. Use shielded twisted-pair cables, but do not connect the shielding layer.
  2. If an input is not used, short the VIN and COM terminals.
  3. Isolate the analog signal lines from power lines (AC power lines, high-voltage lines, etc.).
  4. If there is interference on the power lines, install a filter between the input section and the power unit.
  5. After confirming the correct wiring, first power the CPU unit, then the load.
  6. 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:

  1. 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°).
  2. 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].
  3. Position Control: This is a combination of angle control and distance control.
Motor

Servo motors operate similarly to stepper motors but require consideration of the internal electronic gear ratio and the reduction ratio of the servo motor.

Shopping Cart