0

I need to obtain an average value of my input signals from mitsubishi input module Q64AD. I'm working in GX Works 2 in structured text.

This is how i used to obtain average value in Codesys:

timer_sr(IN:= NOT timer_sr.Q , PT:= T#5s );

SUM1:= SUM1 + napr1;
Nsum:=Nsum + 1;

IF timer_sr.Q THEN
    timer_sr(IN:= NOT timer_sr.Q , PT:= T#5s);
    outsr := SUM1 /Nsum;
    Nsum := 0;
    SUM1 := 0;
END_IF;

napr1 - is value from module

This piece of code is not working in GX Works 2, and i think because SUM1 is not an INT data type, but just a Word[signed] type.

Is there a way to make SUM1 an INT type or may be there is another logic to that solution?

Roman Selin
  • 109
  • 1
  • 16

1 Answers1

0

In other platforms it should work but the compiler gives a warning so I guess it will still compile? Of course, if the value is negative there will be problems.

You can convert a WORD to INT by the IEC function WORD_TO_INT. I'm not sure how well your system follows the standard but if it does, try the following: WORD_TO_INT(SUM1). If the SUM1 > 65535 then there will be problems as the upper bound of INTis 32767.

If this doesn't help, could you provide more details? How is it not workin?

Ps. The WORD is unsigned data type, not signed as you wrote.

Quirzo
  • 1,183
  • 8
  • 10