Download this file
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
{attribute 'hide_all_locals'} FUNCTION_BLOCK FB_B11_FaultCounter EXTENDS FB_Prot_Base VAR_INPUT uiCounter : UINT; bReset : BOOL; END_VAR VAR_OUTPUT lrThreshold: LREAL; tOND: TIME; VAR bInit : BOOL := TRUE; Ts: LREAL; lrPeriod : LREAL; _Angle : TTB.FB_IntegratorRanged; _EdgeResetAuto : Standard.R_TRIG; _EdgeResetMan : Standard.R_TRIG; _Sample : TTB.FB_SampleHold; // Calculate period IF bInit THEN Ts := TTB.F_lrGetSampleTime(); lrPeriod := 2.0/MAX(TIME_TO_LREAL(tsData.tTOND),Ts); bInit:=FALSE; END_IF // detect edge on manual reset signal _EdgeResetMan(CLK:=bReset); // Create counter for periodic reset _Sample(bSet:=_EdgeResetAuto.Q OR _EdgeResetMan.Q,lrI:=UINT_TO_LREAL(uiCounter)); _bFault := (UINT_TO_LREAL(uiCounter)- _Sample.lrQ) > tsData.lrThreshold AND tsData.bIsEnabled; // Execute base block SUPER^(tsData := tsData, tsProt := tsProt); // Assign further parameter for visualization lrThreshold := tsData.lrThreshold; tOND := tsData.tTOND;