Step 7 - analog to real value problem

Miuko

Member
Join Date
Jun 2012
Location
Bratislava
Posts
6
I am try to do this task:
write FC1 that would read from analog input (analog input = tw). The output of the FC1 will be downloaded/read/recorded in the format REAL. The output should be normed in the interval himin and himax that is connected with the input values of the model with analog inputs.
FC1 will have 3 inputs read from analog entry,himin, himax.

In the picture you can see my FC1. It is called from OB1.
http://imageshack.us/photo/my-images/171/screenshot260d.jpg/

My problem is that from what I have tested, it is working very strangely - I get weird numbers.
examples-
tw=2
himin= changed automatically to 512!
himax=100
output= 1120407388




Do you see what can be the problem?

Thank you for any help!

Miro
 
I guess you should do something like this:
t1 := WORD_TO_INT(tw);
t2 := INT_TO_REAL(t1);
t3 := t1/27468; //here you have the value in a 0 to 100 scale
t4 := 100/himax; //get the convertion factor for your scale
t5 := t3/t4 + himin //now youo have it int a himin to himax scale


Hope this can help you, I don't know why your min and max values are changing (you said they are readed from an input), so maybe that's messing your program also.
 
In the picture you can see my FC1. It is called from OB1.
http://imageshack.us/photo/my-images/171/screenshot260d.jpg/

Copy/paste the text from the SCL editor into your post - it is really quite tedious having to enter code from a screen shot. E.g.

Code:
FUNCTION fc111:VOID
VAR_INPUT
    himin:INT;
    himax:INT;
    tw:WORD;
END_VAR
VAR_OUTPUT
    ti5:REAL;
END_VAR
VAR_TEMP
    ti:INT;
    ti2:REAL;
    ti3:REAL;
    ti4:REAL;
END_VAR

BEGIN
ti:=WORD_TO_INT(tw);
ti2:=INT_TO_REAL(ti);
ti3:=ti2/27648;
ti4:=ti3*(himax-himin);
ti5:=ti4 + himin;
end_function
You also need to post the call in OB1 - without that we are blind. At a guess though, you are using M flags as the parameters to the FC and you have chosen MW's and MD that overlap.
 
Last edited:
When you are monitoring code, you can chose the format for the display. You are showing the result in decimal format. Right click on the variable and select floating point (or automatic)

fpf.JPG
 
OK sorry next time I will do it.
Yes that was one of the problems. The other was that I used close Bytes (now I am reading that you found out also this!:) ), so it was manipulating himin when I changed himax - for each it is needed 2 bytes and I used PEW256 and PEW257 so it was overriding!
Thank you very much for support!
Copy/paste the text from the SCL editor into your post - it is really quite tedious having to enter code from a screen shot. E.g.

Code:
FUNCTION fc111:VOID
VAR_INPUT
    himin:INT;
    himax:INT;
    tw:WORD;
END_VAR
VAR_OUTPUT
    ti5:REAL;
END_VAR
VAR_TEMP
    ti:INT;
    ti2:REAL;
    ti3:REAL;
    ti4:REAL;
END_VAR

BEGIN
ti:=WORD_TO_INT(tw);
ti2:=INT_TO_REAL(ti);
ti3:=ti2/27648;
ti4:=ti3*(himax-himin);
ti5:=ti4 + himin;
end_function
You also need to post the call in OB1 - without that we are blind. At a guess though, you are using M flags as the parameters to the FC and you have chosen MW's and MD that overlap.
 

Similar Topics

Hello, We monitor the temperature of a pipe via a 4-20mA temperature transducer. This goes into DB135(Read Analog Inputs). The issue I have is the...
Replies
0
Views
615
Dear all, I'm trying to figure out the following situation: A PT-100 temperature sensor is measuring water. When I measure the water temperature...
Replies
17
Views
6,144
how to read analog input values in siemens step 5? In other words if i want to know the analog input value from the program i always find analog...
Replies
11
Views
7,152
Hello guys, I have one little problem at work. I'm writting a ladder diagram program that will manipulate with analog values. Since analog values...
Replies
39
Views
10,437
Hello guys, I'm learning how to design a PID controller in STEP 7. Now my first question is how to check if PID working OK? I want to test it but...
Replies
4
Views
6,106
Back
Top Bottom