# Operating a Variable Delay Line

## Before you Begin

Insure these prerequisites are met before using the VDL optical module per the instructions listed below:

* VDL driver circuit and VDL connector receptacle must be installed on the Laser driver board.
* Laser driver board must be [connected to the host PC via USB cable](https://docs.axsun.com/axsun-knowledge-base/guides/ss-oct-laser-engine#making-connections) (or connected via Ethernet DAQ).
* Axsun USB device driver must be installed on the host PC (or network card must have appropriate configuration if connected via Ethernet DAQ).
* [*AxsunOCTControl.dll*](https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol.dll)  / [*AxsunOCTControl\_LW.dll* ](https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol-lightweight) (API access) or [OCT Host](https://docs.axsun.com/axsun-knowledge-base/software-tools/oct-host) / [Hardware Control Tool](https://docs.axsun.com/axsun-knowledge-base/software-tools/hardware-control-tool) (GUI tools) must be installed on the host PC.

## VDL Optical Module Installation

With the Laser Engine powered OFF, plug the VDL optical module's electrical connector into the corresponding receptacle on the laser driver board. The beige 2x5-pin VDL connector is unique and can only be plugged into one receptacle on the laser driver board.  Also connect the VDL module's fiber connector(s) to your optical network as desired.

![Beige 2x5-pin VDL electrical connector plugged into a Laser driver board.](https://3144558317-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LP1icDU_wgMhPOYQY7u%2F-LQ_g80K27p6mQYjmDAb%2F-LQ_gLC1fWGPiQgBeP9x%2FVDL_connected.png?alt=media\&token=46eaf3a2-e419-4df3-b21f-ae8c57fb099d)

Power ON the Laser Engine.  Confirm successful connection between the Laser Engine and the host PC via [OCT Host](https://docs.axsun.com/axsun-knowledge-base/software-tools/oct-host) or the [Hardware Control Tool](https://docs.axsun.com/axsun-knowledge-base/software-tools/hardware-control-tool).  For example **OCT Engine** (i.e. the laser driver board) will be listed in the **Connected Boards:** indicator in the lower left region of the OCT Host window:

![OCT Engine connection as shown in the OCT Host window](https://3144558317-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LP1icDU_wgMhPOYQY7u%2F-LP2D5HlFFGuTKgbLFOU%2F-LP2FfnLugwGfFFSRG_k%2Fimage.png?alt=media\&token=95e1a48e-4e5f-4b53-ad70-4087ec6829d2)

## VDL Operation

Adjustment of the optical delay provided by the VDL optical module is achieved by movement of a retroreflector mounted on a carriage actuated linearly by a stepper motor turning a lead screw. The user sends commands to the Laser driver board microcontroller firmware which then controls the stepper motor motion.

There is no linear encoder present, hence the controller firmware must register itself with the actual physical position of the carriage by moving it to one extreme until it triggers a limit switch.  This process is called *homing* or *zeroing* the VDL.  Once the VDL has been homed, the firmware tracks the carriage position by accumulating all issued steps in the positive and negative directions.  The homed position is considered the 0.00 mm delay point.

{% hint style="warning" %}
**IMPORTANT!**  For accurate motion control of the VDL, the *homing* operation must be performed after each power-on cycle of the Laser driver board (i.e. any time the device firmware is rebooted).
{% endhint %}

Commands to a) go home, b) move to an arbitrary position within the total range, and c) get the current VDL position are available in the Axsun GUI Tools ([OCT Host ](https://docs.axsun.com/axsun-knowledge-base/software-tools/oct-host)or the [Hardware Control Tool](https://docs.axsun.com/axsun-knowledge-base/software-tools/hardware-control-tool)) or can be sent by a user's custom application using either the [AxsunOCTControl\_LW](https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol-lightweight) or [AxsunOCTControl](https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol.dll) APIs:

{% tabs %}
{% tab title="OCT Host" %}
VDL controls on the [OCT Host](https://docs.axsun.com/axsun-knowledge-base/software-tools/oct-host) GUI are located on the **VDL Motor** tab.  Buttons and input fields are provided to **Home** the VDL, **Move** it in a **Relative** or **Move** it in an **Absolute** fashion by a desired distance, or **Stop** VDL motion in progress.  The current status of the VDL is also shown.  Any requests to move the VDL to a position which is outside of its allowable delay range (0 to 15 mm) will be ignored.

![OCT Host window showing VDL Motor tab and associated VDL controls and indicators.](https://3144558317-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LP1icDU_wgMhPOYQY7u%2F-LQdS4MHvKUjxEdQtWsS%2F-LQdppiMMUgIUCaHo7ZY%2FOCTHostVDLmotorTab.png?alt=media\&token=09113849-ac84-49fd-ade0-db7c28cac5fd)
{% endtab %}

{% tab title="Hardware Control Tool" %}
VDL controls on the [Hardware Control Tool](https://docs.axsun.com/axsun-knowledge-base/software-tools/hardware-control-tool) GUI are located on the **Miscellaneous** tab.  The **GO HOME** button homes the VDL and adjustment of the numeric **VDL Position (mm)** control field immediately commands the VDL to move to the requested absolute position.

![Hardware Control Tool window showing Miscellaneous tab and VDL controls.](https://3144558317-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LP1icDU_wgMhPOYQY7u%2F-LQdqwev0O0DdzFoH9KD%2F-LQdrfWP1sjBgd5gYHYi%2FHardwareCntTool_VDL.png?alt=media\&token=d1ffac52-2405-4a0c-90e9-0855f5c53fee)
{% endtab %}

{% tab title="AxsunOCTControl\_LW API" %}
Before operating the VDL, please read the general instructions on [using the AxsunOCTControl\_LW API](https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol-lightweight/using-the-control_lw-api) in your custom application.

See the [AxsunOCTControl\_LW function reference](http://downloads.axsun.com/public/software/EthernetDAQ/AxsunOCTControl_LW_API_manual/) for details on calling the functions discussed here.

#### Homing the VDL

The VDL Homing operation must be performed for each power-on cycle of the Laser Engine board by calling `axHomeVDL()`.  The carriage is moved in the negative direction until it reaches the home limit switch and then backs off the switch slightly. All subsequent motion within the delay range is referenced to this 0.00 mm position. This function returns after *requesting* the homing operation from the VDL controller; it does not wait for the mechanical homing operation to complete before returning.

#### Moving the VDL to a Desired Position

The VDL can be moved in a *relative* fashion (positive or negative displacement from the current position) with `axMoveRelVDL(..)` or in an *absolute* fashion (directly to a fixed position within the delay range) with `axMoveAbsVDL(..)`.  Any requests to move the VDL to a position which is outside of its allowable delay range (0 to 15 mm) will be ignored.  These functions return immediately after requesting the the move operation from the VDL controller; they do not wait for the requested move operation to complete before returning.

#### Querying the Status of the VDL

The status of the VDL hardware can be queried or polled with `axGetVDLStatus(..)`, providing information useful especially during a home or move operation, such as: instantaneous position and speed, target position for the current move, and limit switch state.  After issuing a home or move command, poll this function to determine if the operation has completed or failed with an error.

#### Stopping the VDL

A VDL operation in progress can be stopped immediately using `axStopVDL()`. This function returns after *requesting* the stop operation from the VDL controller; it does not wait for the mechanical operation to stop before returning.
{% endtab %}

{% tab title="AxsunOCTControl API" %}
Before operating the VDL, please read the general instructions on [using the AxsunOCTControl API](https://docs.axsun.com/axsun-knowledge-base/api-references/axsunoctcontrol.dll/using-the-control-api) in your custom application.

#### Homing the VDL

The VDL Homing operation must be performed for each power-on cycle of the Laser driver board.  The carriage is moved in the negative direction until it reaches the home limit switch and then backs off the switch slightly. All subsequent motion within the delay range is referenced to this 0.00 mm position. This method returns after *requesting* the homing operation from the VDL controller; it does not wait for the mechanical homing operation to complete before returning.

```csharp
uint  HomeVDL()       // returns 0 (success) or error code
```

#### Moving the VDL to a Desired Position

The VDL can be moved in a *relative* fashion (positive or negative displacement from the current position) or *absolute* fashion (directly to a fixed position within the delay range).  Any requests to move the VDL to a position which is outside of its allowable delay range (0 to 15 mm) will be ignored.  These methods return immediately after requesting the the move operation from the VDL controller; they do not wait for the requested move operation to complete before returning.

```csharp
uint  MoveRelVDL(    // returns 0 (success) or error code
    float Position,  // distance to move relative to the current position (mm)
    float Speed)     // the speed at which to move (mm/sec)
```

```csharp
uint  MoveAbsVDL(    // returns 0 (success) or error code
    float Position,  // the desired position (mm) in absolute terms 
    float Speed)     // the speed at which to move (mm/sec)
```

#### Querying the Status of the VDL

The status of the VDL hardware can be queried or polled, providing information useful especially during a home or move operation, such as: instantaneous position and speed, target position for the current move, and limit switch state.  After issuing a home or move command, poll this method to determine if the operation has completed or failed with an error.

```csharp
uint  GetStepperStatus(           // returns 0 (success) or error code
    ref float Position,           // current position (mm)
    ref float Target,             // target position (mm) during a move operation
    ref float Speed,              // current speed (mm/sec) during a move operation
    ref uint State,               // 1 = idle, 
                                  // 2 = moving, 
                                  // 3 = seeking home, 
                                  // 4 = backing off home, 
                                  // 5 = at home,
                                  // 10 = error state
    ref bool HomeSwitch,          // indicates if the home switch is tripped
    ref bool LimitSwitch,         // indicates if limit switch is tripped (far end of travel)
    ref int ErrorFromLastHome,    // error accumulated since last Home operation (in motor microsteps)
    ref uint LastMoveTime,        // time (sec) taken by the last issued move command
    ref uint Error)               // firmware error code (0 if no error)
```

#### Stopping the VDL

A VDL operation in progress can be stopped immediately using `StopVDL()`. This method returns after *requesting* the stop operation from the VDL controller; it does not wait for the mechanical operation to stop before returning.

```csharp
uint  StopVDL()       // returns 0 (success) or error code
```

{% endtab %}
{% endtabs %}
