Analog and Digital Signal Handling in SCL

Analog and Digital Signal Handling in SCL

Introduction

Analog and digital signals are fundamental aspects of industrial controls and automation systems. Handling these signals effectively in Structured Control Language (SCL) is crucial for developing robust and efficient PLC programs. In this article, we'll explore the essentials of reading and writing analog and digital signals, along with practical examples and best practices.

Advice for Beginners in Signal Handling

Start with simple functions and develop a systematic approach to signal processing. Create a map or flowchart of how you will handle most signals to ensure consistency and reliability in your programs.

Reading Analog Input Signals in SCL

Reading analog input signals involves bringing in raw values, converting them to engineering units, and processing them for further use.

Common Pitfalls in Signal Processing

A common issue is not knowing the scaling of the analog device in the field. It's crucial to understand the scaling parameters so you can accurately scale your code to match the actual device behavior.

Accurate Analog Input Reading Strategies

To read analog input signals accurately:

  1. Bring in Raw Value: Capture the raw analog input value.
  2. Process Value Conversion: Use the engineering value to process the raw value conversion.
  3. Develop an Averaging Function: Implement an averaging function to smooth out the signal.
  4. Implement Logic: Apply the necessary logic to use the processed value in your control system.

Converting Analog Input Signals

When converting analog input signals for processing in PLCs:

  1. Use Floating (or REAL) Values: For precise calculations, use floating-point values.
  2. Memory Optimization: To save memory, consider using integer scaling techniques. For example, use an integer of 32767 to represent 327.67, which allows for smaller memory usage as long as the values are within an appropriate range.

Example: Reading an Analog Input

FUNCTION_BLOCK FB_ReadAnalogInput
VAR_INPUT
   AnalogRaw : INT;     // Raw analog input value
END_VAR

VAR_OUTPUT
   AnalogEng : REAL;    // Converted engineering value
END_VAR

VAR
   EngMin : REAL := 0.0;   // Minimum engineering value
   EngMax : REAL := 100.0; // Maximum engineering value
   RawMin : INT := 0;      // Minimum raw value
   RawMax : INT := 27648;  // Maximum raw value (assuming 16-bit resolution)
END_VAR

BEGIN
   // Convert raw value to engineering units
   AnalogEng := (AnalogRaw - RawMin) * (EngMax - EngMin) / (RawMax - RawMin) + EngMin;
END_FUNCTION_BLOCK
        

In this example, AnalogRaw is the raw analog input value, and AnalogEng is the converted engineering value. The conversion formula scales the raw value to a meaningful engineering unit range.

Practical Tip: Bring in raw value, use engineering value for process value conversion, develop an averaging function, and implement the logic.

Writing Analog Output Signals in SCL

Writing analog output signals is similar to reading inputs but involves converting a processed value back to a raw format suitable for output.

Approach to Writing Analog Output Signals

Writing analog output signals involves:

  1. Processing Value: Use the processed engineering value.
  2. Output Filtering: Apply output filtering based on the process requirements to ensure stable outputs.

Critical Role of Analog Output Signals

Analog output signals are essential for various control applications, such as:

  • Drives: Controlling motor drives.
  • Proportional Valves: Adjusting flow rates or pressures.
  • Analog Output Blocks: Communicating with other control devices.
  • Logical Controls: Integrating function outputs for use in other control functions.

Example: Writing an Analog Output

FUNCTION_BLOCK FB_WriteAnalogOutput
VAR_INPUT
   AnalogEng : REAL;    // Input engineering value
END_VAR

VAR_OUTPUT
   AnalogRaw : INT;     // Raw analog output value
END_VAR

VAR
   EngMin : REAL := 0.0;   // Minimum engineering value
   EngMax : REAL := 100.0; // Maximum engineering value
   RawMin : INT := 0;      // Minimum raw value
   RawMax : INT := 27648;  // Maximum raw value (assuming 16-bit resolution)
END_VAR

BEGIN
   // Convert engineering value to raw format
   AnalogRaw := INT((AnalogEng - EngMin) * (RawMax - RawMin) / (EngMax - EngMin) + RawMin);
END_FUNCTION_BLOCK
        

In this example, AnalogEng is the input engineering value, and AnalogRaw is the converted raw value for output.

Practical Tip: It's almost an inverse of reading analog input signals, but instead of averaging, use output filtering based on the process.

Handling Digital Input Signals in SCL

Digital input signals are straightforward to handle, but it's essential to ensure accurate conversion and processing.

Example: Reading a Digital Input

FUNCTION_BLOCK FB_ReadDigitalInput
VAR_INPUT
   DigitalIn : BOOL;    // Digital input signal
END_VAR

VAR_OUTPUT
   ProcessedValue : REAL;  // Processed value
