Forum Home › Forums › Understanding the Software › Using Formulas › Average value from 5 last values
- This topic has 7 replies, 2 voices, and was last updated 1 month, 2 weeks ago by
Mikhail.
-
AuthorPosts
-
February 27, 2025 at 6:20 am #16202
BamKR
ParticipantHello,
I am trying to make formula for calculate average value from last 5 values.
In firts steps formula update values every time when trigger state change from 1 to 0. State change of this trigger also mean that value is changed.I want to use automatic module for triggering formula in state changing moment, val=0 send command to channel with formula on output to calculate average and update values. I make formula but it don’t update values. Thanks for help.public double TimeUpdate() { double time1 = Val(145); double time2 = Val(146); double time3 = Val(147); double time4 = Val(148); double time5 = Val(149); double newTime = Val(144); SetVal(149, time4); SetVal(148, time3); SetVal(147, time22); SetVal(146, time11); SetVal(145, newTime); double average = (time1 + time2 + time3 + time4 + time5) / 5.0; SetVal(151, average); return average; }
February 27, 2025 at 10:33 am #16205February 27, 2025 at 10:43 am #16209BamKR
ParticipantHello,
I think I solved problem, values in formula wasn’t displayed till i put in input formula Val(cnl). For example, on channel [115] Value 1 I put input formula Val(115), and for other channel also like on img.
February 28, 2025 at 10:42 am #16211Mikhail
ModeratorHello,
It seems that using theVal(145)
input formula in the channel 145 is excessive.March 4, 2025 at 10:15 am #16217BamKR
ParticipantYes, but when I don’t make self-reference, value is not displayed on channels. Maybe you know what I am doing wrong ? I am using setvalue function in formula but it is not enough.
March 4, 2025 at 10:59 am #16218Mikhail
ModeratorIf you remove Val(145) in that channel, where do you set the channel’s 145 value? Which place the TimeUpdate() function is called?
March 4, 2025 at 11:41 am #16219BamKR
ParticipantI am setting 145 value using value from plc stopwatch from value 144. TimeUpdate() is called on output formula on channel 150 from automatic module when input state is changing on plc. Everytime when input state is changing, I replace value on channels by 1 moving up.
public double UpdateTimes() { double time1 = Val(145); double time2 = Val(146); double time3 = Val(147); double time4 = Val(148); double time5 = Val(149); double newTime = Val(144); SetVal(149, time4); SetVal(148, time3); SetVal(147, time2); SetVal(146, time1); SetVal(145, newTime); double average = (time1 + time2 + time3 + time4 + time5) / 5.0; SetVal(151, average); double average_time = (Val(103) * 60) / Val(143); SetVal(153, average_time); return average; }
-
This reply was modified 1 month, 2 weeks ago by
BamKR.
March 5, 2025 at 11:08 am #16222Mikhail
ModeratorMay be you should set an input formula of the channel 145 to blank, and try again.
-
This reply was modified 1 month, 2 weeks ago by
-
AuthorPosts
- You must be logged in to reply to this topic.