Makers Blog

Retain Counter for Operating Hours for PLCnext Engineer

harald.baerdges@phoenixcontact.de 22 March 2021 min. read
419 views 0 comments

Hello, Friends of the PLCnext Technology.

A Customer asked me for a Retain Measurement of Operating Hours in the PLCnext Engineer.

Unfortunately there wasn’t anything available.

So i created my own Function Block. Here is all the information you need to use it yourself.

It automatically creates a second impuls by using two TON FBs if the Measurement-Input (Verbraucher) is high.

Using this method it creates Seconds, Minutes, Hours and up to 32.000 Days.

It can be reseted manually or by a Cold Start. Warm Start or switching the Controller On/Off

will keep the Values. Be sure to set the Measurement Variables to Retain! 

Variables:

Verbraucher – Bool – Input

xReset – Bool – Input

iCS – Integer – Output – Retain

iCM – Integer – Output – Retain

iCH – Integer – Output – Retain

iCD – Integer – Output – Retain

R_TRIG_UP – R_Trig, R_TRIG_RESET – R_Trig, TON1 – TON, TON2 – TON

Code:

TON1(IN := TON2.Q, PT := t#500ms, Q => , ET =>);
TON2(IN := (Verbraucher and not TON1.Q), PT := t#500ms, Q => , ET => );


R_TRIG_UP(CLK := TON2.Q);
R_TRIG_RESET(CLK := xReset);

If R_TRIG_UP.Q AND (iCS < 60) then iCS := iCS + INT#1;
    Elsif R_TRIG_Reset.Q OR iCS = 60 then iCS := INT#0;
    END_IF;
    
    
IF ICS = 60 then ICM := ICM + INT#1;
    Elsif R_TRIG_Reset.Q OR iCM = 60 then iCM := INT#0;
    END_IF;
    
IF ICM = 60 then ICH := ICH + INT#1;
    Elsif R_TRIG_Reset.Q OR iCH = 24 then iCH := INT#0;
    END_IF;        

IF ICH = 24 then ICD := ICD + INT#1;
    Elsif R_TRIG_Reset.Q OR iCD = 32000 then iCD := INT#0;
    END_IF;   

Note:

The Makers Blog shows applications and user stories of community members that are not tested or reviewed by Phoenix Contact. Use them at your own risk.

Discussion

Please login/register to comment

Login/Register

Leave a Reply

Newsletter
Never miss a new article
Sign up for the newsletter
Never miss news about PLCnext Technology
Get interesting content via newsletter four times a year
Receive exclusive information before all other users