The Encoder Control camera feature allows you to control and monitor a quadrature encoder.
Quadrature encoders are also known as incremental, rotary, or shaft encoders. They are typically used in automation applications where motion or changes in position must be measured.
The Encoder Control feature is only available on Basler racer 2 cameras.
The Encoder Control is interfaced to a quadrature encoder, which can be either rotary or linear, that generates two output signals A and B. These are also called phase or source A and B. The two signals have a phase difference of 90° used to track the encoder's forward and backward direction of motion. Phase A and B are the input signals for the cameras's encoder control.
The following image shows a typical implementation of the encoder control.
The encoder can either move in forward or in backward direction. To detect the direction of motion, the encoder control reads the order of the rising and falling edges of the A and B signals.
Forward direction of motion: The A signal rises 90° ahead of the B signal. The phase order is 1-2-3-4.
Backward direction of motion: The B signal is rises ahead of the A signal. The phase order is 4-3-2-1.
The following image shows the four phases corresponding to the digital signal levels of the A and B signals.
The encoder control uses a position counter driven by the A and B signals. The counter value increments in forward direction of motion and decrements in backward direction of motion.
The position counter runs continuously. Its value represents the number of incoming signals received since the last reset. Therefore, the counter value always reflects the current position of the target object in relation to the forward or backward direction of motion.
Four fully completed signal phases form a quadrature cycle. Every full quadrature cycle, i.e., when the A signal edge is rising, the quadrature encoder counter increments or decrements by 1.
The Four Phase mode is quite robust and allows to filter out a small amount of signal jitter between two phases.
In High Resolution mode, the counts per cycle are quadrupled. The encoder counter increments or decrements by 1 on each signal phase, i.e., when the A and B signal edges are rising and falling.
Info
Jitter filtering isn't possible in High Resolution mode. The High Resolution mode isn't therefore recommended to be used together with an encoder output mode set to Motion since jitter between two phases can result in continuous output trigger pulses.
The encoder output mode allows you to set the conditions for the encoder control to generate a valid output signal. The following encoder output modes are available:
Motion: Output trigger signals are generated regardless of the direction of motion.
DirectionUp: Output trigger signals are generated at all position increments in forward direction. Backward direction of motion is ignored.
DirectionDown: Output trigger signals are generated at all position increments in backward direction. Forward direction of motion is ignored.
PositionUp: Output trigger signals are generated at all new positions in forward direction. If the encoder reverses, no output trigger signals are generated until it has again passed the position where the reversal started.
PositionDown: Output trigger signals are generated at all new positions in backward direction. If the encoder reverses, no output trigger signals are generated until it has again passed the position where the reversal started.
EncoderDivider: Determines the number of input signals from the encoder needed to generate an encoder output trigger signal.
EncoderValue: Gets the current value of the position counter. This parameter is read-only.
EncoderReset: Resets the current counter value of the position counter to 0. This also resets and restarts the entire encoder control. Signal pulses are counted immediately after restart.
// Select the desired encoder selectorcamera.EncoderSelector.SetValue(EncoderSelector_Encoder1)// Select line 2 as the source signal for the A input of the encoder controlcamera.EncoderSourceA.SetValue(EncoderSourceA_Line2);// Select line 3 as the source signal for the B input of the encoder controlcamera.EncoderSourceB.SetValue(EncoderSourceB_Line3);// Select the desired encoder modecamera.EncoderMode.SetValue(EncoderMode_FourPhase);// Determine the number of input signals needed to generate an encoder output trigger signalcamera.EncoderDivider.SetValue(1);// Select the desired encoder output modecamera.EncoderOutputMode.SetValue(EncoderOutputMode_Motion);
INodeMap&nodemap=camera.GetNodeMap();// Select the desired encoder selectorCEnumParameter(nodemap,"EncoderSelector").SetValue("Encoder1");// Select line 2 as the source signal for the A input of the encoder controlCEnumParameter(nodemap,"EncoderSourceA").SetValue("Line2");// Select line 3 as the source signal for the B input of the encoder controlCEnumParameter(nodemap,"EncoderSourceB").SetValue("Line3");// Select the desired encoder modeCEnumParameter(nodemap,"EncoderMode").SetValue("FourPhase");// Determine the number of input signals needed to generate an encoder output trigger signalCIntegerParameter(nodemap,"EncoderDivider").SetValue(1);// Select the desired encoder output modeCEnumParameter(nodemap,"EncoderOutputMode").SetValue("Motion");
// Select the desired encoder selectorcamera.Parameters[PLCamera.EncoderSelector].SetValue(PLCamera.EncoderSelector.Encoder1);// Select line 2 as the source signal for the A input of the encoder controlcamera.Parameters[PLCamera.EncoderSourceA].SetValue(PLCamera.EncoderSourceA.Line2);// Select line 3 as the source signal for the B input of the encoder controlcamera.Parameters[PLCamera.EncoderSourceB].SetValue(PLCamera.EncoderSourceB.Line3);// Select the desired encoder modecamera.Parameters[PLCamera.EncoderMode].SetValue(PLCamera.EncoderMode.FourPhase);// Determine the number of input signals needed to generate an encoder output trigger signalcamera.Parameters[PLCamera.EncoderDivider].SetValue(1);// Select the desired encoder output modecamera.Parameters[PLCamera.EncoderOutputMode].SetValue(PLCamera.EncoderOutputMode.Motion);
/* Macro to check for errors */#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)GENAPIC_RESULTerrRes=GENAPI_E_OK;/* Return value of pylon methods *//* Select the desired encoder selector */errRes=PylonDeviceFeatureFromString(hdev,"EncoderSelector","Encoder1");CHECK(errRes);/* Select line 2 as the source signal for the A input of the encoder control */errRes=PylonDeviceFeatureFromString(hdev,"EncoderSourceA","Line2");CHECK(errRes);/* Select line 3 as the source signal for the B input of the encoder control */errRes=PylonDeviceFeatureFromString(hdev,"EncoderSourceB","Line3");CHECK(errRes);/* Select the desired encoder mode */errRes=PylonDeviceFeatureFromString(hdev,"EncoderMode","FourPhase");CHECK(errRes);/* Determine the number of input signals needed to generate an encoder output trigger signal */errRes=PylonDeviceSetIntegerFeature(hdev,"EncoderDivider",1);CHECK(errRes);/* Select the desired encoder output mode */errRes=PylonDeviceFeatureFromString(hdev,"EncoderOutputMode","Motion");CHECK(errRes);
# Select the desired encoder selectorcamera.EncoderSelector.Value="Encoder1"# Select line 2 as the source signal for the A input of the encoder controlcamera.EncoderSourceA.Value="Line2"# Select line 3 as the source signal for the B input of the encoder controlcamera.EncoderSourceB.Value="Line3"# Select the desired encoder modecamera.EncoderMode.Value="FourPhase"# Determine the number of input signals needed to generate an encoder output trigger signalcamera.EncoderDivider.Value=1# Select the desired encoder output modecamera.EncoderOutputMode.Value="Motion"