0
0
FreertosHow-ToBeginner · 4 min read

How to Write Analog Output in PLC: Simple Guide

To write an analog output in a PLC, use the AnalogOutput instruction or assign a value directly to the analog output variable representing the output channel. This value usually ranges within the device's scale, such as 0-100% or 0-10V, depending on the hardware configuration.
📐

Syntax

The basic syntax to write an analog output in a PLC program involves assigning a value to the analog output variable or using a dedicated instruction like AnalogOutput(channel, value). Here, channel is the output channel number, and value is the analog value to send.

  • channel: Identifies which analog output port to write to.
  • value: The numeric value representing the analog signal, often scaled to the hardware range.
plc
AnalogOutput(1, 500);
💻

Example

This example shows how to write a 4mA to 20mA analog output signal scaled from 0 to 1000 in a PLC program. The value 500 represents 12mA (midpoint).

plc
VAR
  AnalogValue : INT;
END_VAR

// Assign midpoint value to analog output channel 1
AnalogValue := 500;
AnalogOutput(1, AnalogValue);
Output
Analog output channel 1 set to value 500 (approx. 12mA)
⚠️

Common Pitfalls

Common mistakes when writing analog outputs include:

  • Writing values outside the allowed range, causing unexpected output.
  • Not scaling the value correctly to match the hardware's voltage or current range.
  • Forgetting to configure the output channel properly in the PLC hardware setup.

Always check your PLC documentation for the correct value range and channel setup.

plc
/* Wrong: Value out of range */
AnalogOutput(1, 2000);  // May cause error or max output

/* Correct: Value within range */
AnalogOutput(1, 1000);  // Max allowed value
📊

Quick Reference

ConceptDescription
AnalogOutput(channel, value)Function to write analog value to output channel
Value RangeMust match hardware specs (e.g., 0-1000 for 4-20mA)
Channel NumberIdentifies which output port to write
ScalingConvert physical units to PLC value range
Hardware SetupConfigure output module before use

Key Takeaways

Always assign analog output values within the hardware's specified range.
Use the correct output channel number when writing analog signals.
Scale your values to match the PLC hardware's voltage or current range.
Configure your analog output module properly before writing values.
Test outputs carefully to avoid hardware damage or unexpected behavior.