Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETY

 

S_RefControlAndDiagnostics (FB)

Description

This function block diagnoses and controls reference voltage outputs. Reference voltage types depend on HW, 5V and 10V outputs are supported.

The function block uses internally S_ADCToVoltageOrCurrent function block to convert ADC values to voltage, and S_ValidateAI function block to validate voltage values.

 

Depending on the input parameter S_i_ReferenceType5V, the function block uses either VALUE_AT_AD_MAXIMUM.U_REF_5V or VALUE_AT_AD_MAXIMUM.U_REF_10V as voltage value at AD maximum value.

Also depending on the input parameter S_i_ReferenceType5V, the function block uses either G_REF_5V_OVERVOLT_LIMIT or G_REF_10V_OVERVOLT_LIMIT for diagnosing voltage high in both inputs.

 

Initialization

Init method is used to initialize the necessary static calculation parameters for the function block instance.

The method shall be called at least once before the actual function block can be called, i.e. at the application initialization phase.

The method checks the validity of input parameters. However, none of the function block outputs are affected by the initialization.

 

A parameter error is diagnosed if:

  • Init is not called before the main FB call OR

  • i_pEventCode = 0 OR

  • S_i_Tolerance < 0 OR

  • S_i_Tolerance > 1000 OR

  • S_i_DiagnosticDelay > 100

 

Initialization parameters

Parameter

Data type

Unit

Range

Description

S_i_Tolerance

SAFEDINT

0 - 1000

Limit for voltage mismatch diagnosis.

S_i_ReferenceType5V

SAFEBOOL

-

-

Is used REF type 5V.

S_i_DiagnosticDelay

SAFEUINT

ms

0 - 100

Delay time for diagnostics.

i_pEventCode

POINTER TO EventCode

-

≠ 0

Pointer to application variable which is type EventCode.

 

Initialization method return value

TRUE: All initialization parameters ok.

FALSE: Error in initialization parameter(s).

 

 

Operation (V1.4.1.0 or older)Operation (V1.4.1.0 or older)

The function block validates reference voltage by comparing measurement channel 1 with channel 2 and given high and low limits and that the channel voltages differ no more than given tolerance. The tolerance voltage is calculated per mil of channel 1 voltage. Tolerance is monitored only when REF control is active (i_RefControl = TRUE).

 

Short circuit and external voltage situations are diagnosed too.

 

The validated voltage is written to S_o_Voltage if:

• The control is enabled, i.e. i_Enable is TRUE

• No fault (including initialization) has been diagnosed

 

Operation (V1.5.1.0 or newer)Operation (V1.5.1.0 or newer)

The function block validates reference voltage by comparing measurement channel 1 with channel 2 and given high and low limits and that the channel voltages differ no more than given tolerance. The tolerance voltage is calculated per mil of nominal reference voltage (5000mV or 10000mV depending on used REF mode). Tolerance is monitored only when REF control is active (i_RefControl = TRUE).

 

Short circuit and external voltage situations are diagnosed too.

 

The validated voltage is written to S_o_Voltage if:

• The control is enabled, i.e. i_Enable is TRUE

• No fault (including initialization) has been diagnosed

 

 

 

 

Inputs

Input variable name

Data type

Unit

Range

Description

i_Enable

BOOL

-

-

Enable POU operation

i_RefControl

BOOL

-

-

Reference output control status request

i_ADValueCh1

DWORD

-

0 - G_ADC_MAXIMUM_VALUE

Measured channel 1 AD value

i_ADValueCh2

DWORD

-

0 - G_ADC_MAXIMUM_VALUE

Measured channel 2 AD value

Outputs

Output variable name

Data type

Unit

Range

Description

o_RefControl

BOOL

-

-

Reference output control status.

S_o_Voltage

SAFEDINT

mV

-

Validated reference voltage.

o_Status

Status

-

-

Status of output value. See Status struct.

Error diagnostic

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

 

Conditions

S_o_Voltage

o_RefControl

o_Status. OutputValid

o_Status error status

Event code FunctionID

Event code EventID

i_Enable TRUE

AND

init parameter error AND

 i_pEventCode valid

0

FALSE

FALSE

ParameterError

REF_CONTROL

PARAMETER_ERROR

i_Enable TRUE

AND

init parameter error AND
i_pEventCode NULL

0

FALSE

FALSE

ParameterError