END_VAR

BEGIN
   // Convert digital input to a floating-point value for processing
   IF DigitalIn THEN
      ProcessedValue := 1.0;
   ELSE
      ProcessedValue := 0.0;
   END_IF;
END_FUNCTION_BLOCK
        

In this example, DigitalIn is the digital input signal, and ProcessedValue is the floating-point value used for further processing.

Practical Tip: Use floating (or real) values for calculations. If a value is an integer, it makes precise math difficult. To save memory, you can use an integer of 32767 to be equivalent to 327.67, allowing for smaller memory usage as long as the number isn't going to be large.

Generating Digital Output Signals in SCL

Generating digital output signals involves setting the output based on specific conditions.

Example: Writing a Digital Output

FUNCTION_BLOCK FB_WriteDigitalOutput
VAR_INPUT
   Condition : BOOL;    // Condition to set output
END_VAR

VAR_OUTPUT
   DigitalOut : BOOL;   // Digital output signal
END_VAR

BEGIN
   // Set digital output based on condition
   DigitalOut := Condition;
END_FUNCTION_BLOCK
        

In this example, Condition is the input condition, and DigitalOut is the digital output signal.

Real-world application: Controls for drives, proportional valves, analog output blocks to other controlling items, and function outputs can be used for logical controls in other functions.

Practical Example: Signal Processing in an Automation System

Let's combine the concepts discussed above in a real-world example: controlling a motor's speed based on analog input and output signals.

FUNCTION_BLOCK FB_MotorControl
VAR_INPUT
   SpeedInput : INT;       // Raw speed input (analog)
   StartButton : BOOL;     // Start button (digital)
   StopButton : BOOL;      // Stop button (digital)
END_VAR

VAR_OUTPUT
   MotorSpeed : INT;       // Raw motor speed output (analog)
   MotorStatus : BOOL;     // Motor status (digital)
END_VAR

VAR
   SpeedEng : REAL;        // Engineering speed value
   Setpoint : REAL := 50.0; // Desired speed setpoint
   Running : BOOL;         // Motor running state
END_VAR

BEGIN
   // Convert raw speed input to engineering units
   SpeedEng := (SpeedInput - 0) * (100.0 - 0.0) / (27648 - 0) + 0.0;
   
   // Start/Stop logic
   IF StartButton AND NOT Running THEN
      MotorStatus := TRUE;
      Running := TRUE;
   ELSIF StopButton THEN
      MotorStatus := FALSE;
      Running := FALSE;
   END_IF;

   // Set motor speed if running
   IF Running THEN
      MotorSpeed := INT((Setpoint - 0.0) * (27648 - 0) / (100.0 - 0.0) + 0);
   ELSE
      MotorSpeed := 0;
   END_IF;
END_FUNCTION_BLOCK
        

Common Pitfalls: People often don't know the scaling of the analog device in the field. It is important to know this information so you can scale your code accurately.

Ensuring Reliable Signal Processing

In extreme or hazardous environments, the wiring of your signals matters a lot. Here are a few tips for ensuring reliability of your signals in the field:

  1. Use Fuses: Protect input power and output signals with appropriate fuses.
  2. Correct Wiring: Use the correct type of wire for the environmental conditions.
  3. Shielding: Employ shielding to reduce electrical noise and interference.
  4. 4-20mA Signals: Use 4-20mA signals for better accuracy and noise resistance.
  5. Redundancy: By using redundancy, you can create backup control methods, and signal differential handling.
  6. Advanced Communications: Utilize communication protocols like Profinet, Profibus, or IO-Link for more reliable data transmission.

Troubleshooting Tools and Methods

Often, in the field, you will need to troubleshoot signal handling issues. Some field instruments you may use are:

  1. Voltmeters: Measure voltage levels.
  2. Amprobes: Measure current flow.
  3. Process Meters: Source and sync analog signals for testing.

Function Block for Fill Valve Control

Explanation

  • Level Signals: Level1 and Level2 are the signals from the two level detectors.
  • UseLevel1: This boolean input selects which level detector to use for control.
  • Alarms: The program checks the difference between the levels and the rate of change difference to trigger alarms.
  • Safety Interlock: The SafetyInterlock, AlarmDiff, or AlarmRate conditions will disable the fill valve and set the output to 0.
  • Control Logic: The fill valve output is controlled proportionally based on the selected level signal.

Usage

  1. Inputs: Connect the level signals (Level1, Level2), and set UseLevel1 to select the controlling level detector.
  2. Alarms: Monitor AlarmDiff and AlarmRate for any discrepancies or issues.
  3. Safety Interlock: Use the SafetyInterlock input to disable the fill valve in case of emergencies or maintenance.

