Block that performs counting of encoder pulses.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
COUNT_SRC |
BYTE |
It determines which encoder will be used in counting of pulses |
|
PRESET |
BOOL |
Attributes value from PV to CV |
|
RESET# |
BYTE |
Chooses the CV reset control |
|
RESET_VAR |
BOOL |
If the choice of RESET # is by variable, it performs the reset of CV when in TRUE value |
|
SAVE# |
BYTE |
Chooses the saving control of the counter |
|
SAVE_VAR |
BOOL |
If the choice of SAVE# is by variable, it performs the saving of CV in SV when in TRUE value |
|
REF_CNT |
LREAL |
Value of the reference pulse for output enabling |
|
PV |
LREAL |
Value of initial configuration |
|
RESTART |
LREAL |
Reference value for automatic reset of CV |
|
VAR_OUTPUT |
Q |
BOOL |
Output enabling |
RESET_OCC |
BOOL |
Reset flag |
|
SAVE_OCC |
BOOL |
Saving flag |
|
CV |
LREAL |
Value of pulse counter |
|
SV |
LREAL |
Last saved counter value |
|
VAR |
READENC5_INST_0 |
READENC5 |
Instance of access to block structure |
Operation
When this block identifies a leading edge in EN, it resets its outputs and counts the pulses from the encoder specified in COUNT_SRC while enabled. This count value is stored in CV.
The specified control in RESET# resets the counter when enabled, while the specified control in SAVE#, when activated, stores the value of CV in SV. Each of these controls sets its respective flag (RESET_OCC or SAVE_OCC) for one scan cycle.
The block also allows you to configure an automatic reset when CV reaches the RESTART value.
The value of Q is activated by one scan cycle when CV reaches the value of REF_CNT.
Block Flowchart

Example in Ladder

The above example reads the encoder 1 and stores its value in COUNTER, with count reference set in REF and RESET and SAVE control done by the variables LOAD_ZERO and SAVE_COUNT, respectively. When COUNTER is equals to REF, the output Q is set for one scan cycle.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR LOAD_PRESET, LOAD_ZERO, SAVE_COUNT : BOOL; REF1, PRESET_VALUE, RESTART : LREAL; FLAG_RESET, FLAG_SAVE : BOOL; COUNTER, COUNTER_SAVED : LREAL; FB_READENC5_INST_0 : FB_READENC5; END_VAR
FB_READENC5_INST_0( EN:=DI1, COUNT_SRC:=1, PRESET:=LOAD_PRESET, RESET:=0, RESET_VAR:=LOAD_ZERO, SAVE:=0, SAVE_VAR:=SAVE_COUNT, REF_CNT:=REF1, PV:=PRESET_VALUE, RESTART:=RESTART, RESET_OCC=>FLAG_RESET, SAVE_OCC=>FLAG_SAVE, CV=>COUNTER, SV=>COUNTER_SAVED, Q=>DO1);
|
|---|