Announcement

Collapse
No announcement yet.

P3K gives conflicting MATH result

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • P3K gives conflicting MATH result

    Currently, I have three P3K CPUs running 'identical' programs (except for IP addresses)
    One PAC says that a ZERO value is 2.147 billion digits in size. The other two say that a ZERO is 1 digit in size.
    The tag SelCap_V has a value of ZERO - as shown in the following subrung.
    I replaced the CPU with a 'like' hardware revision, problem resolved -- except for CPU COST!
    Using something very similar to this

    The offending CPU is Rack_1 192.168.7.1 (Grumpy) [middle of image]Click image for larger version

Name:	How BIG is a ZERO.png
Views:	123
Size:	183.4 KB
ID:	128849

    All 'Rack' CPUs P3-550
    All Firmware Revs 1.1.14.39
    All Software Revs 1.9.2.0



    The CPU Module Info follows

    Code:
            Project  Rack 1          Rack 2          Rack 3          Replacement CPU
    REV              D2              D2              D2              D2
    DATE             10/17           04/18           04/18           04/18
    LOT              1               1               1               1
    MFG LOC          4-3             4-3             4-3             4-3
    
    SN               P3-550          P3-550          P3-550          P3-550
                     +17X18F027D2    +18530F007D2    +18530F012D2    +1853F008D2
    The difference seems to be something that happened to the hardware between 10/17 and 04/18

  • #2
    I had something like this happen also. Try breaking up the formula into two separate math instructions instead of one.

    Comment


    • #3
      Originally posted by bsinkovich View Post
      I had something like this happen also. Try breaking up the formula into two separate math instructions instead of one.
      Thanks, I tried. Log by itself failed to return a ZERO.
      I can try again, just not on this project. I'm just doing cosmetics for displaying volt/current on HMI. Would be simpler if I didn't already have 330+ tags on the screen.
      I'm trying to consolidate multiple INT tag values and a couple STRING status messages into one STRING tag -- with decent formatting - so I gotta know how long the INTs are.

      I think that something (FPGA-Code related) changed between 10/17 and 04/18. We don't get release notes on those.(?)

      Comment


      • #4
        Back to the bench for a test.
        A simple log(0) returns 2 billlllllllion!
        I think I will try some firmware upgrade/downgrade cycles. May be something glitchy in one of the FW installers.




        Click image for larger version  Name:	log(Zero) -math -simplified.png Views:	0 Size:	22.7 KB ID:	128853



        [EDIT] firmware juggling did not help.Went from 1.1.13.24 thru 1.2.7.39 No luck.
        Tried on a C1 CPU, it works as expected.
        CPU P3-550
        Rev C1
        Date 10/09
        Lot 1
        MFG 4-3


        [EDIT] it was a C1 CPU, not a C4
        Last edited by kewakl; 02-27-2020, 11:39 AM.

        Comment


        • #5
          Certain mathematical operations are "undefined" in computers. For example, what should the result be when you divide by 0? Result value could be 3. Result value could be the numerator. It could be 2 billion. If it's floating point, it could be NAN or +INF or -INF or ... Some computers raise exceptions and purposefully crash the computer since there is code that needs to properly handle that condition, but did not.

          It is impossible for a computer to provide consistent results for all possible "undefined" behavior. Programs need to test for those cases ahead of time in the code. You can't divide by 0, do the log of 0 (or log of -1), so write code to check for that ahead of time (although some math libraries support imaginary numbers, so ln(-1) is do-able for those, -3.14159265i). Hence, simply calculate the base value and store it in a tag, then do one calculation when it is valid (i.e. > 0), and do something different when it is invalid (i.e. <= 0). When it's invalid, you could raise an error, or generate a desired known result when it is invalid. You are in complete control of the desired behavior when the expression is invalid. Do not depend upon the microprocessor to do exactly what you expect when you feed it an invalid expression.

          As I tell my co-workers - that's why they pay us the big bucks.
          There are 10 kinds of people in this world, those who know binary, and those who do not.

          Comment


          • #6
            I think it may be that log(0) is invalid (try it on your computer calculator). Anything invalid, NAN, undefined, etc is going to be something that cannot be trusted. I would do a compare ahead of the math operation to be sure the value is nonzero.

            Also, what is the purpose of the ( * 10/10)? Why not just do (log(SelCap_V) + 1)?

            Comment


            • #7
              Log(0) works on the other 4 P3-550's. So either ONE is wrong, or 4 are wrong. If the results were consistent across CPUs, I might never have noticed.
              With Pseries hardware and software , I cannot really tell.
              franji1, what you say makes a lot of sense, but why do several CPUs report with log(0) ---> 0 and one takes issue? I could do a value check before the log check. Thanks.



              g.mccormick I included a link in the OP for that reason https://forum.automationdirect.com/f...nd-or-truncate

              Comment


              • #8
                Originally posted by g.mccormick View Post
                . I would do a compare ahead of the math operation to be sure the value is nonzero.
                Yes. From franji and your responses, I think I shall do just that, since the result will vary from CPU to CPU. Thank you both.
                Background, I am trying to pack some values into a string - I need to know each substring's length - this substring specifically must be length [ 1 .. 3 ], but I do not want leading zeros.
                This substring is the measured voltage on a capacitor (0 - 600 VDC). Reference post 3, I am running out of tags per screen on HMI.

                Comment


                • #9
                  I might be over simplifying and not understanding what you are trying to do but couldn't you use the copy instruction to get an int to a string and then us the use the string length instruction (SLEN).

                  Comment


                  • #10
                    Originally posted by z28z34man View Post
                    I might be over simplifying and not understanding what you are trying to do but couldn't you use the copy instruction to get an int to a string and then us the use the string length instruction (SLEN).
                    Yes, that should work, and I could. Other than another instruction and another tag....
                    I tried to build this string incrementally, but it seems that pac will not take a string as an argument to an instruction where the same string is the result. (like a 'CAT instruction.)

                    So far, the advice from franji1 and g.mc have worked well enough -with minimal code change - I just have to document this so I won't be in repeat-land.

                    The building of the string is not the issue, it is that different PAC hardware revs return different results.
                    Upon thinking (I should do this before posting) it seems that the 2.1billion is more correct than a zero - if the 2.1billion were negative, that would make sense as an error value.

                    Comment

                    Working...
                    X