Reputation: 1
Being new in PLC programming, I am struggling with the programming of countdown timer in PLC. I want to add a countdown timer for 90 days that will be reset to again 90 days once the button on HMI is pressed. The countdown time should be shown on the HMI display. No IO connected, only countdown timer.
Upvotes: 0
Views: 1731
Reputation: 1424
You question is too wide in my opinion. Have you tried to solve it yourself? What is the PLC environment you are using?
Here is something for start, perhaps?
Edit: Here is a working program for Infoteam OpenPCS. I have never used it before but had to test it for curiosity. I managed to get current datetime but it wasn't possible to convert to DWORD
for calculation, so I used this kind of approach (Sergey, do you know how to do it? I tried to convert it using POINTER
but couldn't dereference it..) I haven't tested it for longer delays, so please note that it might not be 100% working.
It calculates 60 second intervals (=minutes) and when enough minutes are passed, timer stops. Note that the minutes should be saved to persistent memory if power losses etc. shouldn't affect it.
VAR
RunTimer : BOOL;
MinutesElapsed : UDINT;
StartTime : TIME;
TimeDifference : TIME;
END_VAR
IF RunTimer THEN
IF StartTime = t#0s THEN
StartTime := GetTime(StartTime);
END_IF;
TimeDifference := GetTime(StartTime);
(*IF one minute has elapsed*)
IF TimeDifference >= t#1m THEN
MinutesElapsed := MinutesElapsed + 1;
(*Reset StartTime to start minute over*)
StartTime := t#0s;
END_IF;
(*IF enough minutes has passed, stop (90*24*60 = 90 days)*)
IF MinutesElapsed >= (90 * 24 * 60) THEN
RunTimer := false;
StartTime := t#0s;
TimeDifference := t#0s;
MinutesElapsed := 0;
END_IF;
else
(*Time is not running*)
StartTime := t#0s;
TimeDifference := t#0s;
MinutesElapsed := 0;
(*Here we would set RunTimer to TRUE when button is pressed to start time again*)
END_IF;
Upvotes: 1