Supported platforms: CODESYS 3.5, CODESYS 3.5 SAFETYCODESYS 3.5 SP19 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 (SP10)Initialization parameters (SP10)

 

Input variable name

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 parameters (SP19)Initialization parameters (SP19)

 

Input variable name

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.
S_i_ControlChangeDiagDelay SAFEUINT ms - Enable delay for short circuit and external voltage diagnostic after control request state change.
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 (SP10, V1.4.1.0 or older)Operation (SP10, 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 (SP10, V1.5.1.0 or newer)Operation (SP10, 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.


Overvoltage is diagnosed using HW specific limit.

 

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 (SP19, V2.0.4.0)Operation (SP19, V2.0.4.0)


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.


Overvoltage is diagnosed using HW specific limit. If overvoltage error is detected, the library shall continue overvoltage monitoring. Persistent overvoltage error is set if overvoltage error is detected again after disabling REF output control.


The validated voltage is written to S_o_Voltage if:


 

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.

 

 

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

Error diagnostic (SP10)Error diagnostic (SP10)


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_5V_EXTERNAL_VOLT_LIMIT

OR channel 2 voltage > G_REF_5V_EXTERNAL_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


Note: For 10V type the INT library constants are compared to corresponding 10V limit values.


 

Error diagnostic (SP19)Error diagnostic (SP19)


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
 parameters ok AND
Output High status is active AND
 (channel 1 voltage > G_REF_5V_ OVERVOLT_LIMIT
OR channel 2 voltage > G_REF_5V_ OVERVOLT_LIMIT)
0 FALSE FALSE PersistentOvervoltage 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 

control change delay has elapsed AND

(channel 1 voltage > G_REF_5V_EXTERNAL_VOLT_LIMIT

OR channel 2 voltage > G_REF_5V_EXTERNAL_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

control change delay has elapsed 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


Note: For 10V type the INT library constants are compared to corresponding 10V limit values.


 

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 21-Feb-2025