S7-300 Analog IO Scaling (newbie question)

minerman

Member
Join Date
Nov 2012
Location
Columbus, OH
Posts
82
First time using Siemens...

From what I understand, all analog IO raw data is stored on the PLC as 16-bit words. I am configuring 4-20mA inputs/outputs. I have read that analog channel data is scaled from 0-27648, 4mA = 0 and 20mA = 27648.

Question 1: Is this true for all modules? I've noticed that in the HW config, it specifies that some modules are 12-bit resolution, and 13-bit resolution. I don't understand the significance of these resolutions, if its true that all analog io is 0-27648? I'm confused, how could you describe the number 27648 in 12 bits?

Question 2: What is the easiest way to convert this data to and from real numbers? It doesn't seem like Step 7 is very friendly when it comes to data conversion. I don't see a possibility for converting a Word to a Real, unless its a BCD word, which the io is not? right? Same the other way, I don't see any converter functions to convert a real to anything?

Learning this software...It's the simple things that are throwing me off. :unsure:
 
scaling

L PIW256
ITD
DTR
L 27648.0
/R
L 1000.0
*R
T MW10

This is a scaling from an analogue input 0-27648 into 0-1000, result in MW10. ITD (Integer to Double format), DTR (Double to Real format).

12 or 13bit doesn't change the integer range 0-27648, it only means you have more precision.





First time using Siemens...

From what I understand, all analog IO raw data is stored on the PLC as 16-bit words. I am configuring 4-20mA inputs/outputs. I have read that analog channel data is scaled from 0-27648, 4mA = 0 and 20mA = 27648.

Question 1: Is this true for all modules? I've noticed that in the HW config, it specifies that some modules are 12-bit resolution, and 13-bit resolution. I don't understand the significance of these resolutions, if its true that all analog io is 0-27648? I'm confused, how could you describe the number 27648 in 12 bits?

Question 2: What is the easiest way to convert this data to and from real numbers? It doesn't seem like Step 7 is very friendly when it comes to data conversion. I don't see a possibility for converting a Word to a Real, unless its a BCD word, which the io is not? right? Same the other way, I don't see any converter functions to convert a real to anything?

Learning this software...It's the simple things that are throwing me off. :unsure:
 
L PIW256
ITD
DTR
L 27648.0
/R
L 1000.0
*R
T MW10

This is a scaling from an analogue input 0-27648 into 0-1000, result in MW10. ITD (Integer to Double format), DTR (Double to Real format).

12 or 13bit doesn't change the integer range 0-27648, it only means you have more precision.

I think I understand your example, but I am hoping to make one FB to scale several different IO points. I am not sure how to do this in STL.

Is there any way to do this in LAD? My previous experience is mostly RS5000 plcs. I can work much faster and understand better if I work in LAD.

Thank you.

edit: Wait, maybe I don't understand your STL? You're loading a Word, then using the ITD (Integer to Double). How can you use Int to Double when you have loaded a Word and not an Int?

edit 2: OK, I see the how your example works. You are using PIW 256, while I was trying to use IW 256. I see that using IW, does not work. I don't understand why though. I have read that PIW stands for peripheral input word, and IW stands for input word? I would think that these are still both Word data. Can someone explain further? Also, how would you go the other direction? From a real to the output channel?
 
Last edited:
First time using Siemens...

From what I understand, all analog IO raw data is stored on the PLC as 16-bit words. I am configuring 4-20mA inputs/outputs. I have read that analog channel data is scaled from 0-27648, 4mA = 0 and 20mA = 27648.

Question 1: Is this true for all modules? I've noticed that in the HW config, it specifies that some modules are 12-bit resolution, and 13-bit resolution. I don't understand the significance of these resolutions, if its true that all analog io is 0-27648? I'm confused, how could you describe the number 27648 in 12 bits?

Question 2: What is the easiest way to convert this data to and from real numbers? It doesn't seem like Step 7 is very friendly when it comes to data conversion. I don't see a possibility for converting a Word to a Real, unless its a BCD word, which the io is not? right? Same the other way, I don't see any converter functions to convert a real to anything?

Learning this software...It's the simple things that are throwing me off. :unsure:

Q1: With 16 bits resolution, the input counts 1,2,3...8,9..16
With 13 bits resolution it counts (jumps) 8,16,24... you loose the fines inbetween.

Q2: Integer to real must go via a double-int due to the representation of negative numbers. In STL it is like this:

L myinteger
ITD // Int to doubleInt
DTR // doubleint to real
T myreal

Backwards:
L myreal
TRUNC or RND or RND+ or RND- (push F1 to investigate)
T myinteger
or
T mydoubleinteger

More info:
There are scaling blocks in the standard library, I think it is in TI-S7 Convert.

It is FC105 for scaling analog inputs
and FC106 for rescaling analog outputs

Kalle
 
Thank you.

I think I only have one knowledge gap in understanding this.

Why in both given answers, does the conversion start with ITD? I thought my data is in word format, so how can I start the conversion with an int? I see that it will work if you use PIW, instead of IW? But, I don't understand why.
 
Integer and word.
Both are 16 bits, the STL doesn't check the format.
If you use LAD, the formats are tested and you must chain boxes (I don't remember the acronyms, but I'm sure you catch it) WtoI, ItoD, DtoR.

Why ITD:
It is only strictly neccessary if you convert negative integers.
If you look in the accu after loading -2 you will see this in hex:
0000 FFFE ,A 16 bit integer representation of -2. If you change this to real , DTR, it will be something like 6.5534e4.
But with an ITD command the accu contents are:
FFFF FFFE, which with DTR gives -2.0e1 real.

Kalle
 
Integer and word.
Both are 16 bits, the STL doesn't check the format.
If you use LAD, the formats are tested and you must chain boxes (I don't remember the acronyms, but I'm sure you catch it) WtoI, ItoD, DtoR.

Why ITD:
It is only strictly neccessary if you convert negative integers.
If you look in the accu after loading -2 you will see this in hex:
0000 FFFE ,A 16 bit integer representation of -2. If you change this to real , DTR, it will be something like 6.5534e4.
But with an ITD command the accu contents are:
FFFF FFFE, which with DTR gives -2.0e1 real.

Kalle

Edit
IW-PIW

The IW values are snapshots of the corresponding PIW numbers taken before the cyclig program (OB1) restarts the cycle. The values are not updated during the OB1 cycle.
So when you read a IW, you read from the internal snapshot memory called the 'Process Image', PI.
When you read a PIW, it accesses the pheripheral equipment instantly on the backplane bus, and is a bit more heavy operation, takes more time.

In the CPU setup in the hardware manager, you can set the size of the process image, within the max limits of course.

If you assign 200 bytes, it means that all I/O bytes with numbers from byte >= 200 must be accessed with L PIWxxx and T PQWxxx.
 
Hi all i am looking for some help in STL can some one help me with the STL nesting of the AND... i am pasting a code in it which I want to understand.
I am new to PLC and STL both.. I Know a bit about FBD and Ladder but not much about STL I am still learning it.. please help me...

A #StoerQuit
R #Stoerungen.Sollwert
A(
A(
O(
A(
L #PID.w //SETPOINT SPEED
L #MaxDrehzahl //Maxspeed
>R // comparison
)
JNB _005 speed) LABEL 005
L #MaxDrehzahl //else load maxspeed in acc1
T #PID.w //transfer maxspeed to PID.w
SET //set RLO to signal state
SAVE //save rlo state in BR
CLR //clear the RLO
_005: A BR //LABEL 005 Check the signal state for BR =1
)
O(
A(
L #PID.w
L 0.000000e+000
<R
)
JNB _006 //jump to 006 label when PID.w Setspeed is less than zero then RLO is 1
L 0.000000e+000
T #PID.w //no then transfer the acculator 1 in PID.w(setpoint)(which is one )
SET
SAVE
CLR
_006: A BR
)
)
A #Funktionen.DZein
O
A(
L #Status.DruckistLernen
L #Regelpara.MaxStellgroesse
>R
)
A #Lagertest_ein
O
A(
L #Lagertest_Para.SollDZ
L #MaxDrehzahl
>R
)
A #Lernen_ein
)
S #Stoerungen.Sollwert
NOP 0



Just like what it is saying... ???
thanks in advance
Ajay
 
