Results 1 to 6 of 6

Thread: OUTPUT FB, Values Retained?

  1. #1
    Join Date
    Jan 2012
    Posts
    10

    Default OUTPUT FB, Values Retained?

    Just need a little clarification: Using the OUTPUT function block in the CR0403 library...

    VAR
    OutCH0:OUTPUT;
    END_VAR;

    WHILE (Some_Bool_Var) DO
    OutCh0(ENABLE:=TRUE,CHANNEL:=0,VALUE:=TRUE,MODE:=2 );
    END_WHILE;

    It would seem as though this should output to channel 0 as long as Some_Bool_Var remains TRUE... however, the documentation states that function blocks retain all values until the instance is called again. In that case, the output to channel 0 will continue indefinitely, regardless of the value of Some_Bool_Var, correct?

    If so, then the use of WHILE is pointless unless I'm wanting to increment some variable or something like that. If I'm wanting to just control outputs, I should stick with IF THEN...ELSE:

    IF (Some_Bool_Var) THEN
    OutCh0(ENABLE:=TRUE,CHANNEL:=0,VALUE:=TRUE,MODE:=2 );
    ELSE
    OutCh0(ENABLE:=FALSE,CHANNEL:=0,VALUE:=FALSE,MODE: =2);
    END_IF;

    Yes?

  2. #2
    Join Date
    Jan 2012
    Posts
    10

    Default

    Furthermore, unless I have something within the loop that sets the condition to FALSE, the loop will be infinite?

    For instance, if I have a pressure switch as an input, with bool variable PRESS_SW, and the output to channel 0 opens the valve to increase the pressure...

    WHILE (NOT PRESS_SW) DO
    OutCh0(ENABLE:=TRUE,CHANNEL:=0,VALUE:=TRUE,MODE:=2 );
    END_WHILE;

    Would this be an infinite loop? PRESS_SW would become TRUE once the pressure reaches the switch point, but the program would never leave the loop to update the value of PRESS_SW.

    Am I understanding this correctly? I have a background in programming with structured text (C++, php etc), and some experience with plc programming in ladder logic only, so just wrapping my head around mixing the two together. Thanks!

  3. #3
    Join Date
    Sep 2010
    Location
    Burnsville, Minnesota
    Posts
    41

    Default

    Typically, you will want to call OUTPUT in every cycle, and manipulate the VALUE variable

    Like this:

    OutCh0(ENABLE:=TRUE,CHANNEL:=0,VALUE:=(NOT PRESS_SW),MODE:=2 );
    David Grambsch
    Automation Controls Engineer

    FORCE America Inc.
    www.forceamerica.com

  4. #4
    Join Date
    Jan 2012
    Posts
    10

    Default

    Thanks David, that makes sense. Am I correct in assuming that once the programs enters a loop, no other parts of the program are executed until the loop is terminated (the program does not cycle)?

  5. #5
    Join Date
    Sep 2010
    Location
    Burnsville, Minnesota
    Posts
    41

    Default

    Yes, any user created code will operate that way (until it hits the watchdog timer and turns off the controller). I would try to avoid adding loops unless you absolutely need them, they tend to increase your cycle time.
    David Grambsch
    Automation Controls Engineer

    FORCE America Inc.
    www.forceamerica.com

  6. #6
    Join Date
    Jan 2012
    Posts
    10

    Default

    Quote Originally Posted by David Grambsch View Post
    I would try to avoid adding loops unless you absolutely need them, they tend to increase your cycle time.
    That's what I wanted to hear! Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •