Adding Multiple #'s

sgsims

Member
Join Date
Jun 2005
Posts
12
Can someone suggest the proper way to add 10 numbers (10 Readings from a flow meter) and divide that # by 10?
 
sgsims said:
Can someone suggest the proper way to add 10 numbers (10 Readings from a flow meter) and divide that # by 10?

Which PLC?

With a text based PLC, I use the following generic form that I learned in Object Oriented Programming I.

Declare Array_Of_10;

Size = 10;
Index = 0;
Total = 0;

While Index < Size do
Total = Total + Array_Of_10[Index];
Index = Index +1;
endWhile

Average = Total / Size;

By doing it this way, if I want to change the # of readings, I adjust the Array, the Size, and boom, still works.

(Edited to zero the total)
 
Last edited:
Thank you very much! That was great. So, if I understand correctly we are loading the first # in the accumulator then ading each subsequent # to that # in the accumulator. After each addition takes place the result is placed in the accumulator.

Am I right?
 
That's right.The result of any of the math operations remains in the accumulator (which is 32 bit by the way). You can then perform further operations or send the result to a destination. Performing the OUT (or OUTD) does not clear the accumulator. It is still holding the last value if that is of any importance. And also, after a DIV the integer quotient is in the accumulator while the remainder is one level up in the accumulator stack. After performing your OUT (if needed) of the quotient you can perform a POP instruction to bring the remainder into the accumulator for any use you may make of it.
 

Similar Topics

Hi, I need help adding a new interlock switch to an existing circuit. I have never done on the existing circuit. I did set it up on the...
Replies
6
Views
279
Hi all I’m looking at adding a RFID card reader to comfort panel pro , how do you set the rfid up can you connect to existing users and password...
Replies
0
Views
94
Hello all! So I have one project with a S7-1214 and a MTP1500 "Project1" and one project with another S7-1214 "Project2". Both of these PLC:s need...
Replies
6
Views
150
Hi Everyone, Currently we have three plants running with Controllogix PLCs (L72, L73, L74). In each of these plants we have 2 FTView SE...
Replies
0
Views
122
Hello, Im building project with 1756-L82ES controller and 1756-IB16S card but i cant find it when trying to add the card to IO configuration...
Replies
3
Views
201
Back
Top Bottom