FUNCTION_BLOCK "Pulser"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
Reset { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool; // Zurücksetzen auch bei Start=1
Start { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool; // Pos. Flanke startet Pulser
T_On { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Time; // Zeit für Signal=1
T_Off { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Time; // Zeit für Signal=0
Repeats { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Int; // Anzahl der Pulse, 0=unendlich
END_VAR
VAR_OUTPUT
Signal { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool; // Pulsierender Ausgang
Active { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool; // Aktiv
Done { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool; // Erreichen der Wiederholungen
Count { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Int; // Aktuelle Wiederholungen
END_VAR
VAR
Start_Prev { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool;
"Timer" {InstructionName := 'TON_TIME'; LibVersion := '1.0'; ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : TON_TIME;
Timer_Q { ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'} : Bool;
"Counter" {InstructionName := 'CTU_INT'; LibVersion := '1.0'; ExternalAccessible := 'False'; ExternalVisible := 'False'; ExternalWritable := 'False'; S7_SetPoint := 'False'} : CTU_INT;
END_VAR
BEGIN
// Starten bei positiver Flanke
IF NOT #Reset AND #Start AND NOT #Start_Prev AND NOT #Active THEN
#Active := TRUE;
#Done := FALSE;
END_IF;
#Start_Prev := #Start;
// Beenden bei Reset oder nach erreichen der Anzahl
IF #Reset OR #Done THEN
#Active := FALSE;
END_IF;
// Timer
#Timer(IN := #Active AND NOT #Timer_Q,
PT := (#T_On + #T_Off));
#Timer_Q := #Timer.Q;
// Ausgang Signal setzen
IF #Active AND #Timer.ET <= #T_On THEN
#Signal := TRUE;
ELSE
#Signal := FALSE;
END_IF;
// Zählen der Pulse
#Counter(CU := #Signal,
PV := #Repeats,
R := NOT #Active);
#Count := #Counter.CV;
// Bei erreichen der Pulse beenden // Unendlich pulsen bei Repeats=0
IF #Counter.QU AND NOT #Signal AND #Repeats>0 THEN
#Done := TRUE;
END_IF;
IF #Reset THEN
#Done := FALSE;
END_IF;
END_FUNCTION_BLOCK