Hi Minerman: I use FC105 for scaling analog inputs. That's what you need to do it the "easy and familiar way" in ladder. This FC is found in the standard library under TI-S7 conversion...for some unknown reason. Let us know how this works for you.

SNAG-0096.jpg
 
Heres a little AI scaling block I wrote...I added a feature to tell me what the actual input was scaled to the input type. Could have used FC105/FC106 but this works good and taught me a little bit about SCL

FUNCTION_BLOCK SCALING

Author:'EML'

VAR_INPUT

RAW : INT; //Enter value to be scaled
rInput_Min : REAL; //Enter input value @ rest (real)
rInput_Max : REAL; //Enter input value @ max (real)
rScaled_Min : REAL; //Enter minimum engineering units (real)
rScaled_Max : REAL; //Enter maximum engineering units (real)
iInput_Type : INT; //1 = 0-10VDC 2 = 4-20mA 3= 2-10VDC 4 = 1-5VDC
Gen_Alarm : BOOL;

END_VAR

VAR_OUTPUT

iScaled_Out : INT;
rScaled_Out : REAL;
iActual_Out : REAL; //Actual analog reading

END_VAR

VAR

rRAW : REAL;
Rate : REAL;
Offset : REAL;
rActualRaw : REAL;
rRateRaw : REAL;
rOffsetRaw : REAL;
rMin : REAL;
rMax : REAL;
rScaledMin : REAL;
rScaledMax : REAL;
rRawMin : REAL;
rRawMax : REAL;
rRawScaledMin : REAL;
rRawScaledMax : REAL;

END_VAR


BEGIN


rRAW:=INT_TO_REAL(RAW); //Convert incoming integer to REAL



IF Gen_Alarm = FALSE THEN //If General Alarm isn't present

Rate := (rScaled_Max - rScaled_Min) / (rInput_Max - rInput_Min); //solve for X
Offset := rScaled_Min - (rInput_Min * Rate); //solve for B

rScaled_Out:= (rRAW * Rate) + Offset; // solve Y=MX+B where M = RAW, X = Rate B = Offset
iScaled_Out:=REAL_TO_INT(rScaled_Out);

ELSE

rScaled_Out := 0; // General Alarm is true, output 0
iScaled_Out := 0;

END_IF;

CASE iInput_Type OF //setup scaling parameters to use depending on integer value iInput_Type
1 : rRawMin := 0.0; rRawMax := 27648.0; rRawScaledMin := 0.0; rRawScaledMax := 10.0; //0-10VDC
2 : rRawMin := 0.0; rRawMax := 27648.0; rRawScaledMin := 4.0; rRawScaledMax := 20.0; //4-20mA
3 : rRawMin := 0.0; rRawMax := 27648.0; rRawScaledMin := 2.0; rRawScaledMax := 10.0; //2-10VDC
4 : rRawMin := 0.0; rRawMax := 27648.0; rRawScaledMin := 1.0; rRawScaledMax := 5.0; //1-5VDC

END_CASE;

rRateRaw := (rRawScaledMax - rRawScaledMin) / (rRawMax - rRawMin); //Solve for X
rOffsetRaw := rRawScaledMin - (rRawMin * rRateRaw); //Solve for B
iActual_Out := (rRAW * rRateRaw) + rOffsetRaw; //Y= MX+B



END_FUNCTION_BLOCK
 

Similar Topics

Hi all, Does any body have some literature on how to scale the analog input signals e.g level tank control using a pressure...
Replies
2
Views
6,229
I have a client who has asked for a pop-up for each of their analogs, which will display the alarm values. The values displayed in the pop-up...
Replies
5
Views
2,513
hi i am using s7-300(CPU 313c). when i try to use FC106 unscale function, i can change IN manually but there is no effect on OUT. i wrote PQW752...
Replies
4
Views
1,565
Hi guys, I have CPU S7-300-313C ( Cat No - 6ES7-313-5BE00-0AB0) DI24/DO16 and AI5/AO2. when I am trying to configure and use the AO channel PQW...
Replies
4
Views
2,519
I am a student. I can program PLC using LAD language using digital IO. But, I want to program using analog IO also. We have analog IO module with...
Replies
2
Views
2,022
Back
Top Bottom