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
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