SIEMENS SIMATIC S7 + WINCC

Analog Input




Analog Inputs and Outputs Signals


Analog signals are widely used in PLC programs. A PLC can only work with values 0 and 1.

This is great for digital signals. They are 0 or 1 and therefore relatively easy to work with. But what about analog signals? Analog signals are continuous signals that can vary over time.

For example, you can have an analog signal from 0 to 10 volts. This signal can vary from 0 to 10 volts and have any voltage level in between. And since analog signals are continuous, this signal always represents a voltage level at any time. If you look at the diagram below, you will see that the analog signal can have any value between 0 and 10 volts.



The question now is: how does a PLC handle all these different values?

Let's say you have a 5-volt analog signal on the PLC. We cannot represent it with Boolean values, because they can only have the values 0 and 1.

The answer is binary numbers!


Representing analog signals with binary numbers

As mentioned earlier, a PLC can only work with the two values 0 and 1. But this prevents us from working with analog signals. Because what is really happening is that the PLC works with binary numbers. This is due to the fact that a PLC or a microcontroller are really just advanced electrical circuits made of transistors. As a transistor can only be activated or deactivated, these two states represent the values 0 and 1.

But that gives us only two states. Very useful for digital signals, but not for analog. To understand how analog inputs work on a PLC, you need to understand binary numbers.

Binary numbers is the numbering system used by a PLC or any other computer. The system has only two numbers, compared to the 10 base numbering system, where we have 10 numbers from 0 to 9. Binary is just another way of writing numbers.


Bits and bytes

A single digit binary number is called a bit. A bit can contain 0 or 1.

If you combine these bits and create multi-digit numbers, things start to get interesting.

In many PLCs, an analog signal is represented by a word (2 bytes). A binary word with zeros looks like this:

00000000 00000000

A 16-digit binary number can represent values from 0 to 65,535. This is only half the truth for PLCs. The first bit is used to signal the number, providing a positive or negative value.

Therefore, with 1 bit for the signal, we have 15 bits remaining to represent the analog value. The binary number can therefore represent values from -32,768 to 32,767.


A/D converter

When the analog input signal enters the PLC, it passes through an A/D converter or analog to digital converter.

This is the component on the PLC's analog input board that transforms the analog signal into digital signals. It is these digital signals that will eventually provide our representation of binary value on the PLC.

Before getting to know the A/D converter, it is important to understand what type of analog signal you are dealing with.

The three most common types of analog signals in PLC programming are:

• Voltage

• Current

• Resistance

The reason we need to know about the type of signal is because we need to know the range of the signal. A widely used type of analog signal is 4-20mA.



In the 4-20mA signal there is a range of 16mA (20mA - 4mA). An analog value is often placed in a 16-bit word on a PLC. This is because the A/D converter converts the analog signal to a 16-bit digital value.

You can buy analog input cards with different resolutions. This depends on how many bits the A/D converter needs to work. More bits gives us more numbers to represent the analog signal.


Resolution of analog signals

The number of bits you need to save in the analog value is called the resolution.

Think of it as your TV. It also has only a certain amount of pixels to represent an image. The same is true with analog to digital conversion. Just as we call resolution when talking about the number of pixels on television, we also call resolution when talking about analog values represented by a number.

Resolution is very important when dealing with analog signals in PLC programming. Upon entering the analog input card, the analog signal will be divided into a value between 0 and 32,767. Dividing the analog value by 32,767 gives us a certain resolution.

Every time our value increases by 1, it means that the analog signal has increased by x mA.


Analog Signal Range

Analog signals tend to be very sensitive. Although it is our intention that a signal range is 4-20mA, the signal can sometimes exceed these limits. When that happens, we want to be able to see it on the PLC. While not always the case, these overflows can mean that something is wrong. In order to detect them in the PLC program, we need what is called overflow and underflow of the range.



Our normal range or nominal range is 4-20mA. But above and below that, some extra mA is usually added to the range. They divide the upper range into these two categories:

• Overshoot range (overrange)

• Overflow

And the lower range in these two:

• Undershoot range (underrange)

• Underflow

What this means is that, instead of a 4-20 mA range, we now have a range of 1.185 - 22.96 mA. The same applies to other types of analog signals. For example. the range from 0 to 10V is from 0 to 11.852 V. All of this means that our analog signal ranges can be illustrated like this:



