Blog

Siemens S7-1200 Analog IO

Siemens S7-1200 Analog IO

If you find yourself working with Analog IO on the Siemens S7-1200 for the first time, you may wonder how and where to start.  Here are some basic tips for working with Analog IO on this PLC platform.  For the purposes of this blog, I will focus on implementing 4-20mA inputs and outputs, but the concepts should apply to other signal types as well.

Configuring Analog Input/Output Models:
Open the Device Configuration for the PLC.  Add your module, then configure each channel's properties.  Not that for current-based signals, the only range available is 0-20mA.  If your signal is 4-20mA, still configure it as 0-20mA and scale the input value as demonstrated below.

Reading an Analog Input Value:
Since DMC engineers are biased toward modular, flexible code, I wrote my own function block to process a 4-20mA analog input that I can re-use within the project and for future projects.

I pass in all the unique values for that sensor that are required for scaling, and pass out my scaled, engineering value along with an error indicator. 
 
Inside my function block, I first test to make sure that the raw input value from the analog input channel is within the normal operating range and set the error output if it is not.  The raw input value ranges are listed in section A.6 of the S7-1200 Easy Book located on the Siemens website.

For the sake of convenience, here are the value ranges: 
  Overflow = 32512 to 32767
  Undershoot = 0 to -4864
  Underflow = -4865 to -32768

Decimal Range:
  0.0 - 27648.0

Wire break limits:
  4mA = 5529.6
  3mA = 4147.2
  2mA = 2764.8
  1mA = 1382.4

After the input validity test, it's time to convert the raw input to a meaningful engineering value.  For 4-20mA input signals, Siemens supplies a library function to convert the 0-20mA to a 4-20mA range.  The library functions are available on the Siemens website with instructions here:  Using the Siemens 0-20mA / 4-20mA conversion blocks.

Note:   I highly recommend modifying the standard library function "Scale_current_input" as shown below to handle a negative input value before the value is converted to a real number.

Once you have an accurate 4-20mA raw value range, perform the linear scaling math to generate your meaningful  engineering value.  For example:  Output = Input((Max-Min) / Range) + Min

Writing an Analog Output Value:
Writing an analog output is a bit simpler than reading the analog input.  Simply convert your analog output value to a percentage (0-100) and input that percentage into the "Scale_analog_output" library function provided by Siemens (see link above).  The resulting word value can be sent directly to the analog output address.
 

In Summary:
With a little help from the Siemens library blocks for converting 0-20mA signals to 4-20mA signals, analog IO on an S7-1200 controller is mostly straightforward.  I’ve tried to cover all the main points, but if there are any additional details that you’d like covered, feel free to leave me a comment.

Learn more about DMC's PLC Programming services and contact us to get started on your next PLC Programming project.

Comments

Kalyana sundaram
# Kalyana sundaram
Can any one tell how to select correct analog hardware in CPU 1214c ac/dc relay
parthiban
# parthiban
SIR I KNOW PLC LOGIC BUT HOW WILL SET ADDRESS (SYNTAX) DI AND DQ , AI AQ , COUNTER TIMER CMPARE SET RESET AND SO ON?
anup
# anup
how to convert the program in s7 1200 ladder logic to stl
Miguel Argolo
# Miguel Argolo
Hi, I'm trying to use SB1232, my plc is 1214C AC / DC / RLY, but SB don't turn on, I made the ​​ground connection to the AC ground and yet nothing happens. The program is simple, I read the analog input and want to put in the analog output this value. grateful
cata
# cata
Can anyone tell me how to physically connect a potentiometer to a plc s7-1200 (1212c)? The potentiometer has 2 wires (one for signal one for +). I tried and every time I have the error high limit exceeded.

Thank you
Nick Shea
# Nick Shea
John,

Please use the link I specified above to download the FCs from the Siemens Support website.

Thanks,
-Nick

Nick Shea
# Nick Shea
Dan,

Voltage outputs are the easier case. Use the Easy Book I mention above to find the decimal range for voltage outputs, then scale your 0-100 input value to that range.

I recommend changing your text box to a numeric input field unless you already have some plan for converting the text to a numeric data type.

Good luck!
-Nick
Dan Kidd
# Dan Kidd
Hi there!
I have been following the instructions on how to write an analog output value but I am a little confused. Firstly, I am using a textbox to input a value (between 0-100) which I want to convert to an analog signal for output to a VSD. Are the instructions outlined applicable to this situation? Also the output needs to be a voltage so I wanted to know if there is a scale block available for this?

Thanks in advance

Dan
John
# John
hey, nick can you help me
send to me that fc?
i am studying use s7-1200 analog IO
thanks.
Joe Burch
# Joe Burch
Hello Nick,
And, Happy New Year!

I used to be a maintenance mechanic, but unable to do that kind of work anymore. I am very new at Siemens plc programming. I purchased a S7-1200 Starter Kit & seek help at programming it. I figured out wiring the inputs & outputs, but programming is much harder to figure. I had some plc programming classes, but it was for Allen Bradley. Can you or your colleagues at DMC help me to be a half-way decent programmer to get a plc job?

Thanks,

joe
Meuris Tom
# Meuris Tom
dear Nick,

Can you mail me the FB that you made?
I use the scale current input block now

As im new withe programming i have no idee what to do to scale the AI to eg 0-200

Please help me

Post a comment

Name (required)

Email (required)

CAPTCHA image
Enter the code shown above:

Related Blog Posts