Updating origin and license info of library fuctions.
Conclude missing counter FBs.
--- a/lib/counter.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/counter.txt Mon Apr 04 15:26:13 2011 +0100
@@ -18,6 +18,13 @@
*)
+
+(******************)
+(* *)
+(* C T U *)
+(* *)
+(******************)
+
FUNCTION_BLOCK CTU
VAR_INPUT
CU : BOOL;
@@ -28,16 +35,96 @@
Q : BOOL;
CV : INT;
END_VAR
-
- VAR RRR : REAL; END_VAR
- RRR := 9.9;
-
- IF R THEN CV := 0 ;
- ELSIF CU AND (CV < PV)
- THEN CV := CV+1;
- END_IF ;
- Q := (CV >= PV) ;
-END_FUNCTION_BLOCK
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_DINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : DINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : DINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_LINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : LINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : LINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_UDINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : UDINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : UDINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTU_ULINT
+ VAR_INPUT
+ CU : BOOL;
+ R : BOOL;
+ PV : ULINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : ULINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF CU AND (CV < PV)
+ THEN CV := CV+1;
+ END_IF ;
+ Q := (CV >= PV) ;
+END_FUNCTION_BLOCK
+
+
+
+
+
+
+
+(******************)
+(* *)
+(* C T D *)
+(* *)
+(******************)
FUNCTION_BLOCK CTD
@@ -58,6 +145,85 @@
END_FUNCTION_BLOCK
+FUNCTION_BLOCK CTD_DINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : DINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : DINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTD_LINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : LINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : LINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTD_UDINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : UDINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : UDINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTD_ULINT
+ VAR_INPUT
+ CD : BOOL;
+ LD : BOOL;
+ PV : ULINT;
+ END_VAR
+ VAR_OUTPUT
+ Q : BOOL;
+ CV : ULINT;
+ END_VAR
+ IF LD THEN CV := PV ;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF ;
+ Q := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+(********************)
+(* *)
+(* C T U D *)
+(* *)
+(********************)
+
+
FUNCTION_BLOCK CTUD
VAR_INPUT
CU : BOOL;
@@ -86,3 +252,118 @@
QD := (CV <= 0) ;
END_FUNCTION_BLOCK
+
+FUNCTION_BLOCK CTUD_DINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : DINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : DINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTUD_LINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : LINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : LINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTUD_UDINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : UDINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : UDINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
+
+
+FUNCTION_BLOCK CTUD_ULINT
+ VAR_INPUT
+ CU : BOOL;
+ CD : BOOL;
+ R : BOOL;
+ LD : BOOL;
+ PV : ULINT;
+ END_VAR
+ VAR_OUTPUT
+ QU : BOOL;
+ QD : BOOL;
+ CV : ULINT;
+ END_VAR
+ IF R THEN CV := 0 ;
+ ELSIF LD THEN CV := PV ;
+ ELSE
+ IF NOT (CU AND CD) THEN
+ IF CU AND (CV < PV)
+ THEN CV := CV+1;
+ ELSIF CD AND (CV > 0)
+ THEN CV := CV-1;
+ END_IF;
+ END_IF;
+ END_IF ;
+ QU := (CV >= PV) ;
+ QD := (CV <= 0) ;
+END_FUNCTION_BLOCK
--- a/lib/derivative_st.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/derivative_st.txt Mon Apr 04 15:26:13 2011 +0100
@@ -1,3 +1,15 @@
+
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
+
FUNCTION_BLOCK DERIVATIVE
VAR_INPUT
RUN : BOOL ; (* 0 = reset *)
--- a/lib/hysteresis_st.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/hysteresis_st.txt Mon Apr 04 15:26:13 2011 +0100
@@ -1,3 +1,14 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
+
FUNCTION_BLOCK HYSTERESIS
(* Boolean hysteresis on difference *)
(* of REAL inputs, XIN1 - XIN2 *)
--- a/lib/integral_st.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/integral_st.txt Mon Apr 04 15:26:13 2011 +0100
@@ -1,3 +1,13 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
FUNCTION_BLOCK INTEGRAL
VAR_INPUT
RUN : BOOL ; (* 1 = integrate, 0 = hold *)
--- a/lib/pid_st.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/pid_st.txt Mon Apr 04 15:26:13 2011 +0100
@@ -1,3 +1,13 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
FUNCTION_BLOCK PID
VAR_INPUT
AUTO : BOOL ; (* 0 - manual , 1 - automatic *)
--- a/lib/ramp_st.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/ramp_st.txt Mon Apr 04 15:26:13 2011 +0100
@@ -1,3 +1,13 @@
+(* Following taken directly from the IEC 61131.3 draft standard *)
+
+(*
+ * An IEC 61131-3 IL and ST compiler.
+ *
+ * Based on the
+ * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
+ *
+ *)
+
FUNCTION_BLOCK RAMP
VAR_INPUT
RUN : BOOL ; (* 0 - track X0, 1 - ramp to/track X1 *)
--- a/lib/timer.txt Mon Apr 04 15:22:42 2011 +0100
+++ b/lib/timer.txt Mon Apr 04 15:26:13 2011 +0100
@@ -1,21 +1,28 @@
(*
- * (c) 2005 Mario de Sousa
- *
- * Offered to the public under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details.
+ * matiec - a compiler for the programming languages defined in IEC 61131-3
+ *
+ * Copyright (C) 2005, 2011 Mario de Sousa (msousa@fe.up.pt)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
*
* This code is made available on the understanding that it will not be
* used in safety-critical situations without a full and competent review.
*)
(*
- * An IEC 61131-3 IL and ST compiler.
+ * An IEC 61131-3 compiler.
*
* Based on the
* FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
@@ -29,8 +36,8 @@
* Timer Function Blocks
* ---------------------
*
- * NOTE: The timing diagrams in the comments were taken from the
- * IEC 61131-3 standard.
+ * NOTE: The timing diagrams in the comments (except the state variable)
+ * were taken from the IEC 61131-3 standard.
*)