跳转到内容

Encoder Control#

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.

Typical Encoder Control Implementation

Encoder Direction of Motion#

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.

Relationship Between A and B Signals

Position Counter#

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.

Encoder Mode#

The encoder mode controls how the incoming encoder signals are calculated by the encoder control.

Four Phase Mode#

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.

Four Phase Mode

High Resolution Mode#

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.

High Resolution Mode

信息

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.

Encoder Output Mode#

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.
  • 熄灭: No output trigger signals are generated.

附加参数#

  • 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.

Configuring the Encoder Control#

To configure the encoder control:

  1. 设置 EncoderSelector parameter to Encoder1.
  2. 设置 EncoderSourceA parameter to one of the available source signals, e.g., Line2.
  3. 设置 EncoderSourceB parameter to one of the available source signals, e.g., Line3.
  4. 设置 EncoderMode 参数设置为以下值:
  5. 设置 EncoderDivider parameter to the desired number of input signals.
  6. 设置 EncoderOutputMode parameter to the kind of output mode that you want to enable, e.g., Motion.

To configure the camera to be triggered by the encoder signal:

  1. 设置 TriggerSelector parameter to LineStart.
  2. 设置 TriggerMode parameter to .
  3. 设置 TriggerSource parameter to Encoder1.

示例代码#

// Select the desired encoder selector
camera.EncoderSelector.SetValue(EncoderSelector_Encoder1)
// Select line 2 as the source signal for the A input of the encoder control
camera.EncoderSourceA.SetValue(EncoderSourceA_Line2);
// Select line 3 as the source signal for the B input of the encoder control
camera.EncoderSourceB.SetValue(EncoderSourceB_Line3);
// Select the desired encoder mode
camera.EncoderMode.SetValue(EncoderMode_FourPhase);
// Determine the number of input signals needed to generate an encoder output trigger signal
camera.EncoderDivider.SetValue(1);
// Select the desired encoder output mode
camera.EncoderOutputMode.SetValue(EncoderOutputMode_Motion);
INodeMap& nodemap = camera.GetNodeMap();
// Select the desired encoder selector
CEnumParameter(nodemap, "EncoderSelector").SetValue("Encoder1");
// Select line 2 as the source signal for the A input of the encoder control
CEnumParameter(nodemap, "EncoderSourceA").SetValue("Line2");
// Select line 3 as the source signal for the B input of the encoder control
CEnumParameter(nodemap, "EncoderSourceB").SetValue("Line3");
// Select the desired encoder mode
CEnumParameter(nodemap, "EncoderMode").SetValue("FourPhase");
// Determine the number of input signals needed to generate an encoder output trigger signal
CIntegerParameter(nodemap, "EncoderDivider").SetValue(1);
// Select the desired encoder output mode
CEnumParameter(nodemap, "EncoderOutputMode").SetValue("Motion");
// Select the desired encoder selector
camera.Parameters[PLCamera.EncoderSelector].SetValue(PLCamera.EncoderSelector.Encoder1);
// Select line 2 as the source signal for the A input of the encoder control
camera.Parameters[PLCamera.EncoderSourceA].SetValue(PLCamera.EncoderSourceA.Line2);
// Select line 3 as the source signal for the B input of the encoder control
camera.Parameters[PLCamera.EncoderSourceB].SetValue(PLCamera.EncoderSourceB.Line3);
// Select the desired encoder mode
camera.Parameters[PLCamera.EncoderMode].SetValue(PLCamera.EncoderMode.FourPhase);
// Determine the number of input signals needed to generate an encoder output trigger signal
camera.Parameters[PLCamera.EncoderDivider].SetValue(1);
// Select the desired encoder output mode
camera.Parameters[PLCamera.EncoderOutputMode].SetValue(PLCamera.EncoderOutputMode.Motion);
/* Macro to check for errors */
#define CHECK(errc) if (GENAPI_E_OK != errc) printErrorAndExit(errc)
GENAPIC_RESULT errRes = 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 selector
camera.EncoderSelector.Value = "Encoder1"
# Select line 2 as the source signal for the A input of the encoder control
camera.EncoderSourceA.Value = "Line2"
# Select line 3 as the source signal for the B input of the encoder control
camera.EncoderSourceB.Value = "Line3"
# Select the desired encoder mode
camera.EncoderMode.Value = "FourPhase"
# Determine the number of input signals needed to generate an encoder output trigger signal
camera.EncoderDivider.Value = 1
# Select the desired encoder output mode
camera.EncoderOutputMode.Value = "Motion"

您也可以使用 pylon Viewer 轻松设置参数。