Create a user-defined function block element and variables

In this task you will create a user-defined function block and then add input and output variables.

1. In the Project Organizer, right-click User-Defined Function Blocks, select Add, and then select New LD: Ladder Diagram.


2. Rename the Ladder Diagram UDFB:

Right-click UntitledLD and select Rename.
Type TRAFFIC_CONTROLLER_FB, and press Enter.



3. Under TRAFFIC_CONTROLLER_FB, double-click Local Variables to display the Local Variables grid as a tab in the workspace. Note the tab name (TRAFFIC_CONTROLLER_FB-VAR), which is the user-defined function block name with -VAR added to the end.


4. Arrange how columns appear in the Local Variables grid (optional):

Right-click the header row and click Hide Column to remove a column from the display
Click Show Column and select a column name to add a column
Click and hold a column header and drag it to an alternate location to move a column;
Click Reset Settings to display all the columns in the default layout.


5. If necessary, arrange the columns so they appear as shown in the following example.


6. Enter four input variables to represent a car sensor in each of the four positions in the intersection (N, S, E, W) as shown in the following table:

Name
Data Type
Direction
N_CAR_SENSOR
BOOL
VarInput
S_CAR_SENSOR
BOOL
VarInput
E_CAR_SENSOR
BOOL
Var Input
W_CAR_SENSOR
BOOL
VarInput

7. Enter six output variables to represent red, yellow and green traffic lights in each of two directions (NS, EW) as shown in the following table:

Name
Data Type
Direction
NS_RED_LIGHTS
BOOL
VarOutput
NS_YELLOW_LIGHTS
BOOL
VarOutput
NS_GREEN_LIGHTS
BOOL
VarOutput
EW_ RED_LIGHTS
BOOL
VarOutput
EW_ YELLOW_LIGHTS
BOOL
VarOutput
EW_ GREEN_LIGHTS
BOOL
VarOutput

8. Verify your input and output variables are the same as those listed in the following the Local Variables grid example.



0 comments :