Block that reads the pulse value of an encoder according to a type of reading chosen, interpreting it as a fraction of revolutions.
Ladder Representation

Block Structure
Variable Type |
Name |
Data Type |
Description |
VAR_INPUT |
EN |
BOOL |
Block enabling |
Source# |
BYTE |
Counting source |
|
Pulses |
DWORD UDINT |
Maximum number of pulses in a turn |
|
VAR_OUTPUT |
ENO |
BOOL |
Output enabling |
Value |
DINT DWORD UDINT |
Counting value |
|
VAR |
READENC2_INST_0 |
READENC2 |
Instance of access to block structure |
Operation
When this block has a TRUE value in EN, it gets the number of pulses counted in the encoder, as selected in Source #, and transfers them to Value. At each leading edge, Value is reset to zero. When Value increases and reaches the value of Pulses, Value receives zero. When Value decrements and tends to reach a value of -1, Value receives the value in Pulses. This way, Value always displays the result in fraction of revolutions.
When EN has FALSE value, Value remains unchanged.
The ENO value forwards to the next Ladder block the EN value after the operation is completed.
Block Flowchart

Example in Ladder

The above example, when identifying a leading edge on DI1, starts counting the number of pulses in the encoder connected in quadrature conformation AB. PULSES_IN_TURN is the value of pulses to complete a turn. If the value read is higher, the counting restarts from zero. If the value read is negative, counting restarts from PULSES_IN_TURN. The resulting value is stored in VALUE. The block ends with success, ENO output is activated.
Example in ST
The example below displays the instructions for applying the example above in the ST language.
VAR PULSES_IN_TURN : DINT; VALUE : UDINT; READENC2_INST_0 : FB_READENC2; END_VAR
READENC2_INST_0.EN := DI1; READENC2_INST_0(Source:=0, Pulses:=PULSES_IN_TURN); VALUE := READENC2_INST_0.Value; DO1 := READENC2_INST_0.ENO;
|
|---|