Posted 31 Jan 2018 Hi everybody I'm trying to create a code to count an absolute value from my Q64AD module. I found absolute value function ABS, but its working somewhat strange, and i do not see the difference between real value and absolute value. Then I created a timer for an absolute value with some mathematics: SUM1:= SUM1 + napr1; Nsum := Nsum + 1; IF timer_sr.Q THEN timer_sr(IN:= NOT timer_sr.Q , PT:= T#100ms); outsr := SUM1 /Nsum; Nsum := 0; SUM2 := 0; END_IF; where napr1 - is value from Q64AD module ch1. It worked on codesys, but not working here. Data type of sum1, napr1, nsum is Word[signed]. In codesys Nsum was INT type. What's the difference and what i did wrong? Share this post Link to post Share on other sites
Posted 31 Jan 2018 (edited) Well you're timer is inside the IF. Either take it out and put before the IF or set it to true before the if. Your if is never getting executed. I'm not 100% sure it will work with the output as an input. Maybe try using an extra variable. SUM1:= SUM1 + napr1; Nsum := Nsum + 1; timer_sr(IN:= NOT timer_sr.Q , PT:= T#100ms); IF timer_sr.Q THEN outsr := SUM1 /Nsum; Nsum := 0; SUM2 := 0; END_IF; Edited 31 Jan 2018 by Andrei Blagaila Share this post Link to post Share on other sites
Posted 1 Feb 2018 The thing is it's working, but not as needed. It just divides Sum1 on Nsum in real values, but not stores SUM1 values and divides them on Nsum value (Nsum is number of values stored in SUM1) Share this post Link to post Share on other sites