Supported platforms: CODESYS 3.5

 

SingleCurrentValveController (FB)

Description

This FB handles single current controlled proportional valve in products that do not have built-in controller.

The FB includes end attenuation, ramp and control curve progression.

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

 

The FB uses internally SafeProportionalValveControl librarys FBs:

S_EndAttenuation

S_LinearRamp

S_CurrentRequest

S_AdaptiveController

 

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

- i_MaximumCurrent

- i_MinimumCurrent

- i_CoilResistance

- i_OverCurrentLimit

- i_WireBrokenLimit

- i_CorrectionParameter

- i_ImpulseUpParameter

- i_PI_P

- i_PI_I

- i_AttenuationLimit

- i_AscendRampTime

- i_DescendRampTime

- i_DiagnosticDelay

+ Any initialized event code.

 

Inputs

Input variable name

Data type

Range

Description

i_Enable

BOOL

FALSE/TRUE

Enables controlling of the PWM outputs

i_Control

INT

0..10000

Control signal from e.g. joystick.

i_MeasuredCurrent

UDINT

0..i_OverCurrentLimit

Measured current (mA).

i_SupplyVoltage

DINT

-

Measured supply voltage (mV).

i_AttenuationOn

BOOL

FALSE/TRUE

End attenuation sensor activity status.

i_MaximumCurrent

UINT

0..5000

Maximum current of valve (mA)

i_MinimumCurrent

UINT

0..5000

Minimum current of valve (mA)

i_CoilResistance

UDINT

> 0

Coil resistance (mΩ).

i_OverCurrentLimit

UINT

> S_i_Wire BrokenLimit and <= 5000

Over current error limit (mA).

i_WireBrokenLimit

UINT

0..5000

Wire broken error limit (mA). 

i_CorrectionParameter

UINT

-

Correction factor parameter. 1000 is a neutral value.

i_ImpulseUpParameter

UINT

-

Impulse up factor parameter.

Bigger value means higher impulse.

0 = use default impulse (1000). Impulse can be disabled with AdvancedInit method.

i_PI_P

UDINT

>0*

PI controller p-value

i_PI_I

UDINT

>0*

PI controller i-value with two decimals, 1 = 0,01.

i_AttenuationLimit

UINT

0..100%

End attenuation limit.

Percentage from maximum control value 10000.

i_AscendRampTime

UINT

-

Time (ms) of o_PWMRatio signal to change from center to positive max

(0->10000).

i_DescendRampTime

UINT

-

Time (ms) of o_PWMRatio signal to change from positive max to center

(10000->0).

i_DiagnosticDelay

UINT

-

Diagnostic delay (ms) for overcurrent/wire broken errors.

*Normally, value >0. PI-controller can be disabled by setting i_PI_P=0 and i_PI_I=0. This is required when finding the optimal i_CorrectionParameter value. See: S_AdaptiveController (FB), section Adjusting correction parameters

Outputs

Output variable name

Data type

Range

Description

o_PWMRatio

DWORD

HW specific

Output value to PWM pin.  Maximum value EPEC_HW.Constants.G_PWM_OUT_MAX_VALUE

o_InputHigh

BOOL

FALSE/TRUE

i_Control too high.

o_InputLow

BOOL

FALSE/TRUE

i_Control too low.

o_StartupError

BOOL

FALSE/TRUE

Control request on already when i_Enable rises.

o_OverCurrentError

BOOL

FALSE/TRUE

Overcurrent error is detected.

o_WireBrokenError

BOOL

FALSE/TRUE

Wire broken error is detected.

o_PI_I_TermError

BOOL

FALSE/TRUE

PI-controller I-term has reached it's limits.

o_ParameterError

BOOL

FALSE/TRUE

Incorrect parameter value in any of the monitored parameters.

 

 

AdvancedInit (Public Method)

This optional method set controlling parameters for controller.

 

Inputs

Input variable name

Data type

Range

Description

i_Enable

BOOL

