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.
Note
200kHz is the maximum possible frequency to be measured.
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
EnableBOOLFALSE
A rising edge (Enable = TRUE) starts the operation, the output Busy goes to TRUE. All other inputs are read and considered continuously. Execution will continue forever until a falling edge (Enable = FALSE) aborts the operation. During Aborting the Busy is still TRUE. Afterward all outputs are reset.
AbbLConC3
Output
BusyBOOLFALSE
Operation is running (while output Error is FALSE)
AbbLConC3
ErrorBOOLFALSE
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.
AbbLConC3
Input
ChannelBYTE0
Channel number, for encoder 0/1, for forward counter 0..3, for PulseTrainOutput 0/1
OBIOBaseCounter
SetBOOLSets counter value to CounterValueSet on rising edge
OBIOBaseCounter
CounterValueSetUDINTCounter value to set
OBIOBaseCounter
EnableLimitBOOLUse 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
LimitValueMaxUDINT0
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
ErrorID0
Error code
OBIOBaseCounter
CounterValueUDINTActual counter value
OBIOBaseCounter
Input
ModeBYTE0=90°Mode=quadrature encoder, 1=Pulse/Direction Mode,new value used with rising edge on Enable
EnableRefBOOLEnables the reference mode. A rising edge on the configured input will then reset the counter value to CounterValueSet
EnableTouchBOOLEnables the touch trigger mode. A rising edge at touch-input will then capture the actual value as CounterTouchValue
ContinuousModeBOOLwith ContinuousMode=TRUE and EnableTouch=TRUE, the touch trigger will reenable itself automatically.
In this mode, the output ReadyTouch will be true for just 1 cycle.
With ContinuousMode=FALSE, a rising edge at EnableTouch is required to retrigger the next TouchProbe, this will set output ReadyTouch=TRUE until EnableTouch=FALSE.
Also with ContinuousMode=TRUE, it is required to call the block every PLC cycle.
MaxFrequencyUDINT(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.
MovingAverageINT0
values 2,3,4 will enable a moving average for the output CounterFrequency, using 2,3,4 cycles
MeasurementPeriodBYTE0
values 0..11 are valid, the value will be limited internally.
This parameter sets the period being used for doing the frequency measurement.
The result will be a frequency value measured over a period of 1-2048 rising edges of the input. The number of rising edges is set in the format 2^n, (n= parameter measurementPeriod). Allowed values for measurementPeriod are in the range of 0-11.
By default, 2^0 is used (measurementPeriod = 0). This will result in a frequency measured based on two subsequent rising edges. With 2^n, the measurement will be done based on 2^n + 1 rising edges.
Changes of the parameter will become effective with the next rising edge on the Enable input
Output
ReadyRefBOOLFALSE
Indicates reference search is ready (=EnableRef). Will be TRUE as long as EnableRef is TRUE
ReadyTouchBOOLFALSE
Indicates CounterTouchValue is ready (=EnableTouch). Will be TRUE as long as EnableTouch is TRUE
NewFrequencyResultBOOLnew frequency measurement available
MinFrequencyWarningBOOLlow value for frequency, below measurement range, the measured frequency includes estimation
FrequencyErrorBOOLif a position overrun happens too often, the frequency is not valid. decrease the cycle time, or increase LimitValueMax
DirectionChangeBOOLdirection change since last cycle
CounterTouchValueUDINT0
captured counter value, valid with ReadyTouch
CounterFrequencyLREALfrequency measurement