Supported platforms: CODESYS 3.5

 

JoystickDirSwitch (FB)

Description

The joystick FB scales input voltage to calibrated control signal.

The middle position switch and the direction switches are used to validate the input voltage signal.

Dead band and progression are included in scaling.

The FB includes calibration functionality.

Calibration parameters, dead band and progression are checked for

valid range and that calibration values increase logically: maximum > middle > minimum.

A startup error is diagnosed if control is requested on the rising edge of i_Enable.

The output control signal is set to zero if i_Enable is FALSE, parameter error is diagnosed or startup error is diagnosed.  

 

All internal FB initializations are done on the rising edge of i_Enable.

All errors are reset on the rising edge of i_Enable.

 

Limitations

Joystick must be connected to voltage input.

 

The FB uses internally

- S_Joystick FB from SafeJoystickCalibrationAndDiagnostic library.

- S_ValidateJoystickWithDirSwitches FB from SafeDataValidation library.

 

Following parameters are taken into use at rising edge of i_Enable:

- i_pCalibratedMin

- i_pCalibratedMid

- i_pCalibratedMax

- i_DeadBand

- i_ProgressionPosDir

- i_ProgressionNegDir

- i_SignalErrorTolerance

- i_DiagnosticDelay

- i_DirSwitchesInUse

- i_MidPosSwitchInUse

+ Any initialized event code.

 

Inputs

Input variable name

Data type

Range

Description

i_Enable

BOOL

FALSE/TRUE

Enables controlling of o_Control output

i_SignalVoltage

DINT

hardware specific

Voltage measured from joystick output pin (mV).

i_ReferenceVoltage

DINT

hardware specific

Voltage measured from joystick supply pin (mV).

i_PosDirSwitch

BOOL

FALSE/TRUE

Positive direction switch status.

i_MidPosSwitch

BOOL

FALSE/TRUE

Middle position switch status.

i_NegDirSwitch

BOOL

FALSE/TRUE

Negative direction switch status.

i_pCalibratedMax

POINTER TO DINT

500…1000

Pointer to maximum calibration value of joystick. Value is given in per mil of supply voltage (1000 = 100,0%).

i_pCalibratedMid

POINTER TO DINT

250…750

Pointer to middle calibration value of joystick. Value is given in per mil of supply voltage (1000 = 100,0%).

i_pCalibratedMin

POINTER TO DINT

500…1000

Pointer to minimum calibration value of joystick. Value is given in per mil of supply voltage (1000 = 100,0%).

i_Deadband

DINT

0…1000

Dead band of joystick in center position, value given in per mil of position range 

i_ProgressionPosDir

DINT

-100…100

Positive direction’s progression curve factor.

i_ProgressionNegDir

DINT

-100…100

Negative direction’s progression curve factor.

i_SignalErrorTolerance

DINT

-1, 0…500

Defines how many volts Signal is allowed to be out of calibrated range. Value is given in per mil of supply voltage (500 = 50,0%), range depends on selected value type. With value -1, diagnostics is not used.

i_ErrorDelay

UINT

0…65535 ms

Defines the time that signal is allowed to exceed tolerated range before error outputs are activated.

i_CalibrationMode

BOOL

FALSE/TRUE

Enables calibration of o_Control output.

i_DirSwitchesInUse

BOOL

FALSE/TRUE

Enables direction switch errors.

i_MidPosSwitchInUse

BOOL

FALSE/TRUE

Enables middle position errors.

Outputs

Output variable name

Data type

Range

Description

o_Control

INT

 

Calibrated control signal value.

o_SignalTooHigh

BOOL

FALSE/TRUE

Signal input value is higher than maximum tolerated value

o_SignalTooLow

BOOL

FALSE/TRUE

Signal input value is lower than minimum tolerated value

o_PosDirSwitchMissing

BOOL

FALSE/TRUE

Positive direction switch status FALSE when signal positive.

o_PosDirSwitchOnFault

BOOL

FALSE/TRUE

Positive direction switch status TRUE when signal not positive.

o_MidPosSwitchMissing

BOOL

FALSE/TRUE

Middle position switch status FALSE when signal neutral.

o_MidPosSwitchOnFault

BOOL

FALSE/TRUE

Middle position switch status TRUE when when signal not neutral.

o_NegDirSwitchMissing

BOOL

FALSE/TRUE

Negative direction switch status FALSE when signal negative.

o_NegDirSwitchOnFault

BOOL

FALSE/TRUE

Negative direction switch status TRUE when signal not negative.

o_ParameterError

BOOL

FALSE/TRUE

True when incorrect parameter value in any of the monitored parameters.

