Operating principle of the switch

The CX1100-000x power supply units all have 4 + 1 navigation switches. The switches can therefore be used to input five basic states:

  1. UP
  2. DOWN
  3. LEFT
  4. RIGHT
  5. SELECT

Combined inputs, such as UP + RIGHT or UP + RIGHT + SELECT can also be entered. The values of the switches are stored in a register of the "Auxiliary Control Block", ACB. Details may be referred to in the architectural description.

The register can be accessed from within a PLC program, and the value can be assessed. This requires a variable of type USINT first to be created in the PLC program. This is then linked in the TwinCAT System Manager to the IN-register of the CX1100.

Operating principle of the switch 1:

The figure shows the linked signals (with a bright red background). The switch can be accessed from the PLC program through the Switch variable. The PLC program takes the form described below. To begin an external variable is declared as an input. (In this example it is at address 0)

PROGRAM MAIN
VAR
    Taster AT %IB0 : USINT;
END_VAR

A simple CASE statement can then be used to evaluate the switch, and the desired function can be initiated, e.g.:

CASE Taster OF
0:      ACTION := NONE;
1:      ACTION := UP;
2:      ACTION := DOWN;
4:      ACTION := LEFT;
8:      ACTION := RIGHT;
16:     ACTION := SELECT;
END_CASE;

In this case, "ACTION" is a newly defined ENUM type. It is also possible for the desired action to be activated immediately.

The sum of the numerical values is used for the combined functions. In other words, UP (1) and RIGHT (8) would be 8 + 1 = 9. In this way, only sensible combinations are possible. In other words, switch positions that are opposite to one another cannot be selected without damaging the switch.

If the programmer does not want to carry out the evaluation, the TwinCAT System provides a library function that implements conversion of the switch input into an ENUM type. For this purpose, the library for the CX Systems, TcSystemCX.lib, must be integrated into the library manager. The function is called "F_CXNaviSwitch(iCX1100_IN : USINT)", and returns an ENUM type. This encodes the direction of the switch that has been pressed as names, for example e_CX1100_NaviSwitch_MIDDLE for <Middle>. The full list of valid possibilities is:

Further details on the function can be read in the TwinCAT documentation. The function can be used in a program as follows: (The declaration and linking are as given in the example above)

CASE F_CXNaviSwitch(Taster) OF
e_CX1100_NaviSwitch_IDLE            :;          (* do nothing *)
e_CX1100_NaviSwitch_MIDDLE              :call_select;   (* select item *)
e_CX1100_NaviSwitch_TOP             :call_prev_item;(* previous menue item *)
e_CX1100_NaviSwitch_RIGHT               :call_inc_value;(* increase value *)
e_CX1100_NaviSwitch_BOTTOM              :call_next_item;(* next menue item *)
e_CX1100_NaviSwitch_LEFT            :call_dec_value;(* decrease value *)
END_CASE;

Further evaluation of the switch inputs is then done later in the program.