Does any of you ever had an issue with the dint_to_dword function ?
I receive an 16 bit real value (yes it's possible) in the form of a dint register. I made a function that convert it to a dowrd, shift to the left 16 bits, dword to real then gets into a piecewise to scale the value if necessary.
So far so good you would say. Until I see some spurious spikes on the output of the piecewise function block. I managed to isolate the source.
If for exemple my real value is 8.9375, it should be 0x410F0000(IEEE754). Strip the 16 LSB and you get 16655
16652 is the value I receive on the input and the task here is to put it back in the 32bit single precision floating point. As simple as that.
My issue is at the very beginning of the whole procedure. Once in a while, the dint_to_dword conversion gives incorrect results. For an input of 16555 (0x410F) the function gives me an incorrect result(0xB538) and it lasts for only 1 scan (normal task @ 250ms).
I managed to put a double conversion to patch the issue. I convert the original Dint input back to a Dint after converting it to a dword. I compare the two and if they are equal I keep going otherwise, the output is frozen.
BTW the conversion here is the real value received from a DCU controller through a Profibus gateway. The value sent by the DCU is a real according to IEEE754 with the last 16bit of precision stripped down. So it is basically a half precision floating point number.
5.0 SP2 RevC
If someone has ever encountered this behaviour, I would be more than happy to know it.
Thanks to all,
Insert the URL that your highlighted text will link to.
Copy the video's "embed" tag into Embedded Video below.