With overflow and underflow in mind, we can now start calculating the actual resolution of our analog signal. But instead of just using the 22.96-1.185 mA or 11.852 V ranges, there is a number that you should note here: 27,648.

As you can see in the table above, this is where our classified range ends. Our resolution for a 0 to 10 V signal must therefore be calculated as follows:

10 V / 27648 = 361,7 μV

Or for our 4-20 mA signal:

16 mA / 27648 = 578,7 nA

These two numbers are the minimum values that we can represent in the CLP with the digital value. In most cases, these measurements are small and accurate enough. Also remember that the higher resolution you want, the more expensive the PLC analog input and output modules.

Analog Inputs

Analog inputs can come from a variety of sensors and transmitters, or both. For example, one of the types of thermocouples connected to a transmitter, which is then connected to an analog input on the PLC. You can measure a lot of different things. The job of the sensor or transmitter is to turn this into an electrical signal. Here are some of the things you can measure with analog sensors:

• Level

• Flow

• Distance

• Viscosity

• Temperature

• Pressure

The main point is that the sensor or the transmitter turns the physical values into an analog signal. It is this signal that we can use on the PLC as an analog input.

An example here could be a temperature transmitter with a 4-20 mA output. Connected to the transmitter is a temperature sensor. The transmitter is then calibrated to a range of 0-100 degrees. What this means is that when the temperature is 0 degrees, the transmitter's output will be 4 mA and 20 mA per 100 degrees.

A transmitter is often necessary because the sensor itself cannot provide us with an analog signal. Or at least not one that fits the PLC's analog input. It is possible to buy analog input modules where you can directly connect a temperature sensor. But, most of the time, you will have a voltage or current input module to which you will connect a transmitter.



Calibration is very important when talking about transmitters. You need to know how much these mA or volts represent in the physical value.

Analog inputs wiring

Analog voltage input wiring

The use of voltage for analog signals is quite common. They are also quite easy to connect, as you usually only need two wires. But that does not mean that you should not be careful when connecting this type of analog signal. If it is not connected correctly, you may get a defective analog signal or, worse, a damaged analog input module.

Therefore, basically all analog voltage inputs have two terminals:

• AGND: The ground or reference for analog inputs

• AIN: Analog input

The tension is always measured between two points. You cannot take a point and then say: at this point I can measure 10 volts. For that, you need a point of reference. Like a battery. A 9-volt battery has only 9 volts between the positive and negative sides.

That's why we use AGND or analog ground. It is between AGND and AIN that the PLC measures how many volts there are at the analog input. It also gives us the answer to what AIN is.

When you are connecting the analog voltage source, the AIN is where you connect the positive (+) side of it. The negative side (-) must be connected to the AGND. These are the two main wires of the analog signal.

But if you connect only these two, you will have a very vulnerable signal. Electromagnetic compatibility (EMC) can easily change the analog signal.

As you can see below, this is resolved by protecting the wires and connecting the shield to the ground. Be aware that this is NOT the same ground as AGND!



The fact is that not all lands are equal. Where AGND is used as a reference for our analog signal (0 volt), the shield must be connected to earth. Because the noise is really just current induction in the wires because of the magnetic fields. Using a shield, the current will be induced in the shield, instead of the wires of our analog signal. This current needs to be removed and that is why we connect the shield to the ground.

Voltage drop in wires

As we are dealing with voltage here, there is something in the wiring itself that can cause problems. All electrical wires (conductors) have resistance and therefore create a voltage drop. This can potentially mean that the voltage at the analog input is different from the voltage at the transmitter. Obviously, this only has a significant consequence if you have long wiring distances or very small wires.


Current analog input wiring

Instead of voltage, you can also use the current as an analog signal. They may be a little more difficult to connect, but in general they are more stable. Especially one of them has a very smart feature that probably makes it the most used type of analog signal.

The current in the analog signals is usually measured in milliamps (mA). A typical range here is between 0 and 20 mA. Less than that would be difficult to measure and more than that would soon become dangerous.

Let's take a look at what it really means to use current in analog signals.

First of all, you need a closed loop for the current to flow. Although the wiring for the first type of current transmitter is the same as the voltage, something different happens here. Current is the flow of electrons from one pole to another. That is why you will always need a closed circuit to measure the current.


