maybe I can explain it better than I did before.
i have an ab micrologix 1100.with analog card im just a basic programmer i just need a simple way to do this the sugar travels through a pipe about 100kg a minute and goes into a bin when it reaches 2000 kg it is dumped into a mixer all i care about is how fast that sugar is coming into the bin
Think it through one step at a time.
The "analog in" is always moving and changing while in use. Sugar is flowing over a scale and the weight is changing?
Is this a continuous flow ?
What motivates the sugar? conveyor? airveyor? pump? is it dry or a slurry?
How does the scale read the weight of the sugar? is there a part of a conveyor sitting on a scale?
I have never been a fan of weighing things as they move, but if that's what is needed, we can sort of do it.
How fast is the sugar moving? this will suggest the sample rate.
Process details are usually more important than controls hardware details, unless you want an actual example program written.
So we have sugar moving over a scale and the "analog in" is moving around as the weight changes.
If you take a reading at some moment in time, you get an idea of what is on the scale at that moment.
I would take another reading after that material has moved off the scale. So if the sugar moves at a constant pace, how long is the sugar on the scale?
Imagine squirting food coloring on the sugar in a line across the conveyor as it moves. Now imagine how long that line is on the scale as it passes by.
That would be my sample rate.(I would tie the sample rate to the conveyor speed, but if the conveyor is constant you might skip that part and make the sample rate a constant. Imagine what will happen if the conveyor stops and you keep adding the scale reading to the total.
So every X seconds, take a sample.
Read the analog in and move that number somewhere.
Now do that again.
Now add those two numbers together.
(I would just add the total to to some location and just use one memory location. Like "sample weight" plus "total" equals "total".)
If you stop here you have an ever increasing number equal to the total sugar going by.
Now a separate timer is running to give you a units per time period reading.(I would use a bit from converting the real time clock from double integers to bits, but you can use a timer if you like.)
Alternately , you could add the samples up, like if you take a sample every 10 seconds, then every 6th sample take that reading as Weight per minute and clear the total and start over. That might be easier for you and only uses one timer.
When this second timer is done, move the current total to a new location, that is your units per time period.
And then clear the total and the timer in the next rung.
This captures the total in that time frame or window.
Now you begin a new running total.
You can display the units per time period number as "weight of sugar / time".
The first time you run the machine, the total will display a blank number while you build some history, but if your reading the total every minute, no one will notice.
It doesn't get much simpler than that.
1 read the scale at some interval.
2 add reading to previous reading
3 at some time period, or after some number of samples, take the total as the weight per time period
4 clear the total and repeat.