lib/bistable.txt
changeset 278 050d31dd7c74
parent 277 f88718b71b6c
equal deleted inserted replaced
273:beb05fe75e0c 278:050d31dd7c74
     1 (*
     1 (*
     2  * (c) 26 Feb 2001 David Campbell
     2  *  This file is part of matiec - a compiler for the programming
       
     3  *  languages defined in IEC 61131-3
     3  *
     4  *
     4  * Offered to the public under the terms of the GNU General Public License
     5  *  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  *
     6  *
     8  * This program is distributed in the hope that it will be useful, but
     7  * See COPYING and COPYING.LESSER files for copyright details.
     9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     8  * This library is free software; you can redistribute it and/or
    10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
     9  * modify it under the terms of the GNU Lesser General Public
    11  * Public License for more details.
    10  * License as published by the Free Software Foundation; either
       
    11  * version 3 of the License, or (at your option) any later version.
       
    12  *
       
    13  * This library is distributed in the hope that it will be useful,
       
    14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       
    16  * Lesser General Public License for more details.
       
    17  * 
       
    18  * You should have received a copy of the GNU Lesser General Public
       
    19  * License along with this library; if not, write to the Free Software
       
    20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
       
    21  * USA
    12  *
    22  *
    13  * This code is made available on the understanding that it will not be
    23  * 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.
    24  * used in safety-critical situations without a full and competent review.
    15  *)
    25  *)
    16 
    26 
       
    27 
       
    28 
    17 (*
    29 (*
    18  * An IEC 61131-3 IL and ST compiler.
    30  * An IEC 61131-3 compiler.
    19  *
    31  *
    20  * Based on the
    32  * Based on the
    21  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    33  * FINAL DRAFT - IEC 61131-3, 2nd Ed. (2001-12-10)
    22  *
    34  *
    23  *)
    35  *)
    29  *
    41  *
    30  * SR and RS function blocks
    42  * SR and RS function blocks
    31  * -------------------------
    43  * -------------------------
    32  *)
    44  *)
    33 
    45 
       
    46 (* The standard defines the SR FB thus: 
       
    47 
       
    48                   +-----+
       
    49 S1----------------| >=1 |---Q1
       
    50          +---+    |     |
       
    51  R------O| & |----|     |
       
    52  Q1------|   |    |     |
       
    53          +---+    +-----+
       
    54 *)
    34 
    55 
    35 FUNCTION_BLOCK SR
    56 FUNCTION_BLOCK SR
    36   VAR_INPUT
    57   VAR_INPUT
    37     S1 : BOOL;
    58     S1, R : BOOL;
    38     R  : BOOL;
       
    39   END_VAR
    59   END_VAR
    40   VAR_OUTPUT
    60   VAR_OUTPUT
    41     Q1 : BOOL;
    61     Q1 : BOOL;
    42   END_VAR
    62   END_VAR
    43   VAR
    63   Q1 := S1 OR ((NOT R) AND Q1);
    44     Q_INTERNAL : BOOL;
    64 END_FUNCTION_BLOCK
    45   END_VAR
       
    46 
    65 
    47   Q_INTERNAL := S1 OR ( Q_INTERNAL AND (NOT R));
    66 
    48   Q1 := Q_INTERNAL;
    67 (* The standard defines the RS FB thus: 
    49 END_FUNCTION_BLOCK
    68                    +---+
       
    69 R1----------------O| & |---Q1
       
    70         +-----+    |   |
       
    71 S-------| >=1 |----|   |
       
    72 Q1------|     |    |   |
       
    73         +-----+    +---+
       
    74 *)
    50 
    75 
    51 FUNCTION_BLOCK RS
    76 FUNCTION_BLOCK RS
    52   VAR_INPUT
    77   VAR_INPUT
    53     S : BOOL;
    78     S, R1 : BOOL;
    54     R1 : BOOL;
       
    55   END_VAR
    79   END_VAR
    56   VAR_OUTPUT
    80   VAR_OUTPUT
    57     Q1 : BOOL;
    81     Q1 : BOOL;
    58   END_VAR
    82   END_VAR
    59   VAR
    83   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
    84 END_FUNCTION_BLOCK