-

-

i_Enable TRUE AND

init parameters ok AND

( i_ADValueCh1 > G_ADC_MAXIMUM_VALUE OR i_ADValueCh2 > G_ADC_MAXIMUM_VALUE )

0

FALSE

FALSE

ParameterError

REF_CONTROL

PARAMETER_ERROR

i_Enable rises

AND

 init parameters ok AND

input valid

Calculated voltage of channel 1

i_RefControl

TRUE

-

NO_FUNC

NO_ERROR

i_Enable TRUE AND

init parameters ok AND

(channel 1 voltage > G_REF_5V_OVERVOLT_LIMIT

OR channel 2 voltage > G_REF_5V_OVERVOLT_LIMIT)

0

FALSE

FALSE

Output High

REF_CONTROL

OUTPUT_TOO_HIGH

i_Enable TRUE AND

init parameters ok AND

i_RefControl TRUE AND

voltages ok AND

channel difference > tolerance

0

FALSE

FALSE

ValueMismatch

REF_CONTROL

DATA_MISMATCH

i_Enable TRUE AND

init parameters ok AND

i_RefControl FALSE AND

voltages ok AND

(channel 1 voltage > G_REF_EXT_VOLT_LIMIT

OR channel 2 voltage > G_REF_EXT_VOLT_LIMIT)

0

FALSE

FALSE

ExternalVoltage

REF_CONTROL

EXTERNAL_VOLTAGE

i_Enable TRUE AND

init parameters ok AND

i_RefControl TRUE AND

voltages ok AND

(channel 1 voltage < G_REF_5V_SHORTCUT_VOLT_LIMIT OR channel 2 voltage < G_REF_5V_SHORTCUT_VOLT_LIMIT)

0

FALSE

FALSE

OverCurrent

REF_CONTROL

VOLTAGE_SHORTCUT

 

 

Example code

Function block is included in hardware specific diagnostic program.

It is automatically generated to code template when MultiTool Creator is used.

 

Reference voltage diagnostic is a safe-context POU.

 

Definitions:

 

VAR_INPUT

(* Reference Voltage Control Inputs *)

i_Enable: BOOL := FALSE;            // Enable operation

i_RefVoltageControl: BOOL := FALSE; // Application request for 5V reference

i_5VRefChannel1: DWORD := DWORD#0;  // Filtered ADC value for 5V reference

i_5VRefChannel2: DWORD := DWORD#0;  // Filtered redundant ADC value for 5V reference

 

END_VAR

 

VAR_OUTPUT

(* Reference Voltage Control Outputs *)

o_RefControlStatus: EPEC_SHWD.Status; // FB status

o_RefControl_EC: EPEC_DITF.EventCode; // Event code

o_RefControl: BOOL;                   // 5V ref voltage control status for controlling FB function

S_o_RefVoltage: SAFEDINT;             // Measured voltage

 

END_VAR

 

VAR

init_ok: BOOL;                                    // Initialization status

refControl: EPEC_SHWD.S_RefControlAndDiagnostics; // POU instance

 

END_VAR

 

 

Init:

 

(* Reference voltage control and diagnostic *)

init_ok := refControl.Init(

S_i_Tolerance := G_IO.REFCONTROL_TOLERANCE,              // Maximum voltage tolerance (per mil)

S_i_ReferenceType5V := TRUE,                             // Ref output nominal voltage 5V (FALSE = 10V)

S_i_DiagnosticDelay := G_IO.REFCONTROL_DIAGNOSTIC_DELAY, // Delay time (ms) for error diagnostic

i_pEventCode := ADR(o_RefControl_EC)                     // Event code pointer for FB

);

 

 

Code:

 

(* Reference voltage control and diagnostic *)

refControl(

i_Enable := i_Enable,                // Enable operation

i_RefControl := i_RefVoltageControl, // Control request status

i_ADValueCh1 := i_5VRefChannel1,     // Filtered ADC value for 5V reference

i_ADValueCh2 := i_5VRefChannel2,     // Filtered redundant ADC value for 5V reference

S_o_Voltage => S_o_RefVoltage,       // Measured reference voltage

o_RefControl => o_RefControl,        // Reference voltage control status for FW function

o_Status => o_RefControlStatus       // FB ststus

);

 

 

 

See also

 

 

 

 

Source file topic100439.htm

Last updated 13-Jun-2024