Files
Adeco_20220119-01/TC3_CNCPLCBase/OEM/FB_Papiervorschub.TcPOU
Matthias Heisig 51d6e7e5c4 Initial commit
2024-10-22 14:22:54 +02:00

299 lines
7.7 KiB
XML

<?xml version="1.0" encoding="utf-8"?>
<TcPlcObject Version="1.1.0.1" ProductVersion="3.1.4024.6">
<POU Name="FB_Papiervorschub" Id="{668a62cf-64c8-49b5-ae3e-8fde0e3961f5}" SpecialFunc="None">
<Declaration><![CDATA[FUNCTION_BLOCK FB_Papiervorschub
VAR_INPUT
bExecute : BOOL;
bReset : BOOL;
bInfeedEnabled : BOOL;
fMMToGo : LREAL;
nMEnable : UINT := 50;
uiEncoderValue : UINT;
fMMPerRev : LREAL := 200;
nIncrPerRev : UINT := 1024;
fNSoll : LREAL := -400;
END_VAR
VAR_OUTPUT
bDone : BOOL;
bError : BOOL;
END_VAR
VAR
uiZSW1 AT %I* : UINT;
uiSTW1 AT %Q* : UINT;
iNSoll_A AT %Q* : INT;
iNIst_A AT %I* : INT;
wZSW1 : WORD;
wSTW1 : WORD;
nTargetPosition : DINT;
nActualPosition : DINT;
nDiff : DINT;
uiEncoderValueOld : UINT;
fPathToGo : LREAL;
nState : INT := 0;
nErrorState : INT := -1;
rtStart : R_TRIG;
rtReset : R_TRIG;
rtMFunctionStart : R_TRIG;
ftError : F_TRIG;
tofReset : TOF;
tonPollage : TON;
(*
bTest : BOOL;
fbADSRead : ADSREAD;
fbADSWrite : ADSWRITE;
ReadPort : T_AMSPort := 16#1002;
ReadGroup : UDINT := 16#F302;
ReadGroupOffset : UDINT := 16#0FA60000;
ReadLen : UDINT := 30;
ReadAdsDest : BYTE;
*)
END_VAR
]]></Declaration>
<Implementation>
<ST><![CDATA[// Einlesen
wZSW1 := UINT_TO_WORD(uiZSW1);
// Führung durch PLC
wSTW1.10 := 1;
// Start bei steigender Flanke
rtStart(CLK := bExecute);
rtMFunctionStart(CLK:= CNCSystem.Channel[0].M[nMEnable].bState_rw);
// Reset der Achse
tofReset(IN := bReset, PT := T#250MS);
wSTW1.7 := tofReset.Q;
// Error trigger
ftError(CLK := wZSW1.3);
// Fehlerzustand weitergeben
bError := wZSW1.3;
// Fehlerzustand
IF (wZSW1.3 = 1) AND (nState < 99) THEN
nErrorState := nState;
iNSoll_A := 0;
nState := 99;
END_IF
// Positionsnachführung
nDiff := ((nIncrPerRev + nIncrPerRev / 2 + (uiEncoderValue - uiEncoderValueOld)) MOD nIncrPerRev) - (nIncrPerRev / 2);
nActualPosition := nActualPosition + nDiff;
uiEncoderValueOld := uiEncoderValue;
CASE nState OF
0: // Idle -> Einschalten
wStW1.0 := 0; // Ein
wStW1.1 := 0; // Nicht Austrudel
wStW1.2 := 0; // Kein Schnellhalt
wStW1.3 := 0; // Betrieb freigeben
wSTW1.4 := 0; // EPOS nicht Verwerfen
wSTW1.5 := 0; // EPOS kein Zwischenhalt
wSTW1.6 := 0; // EPOS Verfahrauftrag aktivieren 0 -> 1
iNSoll_A := 0;
IF rtStart.Q AND bInfeedEnabled THEN
bDone := FALSE;
nActualPosition := 0;
nTargetPosition := LREAL_TO_DINT(nActualPosition + (nIncrPerRev * fMMToGo / fMMPerRev));
nState := 10;
END_IF
IF rtMFunctionStart.Q AND bInfeedEnabled THEN
bDone := FALSE;
nActualPosition := 0;
nTargetPosition := LREAL_TO_DINT(nActualPosition + (nIncrPerRev * CNCSystem.Channel[0].M[nMEnable].nArgument_r / fMMPerRev));
nState := 10;
END_IF
10: // Warten auf Einschaltbereit -> Betriebsbereit
wStW1.0 := 0; // Ein
wStW1.1 := 1; // Nicht Austrudel
wStW1.2 := 1; // Kein Schnellhalt
wStW1.3 := 1; // Betrieb freigeben
wSTW1.4 := 1; // Hochlaufgeber freigeben
wSTW1.5 := 1; // Hochlaufgeber starten
wSTW1.6 := 1; // Sollwerte Freigeben
IF wZSW1.0 THEN // Einschaltbereit
nState := 20;
END_IF
20: // Warten auf Betriebsbereit
wStW1.0 := 1; // Ein
wStW1.1 := 1; // Nicht Austrudel
wStW1.2 := 1; // Kein Schnellhalt
wStW1.3 := 1; // Betrieb freigeben
wSTW1.4 := 1; // Hochlaufgeber freigeben
wSTW1.5 := 1; // Hochlaufgeber starten
wSTW1.6 := 1; // Sollwerte Freigeben
IF wZSW1.1 THEN // Betriebsbereit
nState := 25;
END_IF
25: // Warten auf pollagenidentifikation
tonPollage(IN := TRUE, PT := T#500MS);
IF tonPollage.Q THEN
tonPollage(IN := FALSE);
nState := 30;
END_IF
30: // Betriebsbereit -> Bewegungsparameter setzen
wStW1.0 := 1; // Ein
wStW1.1 := 1; // Nicht Austrudel
wStW1.2 := 1; // Kein Schnellhalt
wStW1.3 := 1; // Betrieb freigeben
wSTW1.4 := 1; // Hochlaufgeber freigeben
wSTW1.5 := 1; // Hochlaufgeber starten
wSTW1.6 := 1; // Sollwerte Freigeben
// Berechnung des Ausgabewertes
iNSoll_A := LREAL_TO_INT((16384 * fNSoll) / 1500);
IF nActualPosition >= nTargetPosition THEN
iNSoll_A := 0;
nState := 40;
END_IF
40: // Ausschalten
wStW1.0 := 0; // Ein
wStW1.1 := 1; // Nicht Austrudel
wStW1.2 := 1; // Kein Schnellhalt
wStW1.3 := 1; // Betrieb freigeben
wSTW1.4 := 0; // Hochlaufgeber freigeben
wSTW1.5 := 0; // Hochlaufgeber starten
wSTW1.6 := 0; // Sollwerte Freigeben
IF NOT wZSW1.1 THEN
nState := 0;
CNCSystem.Channel[0].M[nMEnable].bState_rw := FALSE;
bDone := TRUE;
END_IF
99: // Fehler
IF ftError.Q OR (wZSW1.3 = 0) THEN
nState := 0;
END_IF
END_CASE
(*
ReadGroupOffset := 16#0FA60000;
fbADSRead(
NETID := '172.18.236.82.5.17',
PORT := ReadPort,
IDXGRP := ReadGroup,
IDXOFFS := ReadGroupOffset,
LEN := ReadLen,
DESTADDR := ADR(ReadAdsDest),
READ := bTest,
TMOUT := T#1S);
*)
(*
ReadAdsDest := 1;
fbADSWrite(
NETID := '172.18.236.82.5.17',
PORT := ReadPort,
IDXGRP := ReadGroup,
IDXOFFS := ReadGroupOffset,
LEN := 1,
SRCADDR := ADR(ReadAdsDest),
WRITE := bTest,
TMOUT := T#1S);
*)
uiSTW1 := WORD_TO_UINT(wStw1);]]></ST>
</Implementation>
<LineIds Name="FB_Papiervorschub">
<LineId Id="39" Count="0" />
<LineId Id="37" Count="0" />
<LineId Id="41" Count="1" />
<LineId Id="40" Count="0" />
<LineId Id="59" Count="0" />
<LineId Id="61" Count="0" />
<LineId Id="60" Count="0" />
<LineId Id="387" Count="0" />
<LineId Id="47" Count="2" />
<LineId Id="38" Count="0" />
<LineId Id="195" Count="1" />
<LineId Id="194" Count="0" />
<LineId Id="198" Count="1" />
<LineId Id="197" Count="0" />
<LineId Id="54" Count="3" />
<LineId Id="147" Count="0" />
<LineId Id="58" Count="0" />
<LineId Id="53" Count="0" />
<LineId Id="165" Count="0" />
<LineId Id="162" Count="0" />
<LineId Id="333" Count="0" />
<LineId Id="161" Count="0" />
<LineId Id="164" Count="0" />
<LineId Id="64" Count="9" />
<LineId Id="145" Count="1" />
<LineId Id="76" Count="2" />
<LineId Id="151" Count="0" />
<LineId Id="158" Count="0" />
<LineId Id="80" Count="0" />
<LineId Id="84" Count="0" />
<LineId Id="388" Count="2" />
<LineId Id="392" Count="2" />
<LineId Id="391" Count="0" />
<LineId Id="85" Count="8" />
<LineId Id="96" Count="13" />
<LineId Id="111" Count="2" />
<LineId Id="63" Count="0" />
<LineId Id="398" Count="5" />
<LineId Id="405" Count="0" />
<LineId Id="404" Count="0" />
<LineId Id="116" Count="0" />
<LineId Id="118" Count="7" />
<LineId Id="136" Count="1" />
<LineId Id="144" Count="0" />
<LineId Id="148" Count="1" />
<LineId Id="168" Count="0" />
<LineId Id="166" Count="1" />
<LineId Id="169" Count="1" />
<LineId Id="172" Count="5" />
<LineId Id="171" Count="0" />
<LineId Id="178" Count="0" />
<LineId Id="180" Count="1" />
<LineId Id="395" Count="0" />
<LineId Id="182" Count="0" />
<LineId Id="179" Count="0" />
<LineId Id="183" Count="0" />
<LineId Id="185" Count="0" />
<LineId Id="188" Count="1" />
<LineId Id="184" Count="0" />
<LineId Id="143" Count="0" />
<LineId Id="331" Count="0" />
<LineId Id="313" Count="0" />
<LineId Id="312" Count="0" />
<LineId Id="253" Count="0" />
<LineId Id="252" Count="0" />
<LineId Id="254" Count="7" />
<LineId Id="326" Count="1" />
<LineId Id="315" Count="1" />
<LineId Id="319" Count="3" />
<LineId Id="318" Count="0" />
<LineId Id="323" Count="2" />
<LineId Id="328" Count="0" />
<LineId Id="317" Count="0" />
<LineId Id="193" Count="0" />
<LineId Id="192" Count="0" />
</LineIds>
</POU>
</TcPlcObject>