Month: September 2015

Linear power

The following procedure will allow you to define a linearization table for your Pockels’ cell so you can obtain a linear power change with equal steps in the value of the power slider in Scanbox.

During imaging the laser power is controlled by an 8-bit DAC that ranges from from 0V (at a DAC register value of 0) to 2V (when the DAC register value is 255).

The DAC provides the control voltage used by your Pockels driver. I have the Conoptics 302RM driver, which accepts a maximum of 2 Vpp as its control signal.  Other users may have different drivers, but the instructions below should apply for all of them.

The curve relating laser power to voltage depends on your driver, Pockels’ cell and laser wavelength.  The first step to compute your linearization table is to measure the power of the laser during imaging as a function of the DAC register value. Typically doing this measurement at steps of 8 or 16 is enough.

To do this you begin by resetting the default lookup table to the identity.  With Scanbox open (but not imaging), simply go to the Matlab command window and type:

>> sb_pockels_lut_identity

Now, you can manually set the power to an arbitrary value by typing:

>> sb_pockels(0,newValue)

This allows you to directly set the DAC register value to newValue.  Note that after resetting the LUT to the identity the range of the DAC will be from 0V to 2V for a DAC value of 255.

Set the DAC register to your desired newValue.  If you now get the microscope to scan, you can measure the average power at the newValue. Once you have obtained sufficient measurements at different levels, spanning the range 0 to 255,  you can interpolate and determine how the power depends on the DAC register value.

The result is likely to be a non-linear and non-monotonic curve, where the maximum power is obtained as some intermediate value and then it starts to decrease.  This is normal behavior.

From the interpolated curve you can calculate a linearization table such that changes in power will be linear and it will attain the maximum possible power for a setting of 255.

The final step is to include your linearization table in the Scanbox configuration file, which now includes a line that reads:

sbconfig.pockels_lut = uint8([]);

Simply replace the empty array with your lookup table and it will be delivered to the firmware every time Scanbox starts up. The list must have exactly 256 entries or Scanbox will ignore it.

For this procedure to work you must first update your firmware (which you will find under the Yeti/drivers directory).

If you have any questions let me know!

Warning: Please make sure the maximum voltage you test is the one allowed by your driver!


Larger field of view and finer control of pixel size

There have been requests for Scanbox to accommodate a larger field of view and the ability to precisely calibrate the aspect ratio and size of pixels.  The latest version (along with modifications in the firmware) allow you to do just this.

[This paragraph about the diodes is only relevant to older boards] A first step to maximize the field of view is to remove two diodes from the Scanbox controller board that are limiting the extend of the control signal to the galvanometer. These are located close to the connector labeled GALVO on the board and are labeled TVS4 and TVS5. In the picture below, they are found between GALVO connector and the TP9 test point. To remove them, use a soldering iron, pliers, and care not to damage other components . Remove both diodes. Make sure the board is not powered when you do this.

After you are done, download the latest version from Github, update the firmware, and the Scanbox distribution.  Remember to keep a copy of your old version, so you can copy some of your old settings.

Towards the end of the scanbox_config.m file you will see a new section that contains variables that allow you more precise control of the size and aspect ratio of your pixels:

sbconfig.hsync_sign = 0;        % 0-normal, 1-flip horizontal axis
sbconfig.gain_override = 1;     % override default gain settings?
sbconfig.gain_resonant = [1.4 2.9 5.7];  % gains for x1, x2 and x4
sbconfig.gain_galvo    = [1.0 2.0 4.0];  % gains for x1, x2 and x4
sbconfig.dv_galvo      = 64;             % dv per line (64 is the max)

The first variable is used to flip the sign of the horizontal sync signal of the resonant controller. Effectively, what this does, is flip the two-photon image left-right. Normally this variable should be zero, but we have encountered some isolated cases where the controller has a sync signal of the opposite sign. In such cases, set the variable to 1 and it will restore the orientation of the image to its normal setting.

The second variable, gain_override, allows you to change the default gain settings for the resonant and galvanometer mirrors. If the variable is zero, Scanbox will use its default settings.  If it is one, it will use the ones defined by the user in the gain_resonant and gain_galvo variables.

These factors are such that for a value of 1.0 one gets the maximum possible deflection of each of the mirrors. Values larger than one will decrease the optical amplitude of the mirrors and therefore increase the magnification.

In the example above, we are maximizing the deflection of the galvanometer at x1.  At x2, the factor is 2.0 (half of the max amplitude), and for x4 it is 4 (one-fourth of the max amplitude).  The gains for the resonant are chosen so that in our setup the pixels are approximately square, but you can work with non-square pixels if you so desire.

To adjust the values of these variables you need to measure the aspect ratio of your pixels.  One simple way to do this is to image a sample using “accumulate” mode, zero the position, and move the sample by some Δx and Δy.  By measuring the displacement of the image and normalizing by the actual movement performed (as it appears in the position counters) one can obtain the size of the pixels in um.

The variables in the config file are read only at startup.  However, to adjust the gains without restarting Scanbox to accept a new setting you can force a change from the command window as follows:

global sbconfig;
sbconfig.gain_resonant(1) = 1.5;

The above will modify the gain of the resonant mirror at x1 and you can image again right after forcing the change without restarting Scanbox. Once the microscope is stopped, you can change the same or other variables (always followed by sb_update_gains) to continue adjusting your values (of course, there is no need to define the global variable every time).

Once you have obtained the pixel size you want at each magnification, update the config file variables gain_resonant and gain_galvo to your values so that future sessions of Scanbox will automatically use them.

With the default settings you should now obtain a field of view of roughly 1.2 x 0.76 mm at x1 with 512 lines and 31 Hz in bidirectional scanning mode.  You can increase further to 1.2 x 1.5 mm at x1 with 1024 lines at 15.5 Hz in bidirectional mode.

Changes in the gain will likely require further adjustments of the line folding in bi-directional scanning, which is achieved by changing the ncolbi variable.