Announcement

Collapse
No announcement yet.

goto or jump to statement ?????

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


  • goto or jump to statement ?????

    As usual, I know what I want to do but now how to do it in a PLC.

    Say I have the a number ... 25, 299 (Rx)

    I want to subtract 1000 till I get below 1000 (so it is a three digit number .... 999 or less). I am keeping track of how many times I do this so I know how many 1000's I have.

    The command is simple ... if Rx is greater or equal to 1,000 ... subtract 1,000 and save to the same location Rx (so Rx now equals 24,299) ... and add 1 to a counter (say Ry ... now equals 1)

    Now, I want to just back to the same command before going ahead to the next.

    I want ....... if Rx is greater or equal to 1,000 ... subtract 1,000 and save to the same location Rx (so Rx now equals 23,299) ... and add 1 to a counter (say Ry ... now equals 2)

    I want to continue this till ... Rx now equals 299 ... and Ry ... now equals 25

    So, how do I do this?

    I don't want to loop through the entire program as the next rung on the ladder requires me to use the Ry value (25).

    I looked at GOTO and at LOOP ... neither of these seem to do what I want.

    What I need is something that will say if Rx is greater or equal to 1,000 go to rung XX (jump back to the previous rung) ... if less then do nothing and continue with the program.

    Thanks ..... Mike





  • #2
    I keep reading help files and there may be an easier way of do this but I just can't find it ...

    Maybe there is a math function that would take the 25,299 (Rx) ... if it is greater then or equal to 1,000 then subtract 25,000 .... add the 25 to Ry and leave the 299 in Rx

    As usual, all help and advice is greatly appreciated!

    Mike

    Comment



    • #3
      Let's just move it to a 32 bit integer D42. If D42 is always positive, you can use DIVIDE / and MODULUS (Remainder) % in MATH instructions:

      MATH D100 "D42 % 1000" will give you the remainder value 0..999 in D100
      MATH D101 "D42 / 1000" will give you the number of thousands in D101

      If can be negative, just replace D42 above with ABS(D42) which takes the absolute value of D42 and does all of that math on the absolute value.

      If it truly is REAL, then you have to use TOINT but also need the factional part, so use FRAC. Here's worst case, if it's REAL, you want the fractional part, and can be NEGATIVE

      MATH R100 "(ABS(TOINT(R42)) % 1000) + FRAC(ABS(R42))" // so -1111.1 will put +111.1 into R100
      MATH D101 "(ABS(TOINT(R42)) / 1000)" // so -1111.1 will put +1 into D101

      FYI, If you are trying to format an integer for display purposes (e.g. to insert thousands comma), there is a FmtInt script command in STRPRINT:


      STRPRINT SS0 "FmtInt(D42, dec, 10, right, commas)"
      There is a similar script command FmtReal with a slightly different function signature, but puts in commas for the thousands.
      see Help Topic DmD0168 (click on the Search tab in the Help browser's left pane and enter that text) for help on the Print Script commands.
      There are 10 kinds of people in this world, those who know binary, and those who do not.

      Comment



      • #4
        So how about moving to Vermont for a week or so?

        Exactly what I was trying to get it to do. I could not figure out how to get the remainder in one register and the first part in another.

        These will always be positive numbers .....

        I am just reading two flow meters but with very large flows ... 500 gal/min 24/7

        They want some reporting and some logging done.

        The rest of the project is simple ... just turn 12 pumps on and off (and make sure they are really one).

        Thanks so very much again !!!!!!!!!!!!!!!!!

        Mike

        Comment



        • #5
          OK ... so everything works as should ... great example!

          I still have the problem of large numbers .....

          Now, before I to a lot of typing .... since I now have an integer, do I still just go with the idea of using two values .... one for say everything up to 1 million and one for everything under 1 million?

          Say load everything into Dx and when Dx goes over a million then subtract a million from Dx and add one to Dy?

          Then I could use the strprint command to display and e-mail a large value (dy dx)?

          Thanks again !

          Comment



          • #6
            Just looking at the example and what I have in the program ... rather then my way (subtract and add) would it be better to use the example .... if larger then XXX then do the math and move the 1000's (or million or ...) to the next register and leave the remainder where it is ???

            Comment



            • #7
              Here's a program "Counting Millions". D0 is the integration of the flow (volume). D1 is the number of millions. One rung. Easy peasy:

              Click image for larger version

Name:	CountingMillions1.png
Views:	80
Size:	117.6 KB
ID:	125428

              You could even make a symbolic constant OneMillion, and the code would read better (is that 100,000 or 1,000,000?).
              There are 10 kinds of people in this world, those who know binary, and those who do not.

              Comment



              • #8
                Here's a rung that generates the text. It deals intelligently when the number of millions equals zero, so you get a nice display of
                1,234
                then once it gets above 1 million, it shows the millions portion with proper padded zeros on the sub-millions
                1,000,000

                That triangle with the dot is a "power flow inverter". The rung becomes an IF-THEN-ELSE statement.
                IF Number of Millions (D1) == 0 then do the normal display of the number in D0 (number of sub-millions) with comma 1000 delimiters (no leading zeroes)
                ELSE then show number of millions D1 with comma 1000 delimiters, and D0 (number of sub-millions) with comma 1000 delimiters WITH leading zeroes.

                Click image for larger version

Name:	Millions1.png
Views:	76
Size:	87.4 KB
ID:	125433
                There are 10 kinds of people in this world, those who know binary, and those who do not.

                Comment



                • #9
                  The field width of 6 in the 2nd STRPRINT D0 FmtInt is critical for displaying the proper number of submillions (e.g. 000,000 when D0 is 0 but D1 is 1 or more):

                  Click image for larger version

Name:	Millions2.png
Views:	77
Size:	89.9 KB
ID:	125436
                  There are 10 kinds of people in this world, those who know binary, and those who do not.

                  Comment



                  • #10
                    I stubbed in the values 0 and 1 for D0 and D1 to test the case when it is 1,000,000 and it works like a charm:

                    Click image for larger version

Name:	Millions3.png
Views:	77
Size:	102.1 KB
ID:	125438
                    There are 10 kinds of people in this world, those who know binary, and those who do not.

                    Comment



                    • #11
                      Originally posted by xtal_01 View Post
                      So how about moving to Vermont for a week or so?
                      One of the best things about Automation Direct; you get forum responses from the actual developers of the PLC you're using!
                      Why worry? If you've done the best you can, worrying won't make it any better

                      - Walt Disney

                      Comment



                      • #12
                        Originally posted by Todd Dice View Post
                        One of the best things about Automation Direct; you get forum responses from the actual developers of the PLC you're using!
                        Yeah, Do-more is one of those products that people don't know what/how much it can do. There are a few PLC developers out there that utilize a lot of Do-more features, but we Designer software developers are the only ones who know ALL the features (but even we sometimes forget!). Hence, we can provide info like this (e.g. how to do HUGE INTEGRATION and DISPLAY HUGE NUMBERS bigger than 900 billion to a resolution of 1 count).

                        "I didn't know you could do that!"

                        This example counted MILLIONs (and count up to 999 BILLION). We could have counted the number of BILLIONS, resulting in HUGE values as big as 999,999,999,999,999,999 to the 1's digit place (yes, that's 999 QUADRILLION). That's a lot of anything! IEEE floating point can only do 24 bits of resolution, this is basically 60 bits of resolution (59?). THAT's a LOT of INTEGRATION!
                        There are 10 kinds of people in this world, those who know binary, and those who do not.

                        Comment



                        • #13
                          Wow, that is impressive. Now, if I could convince some of my customers out of Allen-Bradley...
                          Why worry? If you've done the best you can, worrying won't make it any better

                          - Walt Disney

                          Comment



                          • #14
                            Wow..

                            I did not realize that the National Debt was a Manageable Number!..

                            Thanks..



                            Cap

                            Comment



                            • #15
                              OK .... what is that symbol on the second STRPRINT line? ... and how do you get find it?

                              I see what it is doing (if D1 is greater than or equal to 1 ...... well anything over 0 ... then use SS0 becomes the second rung).

                              You told me to use the control F2 for the "leading edge power modifier" .... I assume this is the same type of thing ... is there a list of all these functions in the Help files (just looked through and can's seem to find them).

                              So, how about a developers conference in Vermont? Nice time of year ... leaves are changing. My wife says I am making a career out of a project you could finish in a night.

                              Truly, thanks so much for all the help!!!!!!!!!!

                              Mike


                              Comment

                              Working...
                              X