Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
authorEdouard Tisserant
Fri, 03 Feb 2012 18:01:13 +0100
changeset 400 093b72cd2ac3
parent 399 55b074ea7255
child 402 ffa2afab2806
child 496 fa43fed1084c
Applied anonymous contribution RTC, '[Beremiz-devel] RTC function', 29/06/11
lib/accessor.h
lib/ieclib.txt
lib/rtc.txt
--- a/lib/accessor.h	Fri Feb 03 00:09:52 2012 +0100
+++ b/lib/accessor.h	Fri Feb 03 18:01:13 2012 +0100
@@ -57,6 +57,7 @@
 	__INIT_RETAIN(domain##__##name, retained)
 #define __INIT_EXTERNAL(type, global, name, retained)\
     {\
+        type* __GET_GLOBAL_##global();\
 		name.value = __GET_GLOBAL_##global();\
 		__INIT_RETAIN(name, retained)\
     }
--- a/lib/ieclib.txt	Fri Feb 03 00:09:52 2012 +0100
+++ b/lib/ieclib.txt	Fri Feb 03 18:01:13 2012 +0100
@@ -38,6 +38,7 @@
 {#include "integral_st.txt" }
 {#include "pid_st.txt" }
 {#include "ramp_st.txt" }
+{#include "rtc.txt" }
 
 (* Not in the standard, but useful nonetheless. *)
 {#include "sema.txt" }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/rtc.txt	Fri Feb 03 18:01:13 2012 +0100
@@ -0,0 +1,51 @@
+(****************************************************************
+
+              RTC - Real-time clock
+
+Q is a copy of IN.
+
+When IN = FALSE, CDT is the current date and time as set by the
+PLC driver.
+
+When IN changes from FALSE to TRUE, PDT is stored. As long as IN is
+TRUE, CDT is equal to PDT + the amount of time since PDT was loaded.
+
+****************************************************************)
+
+FUNCTION_BLOCK RTC
+   VAR_INPUT
+     IN : BOOL;                  (* 0 - current time, 1 - load time from 
+PDT *)
+     PDT : DT;                   (* Preset datetime *)
+   END_VAR
+   VAR_OUTPUT
+     Q : BOOL := FALSE;          (* Copy of IN *)
+     CDT : DT;                   (* Datetime, current or relative to PDT *)
+   END_VAR
+
+   VAR
+     PREV_IN : BOOL := FALSE;
+     OFFSET : TIME;
+     CURRENT_TIME : DT;
+   END_VAR
+
+   {__SET_VAR(data__->,CURRENT_TIME,__CURRENT_TIME)}
+
+   IF IN
+   THEN
+     IF NOT PREV_IN
+     THEN
+         OFFSET := PDT - CURRENT_TIME;
+     END_IF;
+
+     (* PDT + time since PDT was loaded *)
+     CDT := CURRENT_TIME + OFFSET;
+   ELSE
+     CDT := CURRENT_TIME;
+   END_IF;
+
+   Q := IN;
+   PREV_IN := IN;
+
+END_FUNCTION_BLOCK
+