# S7-300_analog I/O program

M
Thread Starter

#### milan_djukic

I need a simple program for analog I/O in S7-300.
Thank you in advance

S

#### Shahid Waqas Chaudhry

If you like simple things (like me), here is the fastest method:

Step 1) Open you Step7 Project. You can code this in any Block of your choice (I will simply use the OB1)
Step 2) Open OB1 in the LAD/STL/FBD editor
Step 3) In the Cataog (you get the component list by pressing Ctrl+K), select the following path:
Libraries -> Standard Functions -> TI-S7 Converting Blocks
Step 4) Select FC105 (for Scaling of the Analog Input) and FC106 (for Scaling of Analog Output)
Step 5) For help, read the online help (by selecting the block and pressing F1)

*OR*

If you are the programming type, then here is a simple program (written in STL, comments preceded by //). You can code it in OB1

----------------------------------------------------------------------------
--------Cut Here--------------------------------
// Simple Analog Input and Scale block
//
// The range of the Analog Input is 0 - 100 %.
// In the scaling equation:
// Output = [AnalogInput * (Max - Min) / 27648] + Min
// Since our Min=0, Max=100, therefore the equation becomes
// Output = AnalogInput *0.003616898
// The analog is read in the form of -27648 to +27648 (through the ADC)
// Use only for Uni Polar

L PIW <analog Address>
ITD // Convert Integer to Double
(16-bit -> 32-bit)
DTR // Convert Double to Real (32 bit
INT to 32 bit Real)
L 0.003616898 // This is your scaling factor
*R // Real Multiplication
T MD10 // The output is in Real Format, hence a Double Word (in Memory)
----------------------------------------------------------------------------
--------Cut Here--------------------------------

Similarly, you can rework the equation and device a thing for the Analog Output

Hope this helps.

Shahid

D

#### Donald Pittendrigh

HI All

This is basically sound advice but I don't know why he wants you to multiply by this odd number when for a 12 bit analog you should divide by 32760 to reduce the magnitude of the input to a range of 0.0 to 1.0 and then multiply by the range, or for a 1 bit analog divide by 65535 and then do the same. The above numbers are derived fron a 12 bit or 15 bit magnitude, (BINARY)
don,t forget the sign bit in the MSB position, and shift the value until it is left justified,. this is the procedure detailed in the instructions for use of analog input cards as published on the Siemens website (for free) and
works correctly.

Good Luck
D.P.

W

#### wlmostia

Standard resolution for 12 bits used in analog signals is 4095 and for 15 bits 32767. The 12 bit resolution does not commonly include a sign bit but 15 bits(16 bits total) typically does. For 16 bits without a sign bit, the resolution is 65535. Some instruments may have a slightly lower signal resolution in order to use the other bits for diagnostics, i.e. live zero, underrange, overrange, etc.

Bill Mostia
===========================================
William(Bill) L. Mostia, Jr. PE
Independent I&E Consultant
WLM Engineering Co.
P.O. Box 1129
Kemah, TX 77565
[email protected]
281-334-3169
These opinions are my own and are offered on the basis of Caveat Emptor.

D

#### Dobrowolski, Jacek

Oops ! I always thought that resolution for 12 bits A/D is 2^12=4096. What a surprise ! I must have missed some math lessons. BTW what is non-standard resolution(s) for 12 bits A/D ?
Now sarcasm aside. Procedure described by Donald is completely right. He only "misspelled" 32767 with 32760, I think. This weird, at first sight,
behavior of Siemens analogue IO cards in fact is brilliant. To do a conversion into and back "analogue" (read: type REAL) value you do not need to know the type (and resolution) of IO card.

Regards,

Jacek Dobrowolski

M

#### milan_djukic

Hallo Shahid,
Thank You .Your answer helps me very much.
Best regards.
Milan Djukic,Croatia

W

#### wlmostia

12 bit resolution is 2^12 - 1 = 4095 as is 15 bit 2^15 - 1 = 32767.
A non-standard resolution for 12 bits would be the use of a sign bit which would give 2^11-1(2047 bit resolution) with the 12th bit as a sign bit. Also, there are some instruments that use 4000 bit resolution for 12 bits with the other 95 bits used as diagnostic bits.

Bill Mostia
===========================================
William(Bill) L. Mostia, Jr. PE
Independent I&E Consultant
WLM Engineering Co.
P.O. Box 1129
Kemah, TX 77565
[email protected]
281-334-3169
These opinions are my own and are offered on the basis of Caveat Emptor.

A

#### Andrew Hawdon

I hate to hark back to the origional solution but it was correct. The S7300 analog input is ranged to +27648 to -27648 by the module. ie on a +-10v input +10v produces a raw value of 27648 and -10v 27648.

Andrew

Similar threads