Codesys question about using a Ladder function block into a SFC (doesn't work properly)

33 views Asked by At

I have a function block made in Ladder which I want to use in SFC, but I can't get it work properly. I hope someone knows the solution here.

This is my devices tree:

DevicesTree

I have the following function block:

Function block

And this is my SFC. A variable is declared with the type of the function block: It's a very simple SFC. In step0 the SetGreen input is set in the TrafficLight instance.

SFC

The MainTask calls the SFC to run it each cycle.

MainTask

Now if I start the program, the function block doesn't work. The SetGreen input is set but the SR-flipflop doesn't flip the output to high:

Debug output

Does someone knows why this doesn't work? Perhaps I also need to call the function block instance somewhere each cycle?

1

There are 1 answers

2
Guiorgy On

Although you are setting the internal variable SetGreen (which I don't recommend, it's internal for a reason, use an input), I don't see anywhere you calling the Function Block TrafficLight that uses taht variable. Unless you call/execute the Function Block, the code inside it won't be executed.