1

For one of my programs I need a normally closed, timed-closing (NCTC) relay in Ladder Diagram.

I do not know of a standard method to implement such, so I'm trying to construct one myself. My current approach needs a falling-edge detection. The code of such a detector I've found in the back of a book: "IEC 61131-3: Programming Industrial Systems" (2nd edition, page 327). Looks like this:

FUNCTION_BLOCK       F_TRIG      (* falling edge *)
    VAR_INPUT
        CLK  :     BOOL;
    END_VAR
    VAR_OUTPUT
        Q   :   BOOL;
    END_VAR
    VAR RETAIN
        MEM   :   BOOL := 1;       (* initialise edge flag *)
    END_VAR
    Q   :=  NOT CLK AND NOT MEM;   (* recognise falling edge *)
    MEM :=  NOT CLK;               (* reset edge flag *)
END_FUNCTION_BLOCK

Which gives me exactly 5 errors (ignoring the build failing because of those):

ERROR 4250: F_TRIG (1): Another 'ST' statement or end of POU expected
ERROR 4250: F_TRIG (4): Another 'ST' statement or end of POU expected
ERROR 4250: F_TRIG (7): Another 'ST' statement or end of POU expected
ERROR 4250: F_TRIG (10): Another 'ST' statement or end of POU expected
ERROR 4250: F_TRIG (13): Another 'ST' statement or end of POU expected

I properly configured the type of POU to be a function block and the language of the POU to be ST. I suspect my syntax is rusty, but I'm open for suggestions. Especially if I'm tackling this problem in an all wrong approach.

It looks okay to me. What's going wrong?

Running Codesys 2.3.

Mast
  • 1,788
  • 4
  • 29
  • 46

2 Answers2

2
  1. Delete END_FUNCTION_BLOCK
  2. Delete RETAIN. You can retain a function block. Not a variable in a function block
  3. Q and MEM at the bottom aren't declared as anything.
  4. F_TRIG is already a type in codesys. Need to declare as something else

Here is an example on how it should look.

FUNCTION_BLOCK  CustomTrig    
VAR_INPUT
    CLK  :     BOOL;
END_VAR
VAR_OUTPUT
    Q   :   BOOL;
END_VAR
VAR
    MEM   :   BOOL := 1;     
END_VAR

Can you explain a little more in detail what you're trying to do? I might be able to help you develop something (or there might be something already built in to codesys)

mrsargent
  • 2,267
  • 3
  • 19
  • 36
  • Point 3, `Q` and `MEM` are declared as `BOOL`. Looks like they'll have a defined value at the end. – Mast Feb 23 '17 at 05:07
  • I'll be back to elaborate further on what I'm doing and whether your suggestion worked. – Mast Feb 23 '17 at 05:08
  • What I'm trying to do, is build a Normally Closed Timed Closing (NCTC) relay. – Mast Feb 23 '17 at 18:37
  • I've tried to copy your proposed function, see what it did, and that also fails on 1, 4, 7 and 10. – Mast Feb 23 '17 at 18:41
  • Looks like you need TOF block. What NCTC means? First time hear this term. You need off timer? You need to close contact after some time the signal was sent to this contact? – Sergey Romanov Jun 08 '17 at 13:10
1

If I understand correctly, you want the output to be:

  • TRUE when idle (normally closed)
  • FALSE during the timer
  • TRUE when time expires

This is the opposite of the built in TP (timed pulse) function block. Just invert the TP output 'Q'.

Scott
  • 116
  • 2