
adccommunitymod (AutomationDirect) asked a question.
Created Date: September 29,2019
Created By: xtal_01
**** This post has been imported from our legacy forum. Information in this post may be outdated and links contained in the post may no longer work.****
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
Created Date: September 29,2019
Created by: xtal_01
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
Created Date: September 29,2019
Created by: xtal_01
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
Created Date: September 29,2019
Created by: franji1
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.
Created Date: September 29,2019
Created by: xtal_01
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
Created Date: October 01,2019
Created by: xtal_01
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 !
Created Date: October 01,2019
Created by: xtal_01
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 ???
Created Date: October 01,2019
Created by: franji1
Here's a program "Counting Millions ". D0 is the integration of the flow (volume). D1 is the number of millions. One rung. Easy peasy:
{ "data-align ": "none ", "data-size ": "full ", "title ": "CountingMillions1.png ", "data-attachmentid ":125428}
You could even make a symbolic constant OneMillion, and the code would read better (is that 100,000 or 1,000,000?).
Created Date: October 01,2019
Created by: franji1
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.
{ "data-align ": "none ", "data-size ": "full ", "title ": "Millions1.png ", "data-attachmentid ":125433}
Created Date: October 01,2019
Created by: franji1
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):
{ "data-align ": "none ", "data-size ": "full ", "title ": "Millions2.png ", "data-attachmentid ":125436}
Created Date: October 01,2019
Created by: franji1
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:
{ "data-align ": "none ", "data-size ": "full ", "title ": "Millions3.png ", "data-attachmentid ":125438}