lib/counter.txt
author laurent
Mon, 16 May 2011 11:57:41 +0200
changeset 292 a1d9c206409e
parent 276 1679f514f38a
child 290 013eab46aebb
permissions -rwxr-xr-x
Fix bug when debugging located variables of type memory (%M)
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
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
    28
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
    29
  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
    30
    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
    31
    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
    32
    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
    33
  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
    34
  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
    35
    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
    36
    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
    37
  END_VAR
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    38
  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
    39
  ELSIF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    40
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    41
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    42
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    43
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    44
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    45
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    46
FUNCTION_BLOCK CTU_DINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    47
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    48
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    49
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    50
    PV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    51
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    52
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    53
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    54
    CV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    55
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    56
  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
    57
  ELSIF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    58
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    59
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    60
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    61
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    62
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    63
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    64
FUNCTION_BLOCK CTU_LINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    65
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    66
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    67
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    68
    PV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    69
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    70
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    71
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    72
    CV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    73
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    74
  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
    75
  ELSIF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    76
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    77
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    78
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    79
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    80
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    81
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    82
FUNCTION_BLOCK CTU_UDINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    83
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    84
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    85
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    86
    PV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    87
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    88
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    89
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    90
    CV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    91
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    92
  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
    93
  ELSIF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    94
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    95
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    96
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    97
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    98
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
    99
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   100
FUNCTION_BLOCK CTU_ULINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   101
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   102
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   103
    R : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   104
    PV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   105
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   106
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   107
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   108
    CV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   109
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   110
  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
   111
  ELSIF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   112
       THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   113
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   114
  Q := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   115
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   116
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   117
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   118
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
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   122
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   123
(******************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   124
(*                *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   125
(*    C  T  D     *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   126
(*                *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   127
(******************)
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   128
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   129
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   130
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
   131
  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
   132
    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
   133
    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
   134
    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
   135
  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
   136
  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
   137
    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
   138
    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
   139
  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
   140
  IF LD THEN CV := PV ;
176
bef3cc16c064 Bug with non-working counters fixed
lbessard
parents: 0
diff changeset
   141
  ELSIF CD 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
   142
      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
   143
  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
   144
  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
   145
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
   146
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   147
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   148
FUNCTION_BLOCK CTD_DINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   149
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   150
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   151
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   152
    PV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   153
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   154
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   155
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   156
    CV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   157
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   158
  IF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   159
  ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   160
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   161
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   162
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   163
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   164
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   165
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   166
FUNCTION_BLOCK CTD_LINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   167
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   168
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   169
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   170
    PV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   171
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   172
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   173
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   174
    CV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   175
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   176
  IF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   177
  ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   178
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   179
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   180
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   181
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   182
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   183
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   184
FUNCTION_BLOCK CTD_UDINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   185
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   186
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   187
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   188
    PV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   189
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   190
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   191
    Q : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   192
    CV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   193
  END_VAR
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 ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   195
  ELSIF CD AND (CV > 0)
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_ULINT
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 : ULINT;
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 : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   211
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   212
  IF LD THEN CV := PV ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   213
  ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   214
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   215
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   216
  Q := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   217
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   218
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   219
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   220
(********************)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   221
(*                  *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   222
(*    C  T  U D     *)
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
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   226
0
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   227
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
   228
  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
   229
    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
   230
    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
   231
    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
   232
    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
   233
    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
   234
  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
   235
  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
   236
    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
   237
    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
   238
    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
   239
  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
   240
  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
   241
  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
   242
  ELSE
fb772792efd1 Initial commit. Last MatPLC CVS with some makefile inclusion removed in order to compile fine out of MatPLC.
etisserant
parents:
diff changeset
   243
    IF NOT (CU AND CD) THEN
176
bef3cc16c064 Bug with non-working counters fixed
lbessard
parents: 0
diff changeset
   244
      IF CU 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
   245
      THEN CV := CV+1;
176
bef3cc16c064 Bug with non-working counters fixed
lbessard
parents: 0
diff changeset
   246
      ELSIF CD 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
   247
      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
   248
      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
   249
    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
   250
  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
   251
  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
   252
  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
   253
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
   254
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   255
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   256
FUNCTION_BLOCK CTUD_DINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   257
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   258
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   259
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   260
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   261
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   262
    PV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   263
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   264
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   265
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   266
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   267
    CV : DINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   268
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   269
  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
   270
  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
   271
  ELSE
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   272
    IF NOT (CU AND CD) THEN
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   273
      IF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   274
      THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   275
      ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   276
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   277
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   278
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   279
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   280
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   281
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   282
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   283
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   284
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   285
FUNCTION_BLOCK CTUD_LINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   286
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   287
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   288
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   289
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   290
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   291
    PV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   292
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   293
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   294
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   295
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   296
    CV : LINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   297
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   298
  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
   299
  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
   300
  ELSE
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   301
    IF NOT (CU AND CD) THEN
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   302
      IF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   303
      THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   304
      ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   305
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   306
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   307
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   308
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   309
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   310
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   311
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   312
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   313
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   314
FUNCTION_BLOCK CTUD_UDINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   315
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   316
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   317
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   318
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   319
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   320
    PV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   321
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   322
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   323
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   324
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   325
    CV : UDINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   326
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   327
  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
   328
  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
   329
  ELSE
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   330
    IF NOT (CU AND CD) THEN
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   331
      IF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   332
      THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   333
      ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   334
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   335
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   336
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   337
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   338
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   339
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   340
END_FUNCTION_BLOCK
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   341
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   342
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   343
FUNCTION_BLOCK CTUD_ULINT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   344
  VAR_INPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   345
    CU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   346
    CD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   347
    R  : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   348
    LD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   349
    PV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   350
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   351
  VAR_OUTPUT
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   352
    QU : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   353
    QD : BOOL;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   354
    CV : ULINT;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   355
  END_VAR
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   356
  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
   357
  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
   358
  ELSE
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   359
    IF NOT (CU AND CD) THEN
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   360
      IF CU AND (CV < PV)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   361
      THEN CV := CV+1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   362
      ELSIF CD AND (CV > 0)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   363
      THEN CV := CV-1;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   364
      END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   365
    END_IF;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   366
  END_IF ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   367
  QU := (CV >= PV) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   368
  QD := (CV <= 0) ;
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 257
diff changeset
   369
END_FUNCTION_BLOCK