Host Engineering Forum

General Category => General Discussion => Topic started by: jrayb on March 25, 2022, 12:14:22 PM

Title: Adding 7,200 Fifo blocks
Post 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?
Title: Re: Adding 7,200 Fifo blocks
Post by: RBPLC on March 25, 2022, 12:36:57 PM
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?
Title: Re: Adding 7,200 Fifo blocks
Post by: jrayb on March 25, 2022, 12:42:36 PM
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!!
Title: Re: Adding 7,200 Fifo blocks
Post by: Controls Guy on March 25, 2022, 01:04:42 PM
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.

Title: Re: Adding 7,200 Fifo blocks
Post by: Controls Guy on March 25, 2022, 01:06:38 PM
You also obviously should think about the possibility of overflow.  Maybe segment the result into multiple registers and build your own 64-bit number.
Title: Re: Adding 7,200 Fifo blocks
Post by: jrayb on March 25, 2022, 01:15:45 PM
Thanks for the help guys. That did the trick ControlsGuy!!
Title: Re: Adding 7,200 Fifo blocks
Post by: BobO on March 25, 2022, 01:39:35 PM
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.
Title: Re: Adding 7,200 Fifo blocks
Post by: franji1 on March 25, 2022, 01:43:38 PM
What is the typical range of values for these D registers?  What is the Max?  Can they be negative?
Title: Re: Adding 7,200 Fifo blocks
Post by: Controls Guy on March 25, 2022, 03:10:08 PM
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.