0
0
FreertosHow-ToBeginner · 4 min read

How to Read Analog Input in PLC: Simple Guide

To read an analog input in a PLC, use the Analog Input module address or tag in your program and convert the raw value to engineering units if needed. Typically, you read the input as a numeric value from the assigned channel or input register using the PLC's programming language.
📐

Syntax

Reading an analog input in a PLC usually involves accessing the input channel or register where the analog signal is stored. The syntax depends on the PLC brand and programming language but generally looks like this:

  • AI_Channel: The address or tag for the analog input channel.
  • RawValue: The raw numeric value read from the analog input.
  • ScaledValue: The converted value in engineering units (e.g., volts, temperature).

Example syntax in ladder logic or structured text:

ScaledValue := (RawValue / MaxRaw) * MaxEngineeringValue;
structured_text
(* Structured Text example for reading analog input *)
RawValue : INT; (* Raw analog input value from channel *)
ScaledValue : REAL; (* Converted engineering value *)

RawValue := AI_Channel; (* Read raw input from analog channel *)
ScaledValue := (REAL(RawValue) / 27648.0) * 10.0; (* Scale raw value to 0-10V range *)
💻

Example

This example shows how to read an analog input from channel 1, convert the raw value to a voltage between 0 and 10 volts, and store it in a variable.

structured_text
(* Example PLC Structured Text code to read analog input and scale it *)
VAR
    RawValue : INT; (* Raw analog input from channel 1 *)
    Voltage : REAL; (* Scaled voltage value *)
END_VAR

RawValue := AI_Channel1; (* Read raw analog input *)
Voltage := (REAL(RawValue) / 27648.0) * 10.0; (* Convert raw to 0-10V scale *)
Output
If AI_Channel1 = 13824 then Voltage = 5.0
⚠️

Common Pitfalls

  • Not scaling the raw analog value correctly leads to wrong readings.
  • Using incorrect channel addresses or tags causes no data or errors.
  • Ignoring the PLC's raw value range (e.g., 0-27648 or 0-32767) results in wrong conversions.
  • Failing to configure the analog input module properly in hardware setup.

Always check your PLC documentation for the exact raw value range and channel naming.

structured_text
(* Wrong scaling example *)
Voltage := (REAL(RawValue) / 32767.0) * 10.0; (* Incorrect if max raw is 27648 *)

(* Correct scaling example *)
Voltage := (REAL(RawValue) / 27648.0) * 10.0;
📊

Quick Reference

TermDescription
AI_ChannelAnalog input channel or tag to read raw data
RawValueRaw numeric value from analog input (e.g., 0-27648)
ScaledValueConverted value in engineering units (e.g., volts)
MaxRawMaximum raw value from the PLC analog input module
MaxEngineeringValueMaximum value in engineering units (e.g., 10V)

Key Takeaways

Always read the raw analog input value from the correct channel or tag.
Scale the raw value to engineering units using the module's max raw range.
Verify your analog input module configuration before programming.
Check your PLC documentation for exact raw value ranges and scaling formulas.