Resistor Shunt

In fact, the PLC cannot even measure the current. So what happens is that, inside the analog input module, a resistor is placed between the positive (AI) and the negative (AGND). This not only makes up the closed circuit, but also converts our current signal into a voltage signal.



The resistor is called a shunt resistor and has a specific resistance. In some analog input modules it is 250 Ohm, for example. And, due to Ohm's law, the analog current signal can now be converted into a voltage signal by simple calculations.

Voltage (V) = Resistance (R) x Current (I)

As we have a well-known resistance of 250 Ohm, it is also possible to calculate how many milliamps our measured voltage corresponds to. With this scenario in mind, let's take a look at the wiring of the analog current inputs. They can generally be divided into three types:

• 2-wire analog input

• 3-wire analog input

• 4-wire analog input

When talking about 2, 3 and 4 wires, what we are talking about here are actually the transmitters or transducers. Current transmitters can be connected in different ways and therefore with a different number of wires. The difference is actually the signal power supply. Sometimes the transmitter will power the circuit and sometimes you will need to use an external source.


2-wire analog input

The first and simplest way to connect a 2-wire transmitter is to connect it to the loop supply. Basically, this means that the PLC will supply the current loop. Only 2 wires are needed here. For the PLC to supply the current, we need to use another terminal on the analog input module:

A+: Analog input source

A wire that passes from A + through the transmitter and back on another wire to AIN. The source comes from A +, the transmitter controls the current flow and the analog current signal enters AIN.



You can also use an external power supply for the 2-wire transmitter. Connect 0 V from the source to the AGND and 24 V through the transmitter back to the AIN. Although you practically need 3 wires for this, it is still considered a 2-wire analog input connection, because the transmitter has only two wires.



A disadvantage of 2-wire current loops is that you only have one loop for the power and signal. In fact, this means that the transmitter needs to draw less than 4 mA to function. Some sensors and transmitters consume more than that, which leads us to 3 and 4 wire loops.


3-wire analog input

In a 3-wire current circuit, only the ground is shared between the source and the signal. The ground is connected to the AGND and the power supply (-). The transmitter has 2 positive wires (+). One that goes to the power supply (+) and the other to AIN.



Although they share the ground, a 3-wire transmitter creates 2 loops. One for the signal and the other for power. The sensor or transmitter can now consume the required amount of current without interfering with the analog signal.


4-wire analog input

The 4-wire transmitter is also widely used, as it separates the power supply from the signal. When supplying the transmitter with 4 wires, you can have 2 for the power and 2 for the signal. Naturally, the 4-wire transmitter requires an external power supply.



Clearly, the biggest advantage of using a 4-wire transmitter is the complete separation between power and signal. They can be totally isolated or opto-isolated, so that the disturbance in the feeding does not affect the signal.


Analog input scale

When the analog input signal enters the PLC, you often need to scale it up in your PLC program. What the scale means is that you convert the raw value of the analog input into some kind of engineering value. An engineering value is a number that represents the physical value, for example flow (m3/s), weight (kg) or temperature (degrees).

Conversion or escalation is done simply with a few accounts. Some software (IDE) even have a functional block specifically for scheduling.

Scaling with math

The analog signal becomes a raw value in the PLC, but that number actually represents nothing but, for example, a number between 0 and 27648. What the analog signal represents is a physical measurement like 0 to 300 degrees. It will often be necessary to work with the engineering value in our PLC program or to show the measurement on an HMI.

Somehow, we have to convert the range 0-27648 to 0-300.

Mathematically, we can describe it with this relationship:

Gross Value / 27648 = Engineering Value / 300

By isolating the value of engineering, we now obtain an equation that we can use directly in our PLC program. This equation can be used to scale the analog input to the engineering value:

Engineering value = (Gross value / 27648) * 300


Analog Outputs

Analog outputs have many similarities to analog inputs. However, there are still some differences in the way you connect them and the way you use them in your PLC program. Analog outputs can be divided into two types:

• Voltage

• Current

Or we use voltage or current as an analog signal.


Analog outputs wiring

No matter what type of analog output you are using, there is always one thing to keep in mind. Load. Because you will essentially connect a load to the output. It can be a flow control valve, a frequency inverter or even an analog input in another PLC.