FUNCTION_BLOCK FB_FillValveControl
VAR_INPUT
   Level1 : REAL;         // Level signal from detector 1
   Level2 : REAL;         // Level signal from detector 2
   UseLevel1 : BOOL;      // Selector for using Level1 or Level2
   MaxDiff : REAL := 5.0; // Maximum allowable difference between levels
   MaxRateDiff : REAL := 0.2; // Maximum allowable difference between rates of change
   SafetyInterlock : BOOL; // Safety interlock signal
END_VAR

VAR_OUTPUT
   FillValve : REAL;      // Proportional output to fill valve
   AlarmDiff : BOOL;      // Alarm for level difference
   AlarmRate : BOOL;      // Alarm for rate of change difference
   ActiveLevel : REAL;    // Active level used for control
END_VAR

VAR
   PrevLevel1 : REAL := 0.0;  // Previous level 1 value for rate calculation
   PrevLevel2 : REAL := 0.0;  // Previous level 2 value for rate calculation
   RateLevel1 : REAL;         // Rate of change for level 1
   RateLevel2 : REAL;         // Rate of change for level 2
   SelectedLevel : REAL;      // Selected level based on UseLevel1 input
END_VAR

BEGIN
   // Select the active level based on the input selector
   IF UseLevel1 THEN
      SelectedLevel := Level1;
   ELSE
      SelectedLevel := Level2;
   END_IF;
   
   // Calculate the rate of change for both level signals
   RateLevel1 := ABS(Level1 - PrevLevel1);
   RateLevel2 := ABS(Level2 - PrevLevel2);
   
   // Update previous level values for the next cycle
   PrevLevel1 := Level1;
   PrevLevel2 := Level2;
   
   // Check for the difference alarm
   AlarmDiff := ABS(Level1 - Level2) > MaxDiff;
   
   // Check for the rate of change difference alarm
   AlarmRate := ABS(RateLevel1 - RateLevel2) > MaxRateDiff;
   
   // Safety interlock logic
   IF SafetyInterlock OR AlarmDiff OR AlarmRate THEN
      FillValve := 0.0;   // Disable the fill valve
   ELSE
      FillValve := SelectedLevel;   // Control the fill valve proportionally
   END_IF;
   
   // Update the active level for monitoring
   ActiveLevel := SelectedLevel;
END_FUNCTION_BLOCK        

Final Thoughts

Handling analog and digital signals effectively is crucial for developing robust PLC programs. By understanding the process of reading and writing these signals in SCL, you can create more efficient and reliable control systems.

About the Author

Ken Jensen brings over 24 years of experience in electrical, automation, & controls engineering across diverse industries like nuclear, steel, and glass. He is a highly skilled problem-solver with expertise in electrical systems, PLCs, SCADA, and Industry 4.0 technologies. He is adept at leading projects, driving innovation, and fostering collaboration.

Thanks for sharing your knowledge and thoughts.

回复

要查看或添加评论,请登录

Kenneth Jensen的更多文章

  • Understanding State Machines in SCL

    Understanding State Machines in SCL

    Understanding the Concept of State Machines A state machine is a computational model used to design algorithms that…

  • Error Handling and Fault Diagnostics in SCL

    Error Handling and Fault Diagnostics in SCL

    Introduction Error handling and fault diagnostics are crucial components of reliable automation systems. Properly…

  • Defining Data Types and UDTs in SCL

    Defining Data Types and UDTs in SCL

    Introduction Defining data types and user-defined types (UDTs) is fundamental to developing robust and maintainable PLC…

  • Developing and Testing Custom Function Blocks in SCL

    Developing and Testing Custom Function Blocks in SCL

    Introduction Custom function blocks are a powerful feature in SCL that enable the creation of modular, reusable code…

  • PID Control in SCL

    PID Control in SCL

    Introduction PID control (Proportional, Integral, Derivative) is a fundamental control technique in automation. It…

  • Creating Ramps in SCL

    Creating Ramps in SCL

    Introduction Ramp functions are essential for controlling the rate of change in various automation processes. They are…

  • Mastering SCL Variables

    Mastering SCL Variables

    Introduction Variables are essential elements in PLC programming, used to store and manipulate data. In Structured…

  • Implementing Latches in SCL

    Implementing Latches in SCL

    Introduction Latches are a fundamental concept in PLC programming, used to maintain a state or hold an output until a…

  • Getting Started with Timers and Counters in SCL

    Getting Started with Timers and Counters in SCL

    Introduction Timers and counters are fundamental elements in PLC programming, essential for creating delays, counting…

  • Introduction to SCL: A PLC Programmer's Guide

    Introduction to SCL: A PLC Programmer's Guide

    Introduction to the Series Welcome to the first article in my series on developing with Structured Control Language…

    4 条评论

社区洞察

其他会员也浏览了