1/9/2021 4:17 AM | |
Joined: 12/18/2014 Last visit: 12/1/2023 Posts: 31530 Rating:
|
Maybe this is what you want.
AttachmentAverage_0BA8.Standard.zip (200 Downloads) |
1/9/2021 10:42 AM | |
Joined: 12/3/2018 Last visit: 10/18/2023 Posts: 75 Rating:
|
It should be formed continuously... but the sample time is unknown in advance. That`s why I choosed 1 minute, but the average should be cumulative, not only for the last minute but for the whole f.i. 20min, 45min or any other period lenghts. And for more periods, not only for one (until reset). About your program: I have hard time to understand it in order to test it, that`s why I don`t know if it fits altogether. I change it a little to more match my situation and for easier following (please, see ver2). Please, can you explain just a little bit: - where can I read out an average output? Is it B005 Aq? - sampling time is every minute? Where can I change that, if needed? - can I reset the calculated average value somewhere and force it to begin calculation again? I tried to test it like this but it gives me strange results: - for the first minute I set A1 at fixed -10°C - after one minute B005Aq displays - 10° which is OK (if this should be output) - for the second minute I quickly set A1 to +10°C - after second minute past, the output should show average for BOTH minutes 0 (-10 + 10 = 0) but it shows me 10° So I think, it only calculates the average of last minute and does not include old values. Basically it works like normal average block without anything around (that why I put the B007 next, for comparision). About the I1 (working period simulation): if I set it to zero - that would mean pause in heating - in that off-time the average temperature should be freezed to last calculated state, until a new heating period is started. I think now is not working this way? It just puts a new value to output, which is not good. But as I said, maybe I just don`t know how to use your program. AttachmentAverage_0BA8.Standard_v2.zip (146 Downloads) |
1/9/2021 5:49 PM | |
Joined: 2/22/2008 Last visit: 11/30/2023 Posts: 2698 Rating:
|
Frayer, that's not difficult to calculate an average for a limited amount of values. Also the S7 FB average cannot calculate endless values, because for arithmetic average you need to sum all values X1, X2, X3 ... Xn and devide it by n. For this you need n blocks to store the values. Depend on your application and free resources it may be possible to use e.g. 50 values. For this you need 50 Min/Max blocks to store the values and several arithmetic blocks to calculate the average. See attachment for an example with 9 blocks and additional arithmetic. The calculation is splitted, a group of 3 blocks needs 1 arithmetic block. The 3 arithmetic blocks needs a final arithmetic block. If you need more values for average, the program will grow up more and more with higher amounts. The example has a pulse generator TH=0,5s and TL=0,5s for simulation with 1s. Change it to TH=30s and TL=30s for 1m. Then you can calculate the average for 9 minutes for active mode (I1=On). Expand the Min/Max chain for your desired amount of values depend on your free resources. Regards, Scorp AttachmentAverage1.zip (153 Downloads) |
This contribution was helpful to
1 thankful Users |
1/9/2021 11:11 PM | |
Joined: 2/22/2008 Last visit: 11/30/2023 Posts: 2698 Rating:
|
There are 2 different methodes to calculate the arithmetic average. The first one is the described methode to store all values and then build the sum and device by amount of values. Sure there is a second methode, which can be used with S7. All values are added directly and a counter is used for the amount of values. Then you have X1+X2+X3....+Xn and n. But this methode you can not use in the Logo, because you only have 16 bit integer values from -32768 up to +32767. May be with some tricks it's possible to create higher values (e.g. 32 bit) to reduce the amount of blocks from my first example. But this is also very complicated and i only can try to find a solution. For this i need the information, which values you have, -100 to +100, -1000 to +1000, -10000 to +10000 ? If you are not fixed on a Logo, it would be better to use another logic controller with 32 bit integer. You can add e.g. 10000 for >400000 times, before there is an overflow. In Logo you only can add 3 times. You see the difference ? Generally you also have to check, if arithmetic average is the right value for your function. Have a look at Wikipedia for different averages, arithmetic, geometric, harmonic ... Regards, Scorp |
Follow us on