lib/counter.txt
author Mario de Sousa <msousa@fe.up.pt>
Wed, 26 Dec 2018 11:12:27 +0000
changeset 1078 81e2a100db14
parent 290 013eab46aebb
permissions -rwxr-xr-x
Test for overflow when translating task periods/intervals to integer variable.
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     1
(* Following taken directly from the IEC 61131.3 draft standard *)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     2
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     3
(*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     4
 * An IEC 61131-3 IL and ST compiler.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     5
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     6
 * Based on the
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     7
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     8
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
     9
 *)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    10
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    11
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    12
(*
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    13
 * This is part of the library conatining the functions
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    14
 * and function blocks defined in the standard.
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    15
 *
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    16
 * Counter function blocks
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    17
 * -----------------------
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    18
 *)
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    19
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    20
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    21
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    22
(******************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    23
(*                *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    24
(*    C  T  U     *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    25
(*                *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    26
(******************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    27
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    28
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    29
FUNCTION_BLOCK CTU
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    30
  VAR_INPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    31
    CU : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    32
    R : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    33
    PV : INT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    34
  END_VAR
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    35
  VAR_OUTPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    36
    Q : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    37
    CV : INT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    38
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    39
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    40
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    41
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    42
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    43
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    44
  IF R THEN CV := 0 ;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    45
  ELSIF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    46
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    47
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    48
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    49
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    50
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    51
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    52
FUNCTION_BLOCK CTU_DINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    53
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    54
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    55
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    56
    PV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    57
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    58
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    59
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    60
    CV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    61
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    62
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    63
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    64
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    65
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    66
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    67
  IF R THEN CV := 0 ;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    68
  ELSIF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    69
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    70
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    71
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    72
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    73
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    74
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    75
FUNCTION_BLOCK CTU_LINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    76
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    77
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    78
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    79
    PV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    80
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    81
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    82
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    83
    CV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    84
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    85
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    86
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    87
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    88
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    89
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    90
  IF R THEN CV := 0 ;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
    91
  ELSIF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    92
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    93
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    94
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    95
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    96
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    97
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    98
FUNCTION_BLOCK CTU_UDINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    99
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   100
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   101
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   102
    PV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   103
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   104
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   105
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   106
    CV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   107
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   108
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   109
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   110
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   111
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   112
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   113
  IF R THEN CV := 0 ;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   114
  ELSIF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   115
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   116
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   117
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   118
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   119
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   120
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   121
FUNCTION_BLOCK CTU_ULINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   122
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   123
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   124
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   125
    PV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   126
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   127
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   128
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   129
    CV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   130
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   131
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   132
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   133
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   134
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   135
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   136
  IF R THEN CV := 0 ;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   137
  ELSIF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   138
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   139
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   140
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   141
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   142
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   143
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   144
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   145
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   146
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   147
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   148
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   149
(******************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   150
(*                *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   151
(*    C  T  D     *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   152
(*                *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   153
(******************)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   154
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   155
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   156
FUNCTION_BLOCK CTD
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   157
  VAR_INPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   158
    CD : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   159
    LD : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   160
    PV : INT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   161
  END_VAR
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   162
  VAR_OUTPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   163
    Q : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   164
    CV : INT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   165
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   166
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   167
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   168
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   169
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   170
  CD_T(CD);
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   171
  IF LD THEN CV := PV ;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   172
  ELSIF CD_T.Q AND (CV > 0)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   173
      THEN CV := CV-1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   174
  END_IF ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   175
  Q := (CV <= 0) ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   176
END_FUNCTION_BLOCK
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   177
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   178
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   179
FUNCTION_BLOCK CTD_DINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   180
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   181
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   182
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   183
    PV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   184
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   185
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   186
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   187
    CV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   188
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   189
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   190
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   191
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   192
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   193
  CD_T(CD);
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   194
  IF LD THEN CV := PV ;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   195
  ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   196
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   197
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   198
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   199
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   200
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   201
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   202
FUNCTION_BLOCK CTD_LINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   203
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   204
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   205
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   206
    PV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   207
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   208
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   209
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   210
    CV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   211
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   212
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   213
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   214
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   215
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   216
  CD_T(CD);
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   217
  IF LD THEN CV := PV ;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   218
  ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   219
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   220
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   221
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   222
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   223
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   224
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   225
FUNCTION_BLOCK CTD_UDINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   226
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   227
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   228
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   229
    PV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   230
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   231
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   232
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   233
    CV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   234
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   235
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   236
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   237
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   238
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   239
  CD_T(CD);
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   240
  IF LD THEN CV := PV ;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   241
  ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   242
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   243
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   244
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   245
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   246
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   247
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   248
FUNCTION_BLOCK CTD_ULINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   249
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   250
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   251
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   252
    PV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   253
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   254
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   255
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   256
    CV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   257
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   258
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   259
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   260
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   261
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   262
  CD_T(CD);
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   263
  IF LD THEN CV := PV ;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   264
  ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   265
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   266
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   267
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   268
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   269
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   270
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   271
(********************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   272
(*                  *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   273
(*    C  T  U D     *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   274
(*                  *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   275
(********************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   277
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   278
FUNCTION_BLOCK CTUD
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   279
  VAR_INPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   280
    CU : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   281
    CD : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   282
    R  : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   283
    LD : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   284
    PV : INT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   285
  END_VAR
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   286
  VAR_OUTPUT
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   287
    QU : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   288
    QD : BOOL;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   289
    CV : INT;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   290
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   291
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   292
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   293
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   294
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   295
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   296
  CD_T(CD);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   297
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   298
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   299
  IF R THEN CV := 0 ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   300
  ELSIF LD THEN CV := PV ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   301
  ELSE
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   302
    IF NOT (CU_T.Q AND CD_T.Q) THEN
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   303
      IF CU_T.Q AND (CV < PV)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   304
      THEN CV := CV+1;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   305
      ELSIF CD_T.Q AND (CV > 0)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   306
      THEN CV := CV-1;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   307
      END_IF;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   308
    END_IF;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   309
  END_IF ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   310
  QU := (CV >= PV) ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   311
  QD := (CV <= 0) ;
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   312
END_FUNCTION_BLOCK
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   313
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   314
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   315
FUNCTION_BLOCK CTUD_DINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   316
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   317
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   318
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   319
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   320
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   321
    PV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   322
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   323
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   324
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   325
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   326
    CV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   327
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   328
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   329
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   330
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   331
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   332
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   333
  CD_T(CD);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   334
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   335
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   336
  IF R THEN CV := 0 ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   337
  ELSIF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   338
  ELSE
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   339
    IF NOT (CU_T.Q AND CD_T.Q) THEN
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   340
      IF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   341
      THEN CV := CV+1;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   342
      ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   343
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   344
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   345
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   346
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   347
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   348
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   349
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   350
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   351
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   352
FUNCTION_BLOCK CTUD_LINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   353
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   354
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   355
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   356
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   357
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   358
    PV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   359
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   360
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   361
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   362
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   363
    CV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   364
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   365
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   366
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   367
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   368
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   369
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   370
  CD_T(CD);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   371
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   372
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   373
  IF R THEN CV := 0 ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   374
  ELSIF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   375
  ELSE
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   376
    IF NOT (CU_T.Q AND CD_T.Q) THEN
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   377
      IF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   378
      THEN CV := CV+1;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   379
      ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   380
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   381
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   382
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   383
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   384
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   385
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   386
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   387
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   388
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   389
FUNCTION_BLOCK CTUD_UDINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   390
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   391
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   392
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   393
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   394
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   395
    PV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   396
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   397
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   398
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   399
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   400
    CV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   401
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   402
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   403
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   404
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   405
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   406
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   407
  CD_T(CD);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   408
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   409
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   410
  IF R THEN CV := 0 ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   411
  ELSIF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   412
  ELSE
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   413
    IF NOT (CU_T.Q AND CD_T.Q) THEN
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   414
      IF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   415
      THEN CV := CV+1;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   416
      ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   417
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   418
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   419
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   420
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   421
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   422
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   423
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   424
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   425
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   426
FUNCTION_BLOCK CTUD_ULINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   427
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   428
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   429
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   430
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   431
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   432
    PV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   433
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   434
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   435
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   436
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   437
    CV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   438
  END_VAR
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   439
  VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   440
    CD_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   441
    CU_T: R_TRIG;
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   442
  END_VAR
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   443
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   444
  CD_T(CD);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   445
  CU_T(CU);
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   446
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   447
  IF R THEN CV := 0 ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   448
  ELSIF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   449
  ELSE
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   450
    IF NOT (CU_T.Q AND CD_T.Q) THEN
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   451
      IF CU_T.Q AND (CV < PV)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   452
      THEN CV := CV+1;
290
013eab46aebb Fixing implementation of CU, CD, and CUD in standard library.
Mario de Sousa <msousa@fe.up.pt>
parents: 276
diff changeset
   453
      ELSIF CD_T.Q AND (CV > 0)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   454
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   455
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   456
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   457
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   458
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   459
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   460
END_FUNCTION_BLOCK