Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

SFC boolean value not working properly

2021-04-11
2021-04-11
  • leiferiksson - 2021-04-11

    Hi!
    As a project, I created an SFC with 4+1 Init step, where each makes a LED light.
    Step C should make the LED blink. I used a BLINK box to do so, the output of the BLINK has been passed to the LED's coil. However, if the output of the BLINK is false, the LED still won't turn off, although the wire leading to the LED's coil is off. What can be the reason?
    Also, when the application starts, it doesn't start by the Init step, but immediately at step C.
    I can't figure out what the problem is.
    I attached the project so that you can have a look on it yourselves.
    Thanks in advance!

     
  • hermsen

    hermsen - 2021-04-11

    I opened your source, here is some small feedback:

    1) There are implicit timers available in SFC (see help!) you should try to use those first instead of programming timers yourself. Only when the implicit timers will not help you you can program one of your own. This helps keep your code clean (and less programming means less bugs)

    Use an UNSIGNED INTEGER (myCurrentStep : UINT := 0;) to keep track of the steps in which you are. Using booleans is only going to make it more convoluted.

    Rename Step A, Step B, to Step 1, Step 2, etc, which is more flexible and easy.

    Every step has an Entry and and exit (See help), you can use this to initialise every step, like timers/counters etc and set myCurrentStep := x; depending on your step.

    Always write your code as if you are writing it for somebody else.

    PS you are free to choose any language for the step code, however Ladder would not be my first choice, maybe try Structured Text?

     

Log in to post a comment.