Potential Emulator Problem?

tomizzo11

Member
Join Date
Jul 2013
Location
Michigan
Posts
49
Hello,

I believe I am experiencing some odd issues, and hopefully some of you may be able to help me out. This might be an issue regarding the emulator processor, or I am overlooking a very minute detail.

I am implementing a simple IF statement.

This is the statement:

if (PercentWidth*Distance + StartEdge) > (Distance) then

O_Error.8 := 1; //Date type DINT
end_if;

This statement works correctly when facing 99.9% of the conditions. However, it doesn’t work for one condition:

PercentWidth := .8; //Date type real
Distance := 10.0 //Date type real
StartEdge := 2.0; //Date type real

This condition should yield a condition where the program asks if 10.0 > 10.0 . Obviously the answer to this conditional statement should be false and the error should not be set, yet it somehow is. I have done tests over and over again trying to figure out why this statement is being triggered. For example, I have created new variables made up of the above expressions:

TestReal1 := PercentWidth*Distance + StartEdge;
TestReal2 := Distance;


I then use these two variables in the conditional statement and the thing works perfectly.

if (TestReal1) > (TestReal2) then

O_Error.8 := 1; //Date type DINT
end_if;


I put in the original expressions back in the if statement and sure enough, it stops working again. I have even put ‘TestReal’ assignment statements within the original if statement, and they produce a result where the TestReal1 = 10.0 and TestReal2 = 10.0. 10 is not greater 10 yet the if statement was somehow triggered. How is this possible? It makes absolutely no sense.

I have checked to make sure all the data types were correct (no integer rounding), and have checked to make sure that variables values weren’t being changed in other parts of the program. The O_Error.8 bit is only set within the this if statement, nowhere else in the program.

Because of this, I am skeptical of the processor. I am using the emulator program which I have heard can have funny things happen. Is this a reasonable assumption, or can anyone think of anything that might be causing problems?

Thanks
 
As an experiment Multiply 10.0 by .8 with a destination of a real data type and tell us the results. ( 7.99999 maybe?) Could be the way floating point numbers are handle in PLCs and computers.
 
As an experiment Multiply 10.0 by .8 with a destination of a real data type and tell us the results. ( 7.99999 maybe?) Could be the way floating point numbers are handle in PLCs and computers.


That's exactly what I think is happening somewhere, but I can't seem to locate it. I did 10.0 times .8 and the output was 8.0. But I suspect there is a rounding issue going on.
 

Similar Topics

I found this article in today's news interesting ... as if we don't already have enough to worry about these days ... headline: here's a link...
Replies
5
Views
2,406
Hi all, I am currently working on a project where i need the to get the Julian date from the PLC (which i have now done). But now the customer...
Replies
4
Views
1,589
Hi, I have a chance to apply for an automation position coming up. I am not in an automation position right now, I am an E/I Project Lead. I have...
Replies
23
Views
7,863
Hi all. I am on the lookout for some terminals for distributing voltage potentials. You know, banks of terminals with 24V or 0V grouped...
Replies
14
Views
10,215
Is it possible to connect two potential free relays output to one 240V supply and return?
Replies
3
Views
1,731
Back
Top Bottom