PT2 Ãœbertragungsglied

Begonnen von hugo, 04. Januar 2007, 11:51:37

Vorheriges Thema - Nächstes Thema

0 Mitglieder und 5 Gäste betrachten dieses Thema.

hugo

FUNCTION_BLOCK FT_PT2
VAR_INPUT
   in : REAL;
   T1 : TIME;
   T2 : TIME;
   K : REAL := 1;
END_VAR
VAR_OUTPUT
   out : REAL;
END_VAR
VAR
   last : TIME;
   tx: TIME;
   init: BOOL;
   out1 : REAL;
   out2 : REAL;
END_VAR

(*
version 1.1   1 jan 2007
programmer    hugo
tested by      tobias

FT_PT2 is a 2nd grade filter with programmable times T1, T2 and faktor K.

*)

tx := TIME();
IF NOT init THEN
   last := tx;
   init := TRUE;
ELSE
   IF T1> t#0s THEN
      out1 := out1 + (in - out1) * TIME_TO_REAL(Tx - last) / TIME_TO_REAL(T1);
   ELSE
      out1 := in;
   END_IF;
   IF T2 > t#0s THEN
      out2 := out2 + (out1 - out2) * TIME_TO_REAL(Tx - last) / TIME_TO_REAL(T2);
   ELSE
      out2 := out1;
   END_IF;
   out := out2 * K;
END_IF;
last := tx;