lib/bistable.txt
changeset 274 8d36d1f81170
parent 0 fb772792efd1
child 277 f88718b71b6c
equal deleted inserted replaced
269:98fc461e1888 274:8d36d1f81170
     1 (*
     1 (*
     2  * (c) 26 Feb 2001 David Campbell
     2  *  matiec - a compiler for the programming languages defined in IEC 61131-3
     3  *
     3  *
     4  * Offered to the public under the terms of the GNU General Public License
     4  *  Copyright (C) 2011  Mario de Sousa (msousa@fe.up.pt)
     5  * as published by the Free Software Foundation; either version 2 of the
       
     6  * License, or (at your option) any later version.
       
     7  *
     5  *
     8  * This program is distributed in the hope that it will be useful, but
     6  *  This program is free software: you can redistribute it and/or modify
     9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     7  *  it under the terms of the GNU General Public License as published by
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
     8  *  the Free Software Foundation, either version 3 of the License, or
    11  * Public License for more details.
     9  *  (at your option) any later version.
       
    10  *
       
    11  *  This program is distributed in the hope that it will be useful,
       
    12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    14  *  GNU General Public License for more details.
       
    15  *
       
    16  *  You should have received a copy of the GNU General Public License
       
    17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
       
    18  *
    12  *
    19  *
    13  * This code is made available on the understanding that it will not be
    20  * This code is made available on the understanding that it will not be
    14  * used in safety-critical situations without a full and competent review.
    21  * used in safety-critical situations without a full and competent review.
    15  *)
    22  *)
    16 
    23 
    17 (*
    24 (*
    18  * An IEC 61131-3 IL and ST compiler.
    25  * An IEC 61131-3 compiler.
    19  *
    26  *
    20  * Based on the
    27  * Based on the
    21  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    28  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    22  *
    29  *
    23  *)
    30  *)
    29  *
    36  *
    30  * SR and RS function blocks
    37  * SR and RS function blocks
    31  * -------------------------
    38  * -------------------------
    32  *)
    39  *)
    33 
    40 
       
    41 (* The standard defines the SR FB thus: 
       
    42 
       
    43                   +-----+
       
    44 S1----------------| >=1 |---Q1
       
    45          +---+    |     |
       
    46  R------O| & |----|     |
       
    47  Q1------|   |    |     |
       
    48          +---+    +-----+
       
    49 *)
    34 
    50 
    35 FUNCTION_BLOCK SR
    51 FUNCTION_BLOCK SR
    36   VAR_INPUT
    52   VAR_INPUT
    37     S1 : BOOL;
    53     S1, R : BOOL;
    38     R  : BOOL;
       
    39   END_VAR
    54   END_VAR
    40   VAR_OUTPUT
    55   VAR_OUTPUT
    41     Q1 : BOOL;
    56     Q1 : BOOL;
    42   END_VAR
    57   END_VAR
    43   VAR
    58   Q1 := S1 OR ((NOT R) AND Q1);
    44     Q_INTERNAL : BOOL;
    59 END_FUNCTION_BLOCK
    45   END_VAR
       
    46 
    60 
    47   Q_INTERNAL := S1 OR ( Q_INTERNAL AND (NOT R));
    61 
    48   Q1 := Q_INTERNAL;
    62 (* The standard defines the RS FB thus: 
    49 END_FUNCTION_BLOCK
    63                    +---+
       
    64 R1----------------O| & |---Q1
       
    65         +-----+    |   |
       
    66 S-------| >=1 |----|   |
       
    67 Q1------|     |    |   |
       
    68         +-----+    +---+
       
    69 *)
    50 
    70 
    51 FUNCTION_BLOCK RS
    71 FUNCTION_BLOCK RS
    52   VAR_INPUT
    72   VAR_INPUT
    53     S : BOOL;
    73     S, R1 : BOOL;
    54     R1 : BOOL;
       
    55   END_VAR
    74   END_VAR
    56   VAR_OUTPUT
    75   VAR_OUTPUT
    57     Q1 : BOOL;
    76     Q1 : BOOL;
    58   END_VAR
    77   END_VAR
    59   VAR
    78   Q1 := (NOT R1) AND (S OR Q1);
    60     Q_INTERNAL : BOOL;
       
    61   END_VAR
       
    62 
       
    63   Q_INTERNAL := (NOT R1) AND (S OR Q_INTERNAL);
       
    64   Q1 := Q_INTERNAL;
       
    65 END_FUNCTION_BLOCK
    79 END_FUNCTION_BLOCK