OBIOEncoderCounter (FB)

FUNCTION_BLOCK OBIOEncoderCounter EXTENDS OBIOBaseCounter

Used for encoder counter on eco V3 PLC

precondition

the respective channel is configured as encoder channel.

The configuration/use of Touch-Trigger and Reset is optional. The encoder will use as a minimum 2 binary inputs, optional 4 binary inputs if configured with Touch/Reset.

- Up to 2 encoder-counter are possible, channel=0 or channel=1.
- The encoder supports quadrature encoder mode and Pulse/Direction mode. In quadrature enocder mode, all 4 rising/falling edges are used.
- Also the frequency will be measured. The frequency is just a measure for velocity with DirectionChange=FALSE

Note

200kHz is the maximum possible frequency to be measured.

- If 100kHz is used as input value for MaxFrequency, 100kHZ can be measured with 1% accuracy.
- If 1MHz is used as input value for MaxFrequency, 100kHz can be measured with 0.1% accuracy.

Note

This block should just be called once per cycle otherwise inconsistent values could be send to PRU, if send twice in short time.

InOut:

Scope

Name

Type

Initial

Comment

Inherited from

Input

Enable

BOOL

FALSE

A rising edge (Enable = TRUE) starts the operation, the output Busy goes to TRUE. All other inputs are read and considered continuously. A falling edge (Enable = FALSE) aborts the operation. During Aborting the Busy is still TRUE. Afterward all outputs are reset.

AbbLConCA

Output

Busy

BOOL

FALSE

Operation is running (while output Error is FALSE)

AbbLConCA

Error

BOOL

FALSE

Operation is stopped with error (while output Busy is FALSE). This output is TRUE for at least one cycle or until Enable is set to FALSE. The output ErrorID gives more details about the error.

AbbLConCA

Input

Channel

BYTE

0

Channel number, for encoder 0/1, for forward counter 0..3, for PulseTrainOutput 0/1

OBIOBaseCounter

Set

BOOL

Sets counter value to CounterValueSet on rising edge

OBIOBaseCounter

CounterValueSet

UDINT

Counter value to set

OBIOBaseCounter

EnableLimit

BOOL

Use limits, FALSE: counts ‘endless’, TRUE: counts from 0 to LimitValueMax, starts again with 0 on overflow. A new value will be used with rising edge on Enable

OBIOBaseCounter

LimitValueMax

UDINT

0

Upper limit, will count from 0 to < LimitValueMax-1 (with EnableLimit=TRUE), so the range for counting is LimitValueMax. The value has to be set while CounterValue < LimitValueMax. A new value will be used with rising edge on Enable

OBIOBaseCounter

Output

ErrorID

Error_ID

0

Error code

OBIOBaseCounter

CounterValue

UDINT

Actual counter value

OBIOBaseCounter

Input

Mode

BYTE

0=90°Mode=quadrature encoder, 1=Pulse/Direction Mode,new value used with rising edge on Enable

EnableRef

BOOL

Enables the reference mode. A rising edge on the configured input will then reset the counter value to CounterValueSet

EnableTouch

BOOL

Enables the touch trigger mode. A rising edge at touch-input will then capture the actual value as CounterTouchValue

MaxFrequency

UDINT

(FREQ_MEASURE_FREQUENCY / 100)

[Hz] Maximum allowed value = 1MHz. It is not necessarily the real measured my frequency, but the reference value used as a base for measurement. It affects the accuracy.

A frequency = “MaxFrequency” will be measured with 1% accuracy. A frequency = “MaxFrequency/10” will be measured with 0.1% accuracy. The minimum possible frequency to measure is: “MaxFrequency/655” For lower frequency values, the warning “MinFrequencyWarning” is shown. A new value for MaxFrequency will be used with rising edge on Enable.

MovingAverage

INT

0

values 2,3,4 will enable a moving average for the output CounterFrequency, using 2,3,4 cycles

Output

ReadyRef

BOOL

FALSE

Indicates reference search is ready (=EnableRef). Will be TRUE as long as EnableRef is TRUE

ReadyTouch

BOOL

FALSE

Indicates CounterTouchValue is ready (=EnableTouch). Will be TRUE as long as EnableTouch is TRUE

NewFrequencyResult

BOOL

new frequency measurement available

MinFrequencyWarning

BOOL

low value for frequency, below measurement range, the measured frequency includes estimation

FrequencyError

BOOL

if a position overrun happens too often, the frequency is not valid. decrease the cycle time, or increase LimitValueMax

DirectionChange

BOOL

direction change since last cycle

CounterTouchValue

UDINT

0

captured counter value, valid with ReadyTouch

CounterFrequency

LREAL

frequency measurement