Create a user-defined function block and variables

Use the steps to create a user-defined function block (UDFB), and then add input and output variables. The UDFB is created using the ladder diagram programming language.
To create a user-defined function block and variables
  1. In
    Project Organizer
    , expand
    Assets
    .
  2. Right-click
    User-Defined Function Blocks
    , and then select
    New user-defined function block
    .
  3. In
    New user-defined function block
    , enter the UDFB name
    Traffic_Controller_FB
    , select
    Ladder Diagram
    from the
    Type
    list, and then select
    Create
    .
  4. In
    Project Organizer
    , expand
    Traffic_Controller_FB
    , and then double-click
    Local Variables
    .
  5. In the local variable grid, add the following variables:
    • Four input variables to represent a car sensor in each of the four positions in the intersection (N, S, E, W).
    • Six output variables to represent red, yellow, and green traffic lights in each of two directions (NS, EW).
    Variables
    Name
    Data Type
    Direction
    Attribute
    N_CAR_SENSOR
    BOOL
    VarInput
    Read
    S_CAR_SENSOR
    BOOL
    VarInput
    Read
    W_CAR_SENSOR
    BOOL
    VarInput
    Read
    E_CAR_SENSOR
    BOOL
    VarInput
    Read
    NS_GREEN_LIGHTS
    BOOL
    VarOutput
    Read/Write
    NS_YELLOW_LIGHTS
    BOOL
    VarOutput
    Read/Write
    NS_RED_LIGHTS
    BOOL
    VarOutput
    Read/Write
    EW_RED_LIGHTS
    BOOL
    VarOutput
    Read/Write
    EW_YELLOW_LIGHTS
    BOOL
    VarOutput
    Read/Write
    EW_GREEN_LIGHTS
    BOOL
    VarOutput
    Read/Write
    TON_1
    TON
    Var
    Read/Write
    TON_2
    TON
    Var
    Read/Write
    TON_3
    TON
    Var
    Read/Write
    TON_4
    TON
    Var
    Read/Write
  6. Save the project by doing one of the following:
    • From the menu bar, select save button.
    • From the
      File
      menu, select
      Save
      .
Provide Feedback
Have questions or feedback about this documentation? Please submit your feedback here.
Normal