Host Engineering Forum
General Category => General Discussion => Topic started by: jrayb on March 25, 2022, 12:14:22 PM
-
I don't know an easier way to add 7,200 FiFo Blocks for a sum other than using the Math Function. It would take me a really long time to create that function. Can anyone help me with an easier route?
-
Your question isn't clear. What exactly are you trying to do? Are you saying that you've got 7200 elements in your FIFO block and you want to sum all of these elements?
-
Yes, I want to sum all of the blocks. I want to be able to have a running total of that sum. I have the FiFo Block setup & it's working properly. I just need to be able to get the sum of the FiFo blocks as they're running. I can do this with a math function. Say Fifoblockone+fifoblocktwo etc. It would take me a tremendous amount of time to create a math function to sum 7,200 fifo blocks. Thanks for your help!!
-
MATH D0 "SUMR(D1, 7200)"
If you don't want to do that, I'd iterate through using a loop and indirect addressing, so the MATH expression will be manageable.
At least once you have the sum, it's much quicker to maintain. Every time you index, add the new value and subtract the one that got pushed off. In fact, so long as you start from the beginning, and it's initially filled with zeros, you can do that while you're filling it too.
-
You also obviously should think about the possibility of overflow. Maybe segment the result into multiple registers and build your own 64-bit number.
-
Thanks for the help guys. That did the trick ControlsGuy!!
-
MATH D0 "SUMR(D1, 7200)"
If you don't want to do that, I'd iterate through using a loop and indirect addressing, so the MATH expression will be manageable.
At least once you have the sum, it's much quicker to maintain. Every time you index, add the new value and subtract the one that got pushed off. In fact, so long as you start from the beginning, and it's initially filled with zeros, you can do that while you're filling it too.
Might be a pretty decent scan bump with SUMR of 7200 elements. Loop lets you spread it out. May not be an issue if just a single scan bump though.
-
What is the typical range of values for these D registers? What is the Max? Can they be negative?
-
Might be a pretty decent scan bump with SUMR of 7200 elements. Loop lets you spread it out. May not be an issue if just a single scan bump though.
Yep, and you can also do a hybrid. 72 loop iterations SUMRing 100 element per.