o_StartupError

BOOL

FALSE/TRUE

Joystick not released when i_Enable rises.

o_CalibrationDone

BOOL

FALSE/TRUE

Joystick calibration finished successfully.

o_CalibrationError

BOOL

FALSE/TRUE

Joystick calibration error.

 

 

EventCodeInit (Public Method)

This optional method sets pointer for event codes for main signal and 3 validating switches.

 

Inputs

Input variable name

Data type

Description

i_Enable

BOOL

Enable operation.

i_pEventCode

POINTER TO EPEC_DITF.EventCode

Pointer to signal event code value provided by the application.

i_pEventCodePDS

POINTER TO EPEC_DITF.EventCode

Pointer to positive direction switch event code value provided by the application.

i_pEventCodeMPS

POINTER TO EPEC_DITF.EventCode

Pointer to middle position switch event code value provided by the application.

i_pEventCodeNDS

POINTER TO EPEC_DITF.EventCode

Pointer to negative direction switch event code value provided by the application.

 

 

Error diagnostic

See Diagnostic Interface library description of error status and event code functionality.

 

FunctionID and EventID are only set if EventCode is used.

 

Joystick and validation related errors are set to main EventCode.

Direction switch related errors are set to switch specific EventCodes.

 

A parameter error is diagnosed if:

  • pointer to any calibration parameter is 0, OR

  • i_DeadBand out of range OR

  • i_ProgressionPosDir out of range OR

  • i_ProgressionNegDir out of range OR

  • i_SignalErrorTolerance out of range OR

  • i_CalibratedMin is out of range OR

  • i_CalibratedMid is out of range OR

  • i_CalibratedMax is out of range OR

  • i_CalibratedMin > i_CalibratedMid OR

  • i_CalibratedMid > i_CalibratedMax

 

 

Conditions

o_Control

Output error set TRUE

Event code FunctionID

Event code EventID

i_Enable TRUE

AND

parameter error  

0

o_ParameterError

JOYSTICK  

PARAMETER_ERROR

i_Enable rises AND

 parameters ok AND

signal voltage outside dead band

0

o_StartupError

JOYSTICK

STARTUP_ERROR

i_Enable TRUE AND

 parameters ok AND

signal agrees with switches

Scaled control value

-

NO_FUNC

NO_ERROR

i_Enable TRUE AND

parameters ok AND

no startup error AND

signal > calibrated maximum value + error tolerance

0

o_SignalTooHigh

JOYSTICK  

INPUT_TOO_HIGH

i_Enable TRUE AND

parameters ok AND

no startup error AND

signal < calibrated minimum value - error tolerance

0

o_SignalTooLow

JOYSTICK

 INPUT_TOO_LOW

i_Enable TRUE AND

 parameters ok AND

i_Control = 0 AND i_MidPosSwitch FALSE AND i_MidPosSwitchInUse TRUE

0

o_MidPosSwitchMissing

VALIDATE_DIRSW

_JOYSTICK

MIDPOS_SWITCH

_STATUS_MISSING

i_Enable TRUE AND

parameters ok AND

i_Control <> 0 AND i_MidPosSwitch = TRUE

0

o_MidPosSwitchOnFault

VALIDATE_DIRSW

_JOYSTICK

MIDPOS_SWITCH

_STATUS_ON_FAULT

i_Enable TRUE AND

parameters ok AND

i_Control > 0 AND i_PosDirSwitch FALSE AND i_DirSwitchesInUse TRUE

0

o_PosDirSwitchMissing

VALIDATE_DIRSW

_JOYSTICK

POSDIR_SWITCH

_STATUS_MISSING

i_Enable TRUE AND

parameters ok AND

i_Control <= 0 AND i_PosDirSwitch TRUE

0

o_PosDirSwitchOnFault

VALIDATE_DIRSW

_JOYSTICK

POSDIR_SWITCH

_STATUS_ON_FAULT

i_Enable TRUE AND

parameters ok AND

i_Control < 0 AND i_NegDirSwitch FALSE AND i_ DirSwitchesInUse TRUE

0

o_NegDirSwitchMissing

VALIDATE_DIRSW

_JOYSTICK

NEGDIR_SWITCH

_STATUS_MISSING

i_Enable TRUE AND

parameters ok AND

i_Control >= 0 AND i_NegDirSwitch TRUE

0

o_NegDirSwitchOnFault

VALIDATE_DIRSW

_JOYSTICK

NEGDIR_SWITCH

_STATUS_ON_FAULT

 

 

Example code

 

 

 

 

See also

 

 

 

 

Source file topic100744.htm

Last updated 19-Dec-2024