equal
deleted
inserted
replaced
|
1 (**************************************************************** |
|
2 |
|
3 RTC - Real-time clock |
|
4 |
|
5 Q is a copy of IN. |
|
6 |
|
7 When IN = FALSE, CDT is the current date and time as set by the |
|
8 PLC driver. |
|
9 |
|
10 When IN changes from FALSE to TRUE, PDT is stored. As long as IN is |
|
11 TRUE, CDT is equal to PDT + the amount of time since PDT was loaded. |
|
12 |
|
13 ****************************************************************) |
|
14 |
|
15 FUNCTION_BLOCK RTC |
|
16 VAR_INPUT |
|
17 IN : BOOL; (* 0 - current time, 1 - load time from |
|
18 PDT *) |
|
19 PDT : DT; (* Preset datetime *) |
|
20 END_VAR |
|
21 VAR_OUTPUT |
|
22 Q : BOOL := FALSE; (* Copy of IN *) |
|
23 CDT : DT; (* Datetime, current or relative to PDT *) |
|
24 END_VAR |
|
25 |
|
26 VAR |
|
27 PREV_IN : BOOL := FALSE; |
|
28 OFFSET : TIME; |
|
29 CURRENT_TIME : DT; |
|
30 END_VAR |
|
31 |
|
32 {__SET_VAR(data__->,CURRENT_TIME,__CURRENT_TIME)} |
|
33 |
|
34 IF IN |
|
35 THEN |
|
36 IF NOT PREV_IN |
|
37 THEN |
|
38 OFFSET := PDT - CURRENT_TIME; |
|
39 END_IF; |
|
40 |
|
41 (* PDT + time since PDT was loaded *) |
|
42 CDT := CURRENT_TIME + OFFSET; |
|
43 ELSE |
|
44 CDT := CURRENT_TIME; |
|
45 END_IF; |
|
46 |
|
47 Q := IN; |
|
48 PREV_IN := IN; |
|
49 |
|
50 END_FUNCTION_BLOCK |
|
51 |