lib/pid_st.txt
author Mario de Sousa <msousa@fe.up.pt>
Fri, 09 Nov 2012 14:34:36 +0000
changeset 724 d19877568878
parent 276 1679f514f38a
permissions -rwxr-xr-x
Check for errors in enum datatype declarations. (This is not yet complete as it will not yet stop the compilation process if these errors are found)
276
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     1
(* Following taken directly from the IEC 61131.3 draft standard *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     2
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     3
(*
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     4
 * An IEC 61131-3 IL and ST compiler.
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     5
 *
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     6
 * Based on the
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     7
 * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     8
 *
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
     9
 *)
1679f514f38a Updating origin and license info of library fuctions.
Mario de Sousa <msousa@fe.up.pt>
parents: 192
diff changeset
    10
192
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    11
 FUNCTION_BLOCK PID
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    12
   VAR_INPUT
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    13
     AUTO : BOOL ;        (* 0 - manual , 1 - automatic *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    14
     PV : REAL ;          (* Process variable *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    15
     SP : REAL ;          (* Set point *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    16
     X0 : REAL ;          (* Manual output adjustment - *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    17
                          (* Typically from transfer station *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    18
     KP : REAL ;          (* Proportionality constant *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    19
     TR : REAL ;          (* Reset time *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    20
     TD : REAL ;          (* Derivative time constant *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    21
     CYCLE : TIME ;       (* Sampling period *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    22
   END_VAR
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    23
   VAR_OUTPUT XOUT : REAL; END_VAR
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    24
   VAR ERROR : REAL ;        (* PV - SP *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    25
       ITERM : INTEGRAL ;    (* FB for integral term  *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    26
       DTERM : DERIVATIVE ;  (* FB for derivative term *)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    27
   END_VAR
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    28
   ERROR := PV - SP ;
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    29
   (*** Adjust ITERM so that XOUT := X0 when AUTO = 0 ***)
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    30
   ITERM (RUN := AUTO, R1 := NOT AUTO, XIN := ERROR,
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    31
          X0 := TR * (X0 - ERROR), CYCLE := CYCLE) ;
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    32
   DTERM (RUN := AUTO, XIN := ERROR, CYCLE := CYCLE) ;
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    33
   XOUT := KP * (ERROR + ITERM.XOUT/TR + DTERM.XOUT*TD) ;
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    34
 END_FUNCTION_BLOCK
c6c2a3d487ac Adding inclusion of function blocks defined in AnnexF into library blocks
lbessard
parents:
diff changeset
    35