etisserant@0:  FUNCTION_BLOCK DERIVATIVE
etisserant@0:    VAR_INPUT
etisserant@0:      RUN : BOOL ;          (* 0 = reset                  *)
etisserant@0:      XIN : REAL ;          (* Input to be differentiated *)
etisserant@0:      CYCLE : TIME ;        (* Sampling period            *)
etisserant@0:    END_VAR
etisserant@0:    VAR_OUTPUT
etisserant@0:      XOUT : REAL ;         (* Differentiated output      *)
etisserant@0:    END_VAR
etisserant@0:    VAR X1, X2, X3 : REAL ; END_VAR
etisserant@0:    IF RUN THEN
etisserant@0:       XOUT := (3.0 * (XIN - X3) + X1 - X2)
etisserant@0:               / (10.0 * TIME_TO_REAL(CYCLE)) ;
etisserant@0:       X3 := X2 ; X2 := X1 ; X1 := XIN ;
etisserant@0:    ELSE XOUT := 0.0; X1 := XIN ; X2 := XIN ; X3 := XIN ;
etisserant@0:    END_IF ;
etisserant@0:  END_FUNCTION_BLOCK
etisserant@0: