I had this in a fb and it was called with filter = 1024 and input = 0. A fb on line 1 calculated the q_lOutput correctly = 0 the fb on line 2 calculated some overflow value. This was tested on a C167 infineon target not in simulation mode. I then cast the filter by using INT_TO_DINT and it appeared to take care of the issue. Does 3s have any standards or best practices on when and when not to cast?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes you are correct, but my concern is sometimes it works and sometimes it doesn't especially for the same filter number calling two instances of the FB. One will be correct and the other is not. So how can the compiler get it correct once and not be consistently wrong? Not being wrong 100% of the time scares me. It makes debugging difficult. Also if you ran this in simulation mode on your PC you will get the correct value 100% of the time.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What is 3s stance on casting?
I have come across the following issue but have seen this before with other calculations.
I had this in a fb and it was called with filter = 1024 and input = 0. A fb on line 1 calculated the q_lOutput correctly = 0 the fb on line 2 calculated some overflow value. This was tested on a C167 infineon target not in simulation mode. I then cast the filter by using INT_TO_DINT and it appeared to take care of the issue. Does 3s have any standards or best practices on when and when not to cast?
your filter is only a INT and not double so calcs will be wrong.
Yes you are correct, but my concern is sometimes it works and sometimes it doesn't especially for the same filter number calling two instances of the FB. One will be correct and the other is not. So how can the compiler get it correct once and not be consistently wrong? Not being wrong 100% of the time scares me. It makes debugging difficult. Also if you ran this in simulation mode on your PC you will get the correct value 100% of the time.