Author Topic: Mathematical operators  (Read 4705 times)

Jóhann Arnarson

  • Guest
Mathematical operators
« on: December 15, 2011, 10:19:22 PM »
I made an odd discovery this morning when doing an application where I measure temperature and and use a COMPARE WITH HYSTERESIS LOW to control a fan.  To make a long story short, the temperature control works just fine, just as long as he temperature measured is above 0°C.  If the input value (A) receives a lower value than 0, the output somehow becomes true, but stays false from 0 up to the referance temperature as it should. 
Ok, I thought. I just use a GREATER THAN operator and use input A for my measured values and B for reference value which I set to 0, so if input A is below 0, I will get a false on the output.  That did not happen. 
When trying to make sense of it, I made an application with only one GRATER THAN operator, put a simple check point on the output and used a parameter on input A and B so that I could run the service tool and monitor the output.  It worked as it should, as long as both inputs were either negative or positive, but if I set input A to negative value and B to positive value I got a wrong answer.

Example:
A = 0, B = 17
A > B = false (as it should)

A = -1, B = 17
A > B = TRUE???? (so not true in reality!)

Both A and B are of the type S8.
Does this make any sense? 

I could avoid all negative values by simply adding a constant to my values but I would like to know why I can't get the right result.
I would like to hear your opinion or if you have experienced the same.





Offline Neil

  • PLUS+1 Expert
  • ****
  • Posts: 96
  • Karma: +2/-0
Re: Mathematical operators
« Reply #1 on: December 15, 2011, 10:52:36 PM »
Hi Jóhann

I have just run the below and check the output with the GUIDE simulator, I got a false return on the AR output.

regards Neil

Jóhann Arnarson

  • Guest
Re: Mathematical operators
« Reply #2 on: December 16, 2011, 10:57:06 AM »
Hi Neil.

If I connect constants to the inputs and use the same values as you do, then I get a false return.  On the other hand if i use a "Non-volatile memory dynamic input", and use the same values (A=-1 and B=17) then I get a true return.  On the output I only have a simple checkpoint connected.  It would be fun to hear if you also get a true return if you use parameters instead of constants.

Regards, Jóhann.

radioact

  • Guest
Re: Mathematical operators
« Reply #3 on: December 18, 2011, 10:45:07 AM »
I ran across this thread and it peaked my interest so I ran the test quick on a MC024-010 with Guide 5.1.9.3.

Surprising but it confirmed what Jóhann saw, the logic comparison gave me the wrong answer when connected to two non-volatile memory dynamics. Next I tried connecting the output of the comparator to a digout pin just in case there was something to do with it only being connected to a checkpoint but it gave the same result. So next I tried bumping 'A' up to a S16 thinking the bug might related to the sign bit and bingo the result is now what it should be.

So in the short term make sure not to use S8 memory dynamics with greater than comparators. I would imagine Thomas will want this sent to the helpdesk, I will let you have the honors.


To Do: Test the other comparator types to see if they suffer the same bug.

Tyler

Offline Stefan

  • Administrator
  • PLUS+1 Expert
  • *
  • Posts: 72
  • Karma: +0/-0
Re: Mathematical operators
« Reply #4 on: December 19, 2011, 10:10:58 AM »
Hello,

We have identified this issue and it will be fixed in next release.

A work around for this will be (as mentioned) to use S16 instead.

Best regards
Stefan