TONOFP2

Begonnen von stlfx, 24. September 2015, 13:06:19

Vorheriges Thema - Nächstes Thema

0 Mitglieder und 2 Gäste betrachten dieses Thema.

stlfx

Hallo!

This is my first post here. I wrote this function, may be somebody interested.

TONOFP2 generated a T_ON Delay on start pulse, and T_OFF Delay after end of pulses on Input IN.

Best regards,
MJ


FUNCTION_BLOCK TONOFP2
TITLE = 'TONOFP2'
//
//TONOFP2 generated a T_ON Delay on start pulse, and T_OFF Delay after end of pulses on Input IN
//
VERSION : '0.1'
AUTHOR  : MJ
NAME    : TONOFP2
FAMILY  : M

VAR_INPUT
  IN : BOOL;
  PAUSE : BOOL;
  RESET : BOOL;
  T_ON, T_OFF : TIME;
 
END_VAR
VAR_OUTPUT
  Q : BOOL;
END_VAR
VAR
  TON_ON : TON;
  TON_OFF : TON;
 
  T_ON_REMAINING, T_OFF_REMAINING : TIME;
 
  init: BOOL;
  lastpause: BOOL;
  pulse: BOOL; 

END_VAR

BEGIN

IF RESET THEN 
  TON_ON(IN := FALSE, PT := T_ON);
  TON_OFF(IN := FALSE, PT := T_OFF);
  init := FALSE;
  Q := FALSE;
ELSE
       

  IF IN AND NOT pulse THEN
    TON_OFF(IN := FALSE, PT := T_OFF);
    T_OFF_REMAINING := T_OFF;
    IF NOT init THEN
      init := TRUE;
      TON_ON(IN := FALSE, PT := T_ON);
    END_IF;
    T_ON_REMAINING := T_ON;
  END_IF;

  pulse := IN;

  IF init AND NOT PAUSE THEN
    TON_ON(IN := TRUE);
    TON_OFF(IN := TRUE);
  END_IF;

  IF TON_ON.Q THEN
    Q := TRUE;
  END_IF;

  IF TON_OFF.Q THEN
    Q := FALSE;
    init := FALSE;
  END_IF;

  IF init THEN
    IF PAUSE AND NOT lastpause THEN
      T_ON_REMAINING := T_ON_REMAINING - TON_ON.ET;
      TON_ON(IN := FALSE, PT := T_ON_REMAINING);
      T_OFF_REMAINING := T_OFF_REMAINING - TON_OFF.ET;
      TON_OFF(IN := FALSE, PT := T_OFF_REMAINING);
    END_IF;
  END_IF;

  lastpause := PAUSE;

END_IF;

END_FUNCTION_BLOCK



[gelöscht durch Administrator]