The device you connect to your analog output is the one that decides what type of analog signal you should use. If you want to control a valve with a 4-20 mA signal, its analog output must also be 4-20 mA.


oltage analog output wiring

Again, the analog voltage output is the easiest to connect. For this, you will only need 2 wires. A positive and a negative side of the voltage source. See how a simple 2-wire analog voltage output is connected:



But sometimes 2 wires are simply not enough even for voltage outputs. Some analog output modules have two extra terminals on their analog outputs. They are used to compensate for something called line impedance or resistance. Impedance is the opposition that a circuit presents to changes in current or voltage. Since we are dealing with tension, any resistance will create a voltage drop.

If you have an analog voltage signal that changes the resistance, it is even greater. These two additional wires exist to compensate, so that the voltage level at the analog output is the same as the voltage level at the destination.



Talking about resistance, there is also something else you should be aware of when dealing with analog voltage outputs: load impedance. To avoid a short circuit on the analog output, the load connected to the output must have a minimum load impedance. This is usually between 500 and 1k Ohm.


Current analog output wiring

Most analog outputs on the PLCs function as a 3-wire transmitter. This may seem strange, since we only had 2 wires so far. But the PLC usually provides an internal power supply, giving us the third wire. The power for the signal.

This means that when you are working with current outputs, most of the time you only need to connect the current loop of the signal. You will also need to connect the power circuit. But this is usually necessary to power the module itself so that the PLC can see it.



A big difference between the current and voltage outputs is the load impedance. Voltage outputs require a minimum load impedance, whereas for current outputs, the maximum load impedance must be checked. Remember, we are talking about the current flow here and the impedance (resistance) limits the current. If the load impedance is too large, the loop simply cannot direct the required current flow.

A typical PLC analog current output has a maximum load impedance of 300-500 Ohm.


Scaling analog output

If you know how to scale an analog value, you also know how to "de-scale". Because this is something that you often need to do. "De-scaling" means turning the engineering value into a value that the module can convert into an output.

Let's say we have an analog 0 to 10 V output signal to control the speed of an engine. To start the engine at 50% speed, we need to generate a 5 V analog signal at the output. To do this, we need to know what value to send to the D/A converter. In other words, we need to know our range.

For example, we can use a range from 0 to 27648.

As we now know our range, we can calculate 50% of that: 13824.

The problem here is that the operator does not insert 13824 into the HMI as a setpoint. What it will normally define is the engineering value, in this case, percentage (%). That is why we now have an engineering value that we need to convert to a value within the analog output range.

You can resize it in two different ways. With math or function blocks. Using math is a good way to make it easier to understand what's behind. Just use the same relationship with the scale:

Gross Value / 27648 = Engineering Value / 100

When isolating the gross value, you now have a mathematical expression for converting an engineering value to a gross value. You can implement this in structured text with just one line of code:

Gross Value: = (Engineering Value / 100) * 27648;


Boiler Project

• Create ACK_CALD variable of the BOOL type to recognize the alarm messages of the Boiler and SIMULA project of the BOOL type to place the process in simulation (monitoring and control in the OS).



• Create Function Block to acknowledge alarms. Right-click on the Blocks folder and select Insert New Object > Function Block menu item.

• Set Name FB2 and Symbolic Name to FB_ACK, Symbol Comment with Function Block Alarm acknowledgment and the language to LAD.

• Open FB2 FB_ACK for editing. In Component View, double-click on the function block.

• In Interface, enter the IN_OUT input/output parameter:

Name Type Description S7_m_c
ACK Bool ACK button True

• In Interface, enter the STAT parameters:

Name Type
A1 TON
AUX1 BOOL

• Insert function block logic.

Networks 1 and 2

ACK operator acknowledgment command goes to 0 after 2 seconds.



• Create DB11 DB_ACK of type FB2 (Symbol Table) and call FB_ACK in OB1.



Analog Inputs

• Create Function Block for analog inputs. Right-click on the Blocks folder and select Insert New Object > Function Block menu item.

• Set Name FB3 and Symbolic Name to FB_EA, Symbol Comment with Function Block Analog Input and the language to LAD.

• Open Attributes tab and in line 1 include the attribute S7_m_c with value true.

• Open function block FB3 FB_EA for editing. In Component View, double-click on the function block.

• In Interface, enter the IN input parameters:

Name Type Description S7_m_c
EA Real Analog Input True
BT_ST Byte Profibus-PA Status Byte

• In Interface, enter the OUT output parameters:

Name Type Description S7_m_c
QUALITY Byte Network signal quality True

• Enter the IN-OUT input/output parameters:

Name Typte Description S7_m_c
HD Bool Enable/Disable Alarm True
M1 Bool High Alarm True
M2 Bool Low Alarm True
SPL Real SP Low Alarm True
SPH Reall SP High Alarm True
HST Real Hysteresis True

• Entrar com os parâmetros STAT:

Name Type
X1HI Real
X1LO Real
WORDIN Word
WORDCOD Word
WORDAUX Word
INTAUX Int

• Insert logic for analog input.

Network 1

Subtract the high alarm SP hysteresis value to determine the high alarm reset value (X1HI). When the analog input is higher than the high alarm SP, the alarm is activated, as long as it is enabled. When the analog input is less than X1HI, the alarm goes to 0 (reset).



Network 2

Add hysteresis value to low alarm SP to determine low alarm reset value (X1LO). When the analog input is less than the low alarm SP, the alarm is activated, as long as it is enabled. When the analog input is greater than X1LO, the alarm goes to 0 (reset).



Network 3

Activation of low and high alarms, if enabled by the operator (HD = 1).



Network 4

Low alarm reset (HD = 0 or EA >= X1LO).



Network 5

High alarm reset (HD = 0 or EA <= X1HI).



Network 6

Logic for prohibiting SP Low Alarm greater than SP High Alarm. The SP High Alarm value must be entered before SP Low Alarm by the operator.



Network 7

Conversion of the Profibus-PA status byte of the instrument to word. Value assignment 192 (11000000) for WORDCOD for further WAND_W instruction.



Network 8

Instruction WAND_W sends bits 0 to 5 (six rightmost bits) of the Profibus-PA status byte to 0. The network diagnostic bits are bits 6 and 7 (two leftmost bits). The result of the WAND_W instruction is converted to an integer.



Network 9

If INTAUX = 0 (bits 6 and 7 at 0), the quality of the network signal is BAD.



Network 9

If INTAUX = 64 (bits 6 in 1 and 7 in 0), the quality of the network signal is UNCERTAIN.



Network 9

If INTAUX = 128 or 192 (bit 7 in 1 and bit 6 in 0 or 1), the quality of the network signal is GOOD.



• Create Function for FC2 EA analog inputs. Right-click on the Blocks folder and select Insert New Object > Function menu item.

• Open function EA and enter function block FB_EA for all analog inputs.

Tag Description DB
LT200 Boiler Level LT200_EA DB12 ID4
FT200 Feed Water Flow FT200_EA DB13 ID9
FT300 Superheated Steam Flow FT300_EA DB14 ID24
PT300 Overheated Steam Pressure PT300_EA DB15 ID29
PT500 Oven Pressure PT500_EA DB16 ID34
TT300 Steam Temperature in Superheater TT300_EA DB17 ID39
PT310 Soot Blowers Steam Pressure PT310_EA DB18 ID64

• Insert the Profibus-PA network diagnostics byte address (fifth byte) into the BT_ST input of the FB_EA.



• Move the first 4 bytes of reading the instrument's cyclic data (measured value in real) to the EA input of the FB_EA.



• Make the call to FC2 EA function in OB1.

• Select Operator Control and Monitoring for the DBs of the analog inputs.

• Compile AS and OS.



• Create customized objects for analog inputs.

• Create picture EA.pdl with 400 x 200 size.



• Insert custom objects for analog inputs in the process pictures.

• Insert text object with description of the tags of the analog inputs. When clicking on these tags, the EA.pdl picture will appear with the data of the corresponding analog input.

C script to show the picture window object PW_OBJ in the current picture.



The Picture Name property of the picture window PW_OBJ receives the name of the picture EA.PDL.

The TagPrefix property of the picture window PW_EA is defined as CALD/LIT200_EA. This statement adds the text “CALD/LIT200_EA.” at the beginning of all dynamizations of objects within the picture window.

• Insert analog inputs into pictures.



• Insert high and low alarm messages for the analog inputs in WinCC Alarm Logging.

• Compile and download AS. Compile OS and run the project. Test all analog inputs.