FALSE/TRUE

Enable operation.

i_CurrentChangeSpeed

UINT

>0

Current change speed mA/ms.

i_UseImpulse

BOOL

FALSE/TRUE

Impulse is used when current request changes more than i_ParStep.

i_LearnOn

BOOL

FALSE/TRUE

Adaptive controller learning, yet to be implemented.

i_StartImpulseTime

UINT

-

How long start impulse is active. Parameter affects only if i_AutomaticStartImpulse is false

i_AutomaticStartImpulse

BOOL

FALSE/TRUE

Controller automatically set start impulse when current request is deviated from 0.

 

 

CorrectionParameterInit (Public Method)

This optional method can be used for setting an array of correction and impulse parameters for controllers.

 

Inputs

Input variable name

Data type

Range

Description

i_Enable

BOOL

FALSE/TRUE

Enable operation.

i_pCorrectionParameters

POINTER TO UINT

>0

Pointer to first correction factor parameter.

i_pImpulseUpParameters

POINTER TO UINT

>0

Pointer to first impulse up factor parameter.

i_pImpulseDownParameters

POINTER TO UINT

>0

Pointer to first impulse down factor parameter.

i_ParameterCount

UINT

-

Parameter count.

i_ParStep

UINT

>0

Difference (mA) between consecutive correction factor parameters.  

 

 

EventCodeInit (Public Method)

This optional method sets pointer for event code.

 

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.

 

 

Error diagnostic

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

 

FunctionID and EventID are only set if EventCode is used.

 

A parameter error is diagnosed if:

  • i_AttenuationLimit out of range OR

  • i_MinimumCurrent >= i_MaximumCurrent OR

  • i_OverCurrentLimit out of range OR

  • i_WireBrokenLimit >= i_OverCurrentLimit OR

 

 

Conditions

o_PWMRatio

Output error set TRUE

Event code FunctionID

Event code EventID

i_Enable TRUE AND

parameter error AND

 i_pEventCode valid

0

o_ParameterError

depends on the parameter

PARAMETER_ERROR

i_Enable TRUE AND

parameter error AND
i_pEventCode NULL

0

o_ParameterError

-

-

i_Enable rises AND

parameters ok AND

i_Control <> 0

0

o_StartupError

CURRENT

CONTROLLER

STARTUP_ERROR

i_Enable TRUE AND

 init parameters ok AND

S_i_Control within range

PWM ratio

-

NO_FUNC

NO_ERROR

i_Enable TRUE AND

 init parameters ok AND

S_i_Control > 10000  

0

o_InputHigh

END_ATTENUATION

INPUT_TOO_HIGH

i_Enable TRUE AND

 parameters ok AND

S_i_Control <  -10000  

0

o_InputLow

END_ATTENUATION

 INPUT_TOO_LOW

i_Enable TRUE AND

parameters ok AND

i_CurrentMeasured > i_OverCurrentLimit

0

o_OverCurrentError

CURRENT

CONTROLLER

OVER_CURRENT

i_Enable TRUE AND

parameters ok AND i_CurrentRequest > 0 AND i_CurrentMeasured < i_WireBrokenLimit

0

o_WireBrokenError

CURRENT

CONTROLLER

WIRE_BROKEN

i_Enable TRUE AND

parameters ok AND

PI controller internal integrator (I) term out of limits

PWM ratio

o_PI_I_TermError

NO_FUNC

NO_ERROR

 

 

Example code

 

 

 

 

 

How to use SingleCurrentValveController as traditional PI-controller

It is possible to use SingleCurrentValveController as traditional PI-controller by using the following settings:

 

  1. Call AdvancedInit method once with the following input values

  2. Set main block input i_CorrectionParameter to value 1. Other inputs can be application specific.

See also

S_AdaptiveController (FB)

S_CurrentRequest (FB)

S_EndAttenuation (FB)

S_LinearRamp (FB)

 

 

 

 

Source file topic100747.htm

Last updated 21-Feb-2025