mla

class mla_api.MLA(settings, calibrations_folder=None, eh=None)

This is the main class for accessing the MLA API. It holds instances of the classes lockin.Lockin, osc.Osc, arb.ARB, feedback.Feedback and hardware.Hardware, which are in turn used for different aspects of setting up and reading data from the MLA. When the MLA class is instanciated, not much happens. Ethernet connection is established in the member function mla_api.MLA.connect() and the MLA is configured and the child objects are created.

Parameters:
  • settings – a configobj object containing various settings. A settings object can be created by the module impconfig.py. For further information, look at impconfig.py and mla_config_spec.ini.
  • calibrations_folder – path to a folder on the local PC where calibrations are stored. If None the temp folder of the operating system will be used. (The calibration is stored in the MLA and coped over to the PC everytime mla_api.MLA.connect() is executed.)
  • eh – An eventhandler object that can be used to notify various parts in the software about changes that occur in other parts of the softare. For more information, look at eventhandler.py.
connect(block=True, server_text_callback=None, print_callback=None, ip_address=None)

Setup an ethernet connection between the PC and the MLA and configure the MLA.

Parameters:
  • block – True or False. Weather to block further program execution while the connect function executes. If False, make sure to run mla.connect_thr.join() before any access to the MLA is made.
  • server_text_callback – A function taking a string as argument to handle text messages coming from the MLA firmware. If None, python’s print() function will be used.
  • print_callback – A function taking a string argument and optionally an append_new_line keyword argument to handle messages text messages from the MLA API. If None, python’s print() function will be used.
  • ip_address – [string or None] The IP address for the MLA to connect to. If None, the first IP address in the list self.settings[‘COMMUNICATION’][‘mla_ip’] will be used.
Returns :
None
disconnect()

Disconnect the ethernet connection to the MLA. This should be done before the python program exits.

Parameters:None
Returns:None
reset(event=True, wait_for_effect=True)

Convenience function to set all the user-configurable settings to a known initial state.

Parameters:
  • event (bool, optional) – make the eventhandler trigger the EVT_AMPLITUDES_UPDATED event.
  • wait_for_effect (bool, optional) – block the execution until a data packet has arrived where the new setting has had effect. This option only has effect of the lockin is streaming, see lockin.start_lockin() and lockin.wait_for_settings_effect().
run_calibration_sequence(base_calibration='')

Start a text based calibration wizard for input and output voltages.

Parameters:base_calibration – Path to calibration file, dictionary with calibration values, or None. The calibration values specified by this paramter will be used when the user skips a calibration step. If ‘’ the calibration factors from calspec.ini will be used.
Returns:None

mla.lockin

class lockin.Lockin(hardware)

This class handles communication with and control of the MLA. Most functions set parameters of the measurement and readout data from the MLA.

Many functions has a keyword argument called unit. The defualt is unit='calibrated which will use the current calibration, for more information, see Calibration. Instead unit='digital' can be selected to communicate with the digital components in their native units. In some functions, other units such as ‘percent’, ‘rad’ and ‘degree’ are also possible.

There are three different methods to wait for new data. While they can be configured to do the same thing, they are different in their implementation:

abort_parameter_sweep()

Abort a hardware-automated parameter sweep, such as a frequency sweep.

Parameters:None
Returns:None

Examples

>>> mla.lockin.frequency_sweep(100e3, 200e3, 100)
>>> time.sleep(1)
>>> mla.lockin.abort_parameter_sweep()
abort_wait_for_counter()

Aborts the command lockin.Lockin.wait_for_counter() which blocks execution. This abort command must be called from another thread.

Returns:None

Examples

>>> from threading import Timer
>>> mla.lockin.set_df(10)
>>> mla.lockin.start_lockin()
>>> Timer(1, mla.lockin.abort_wait_for_counter).start()
>>> mla.lockin.wait_for_counter('trig1',  increment=1)
-1
>>> mla.lockin.stop_lockin()
abort_wait_for_new_pixels()

Aborts the command lockin.Lockin.wait_for_new_pixels() which blocks execution. This abort command must be called from another thread.

Returns:None

Examples

>>> from threading import Timer
>>> mla.lockin.set_Tm(0.1)
>>> mla.lockin.start_lockin()
>>> Timer(1, mla.lockin.abort_wait_for_new_pixels).start()
>>> mla.lockin.wait_for_new_pixels(100)
>>> mla.lockin.stop_lockin()
abort_wait_for_trigger()

Aborts the command lockin.Lockin.wait_for_trigger() by sending a fake trigger. Since lockin.Lockin.wait_for_trigger() blocks execution, this abort command must be called from another thread. When aborted, the buffer position returned by lockin.Lockin.wait_for_trigger() will be -1.

Returns:None

Examples

>>> from threading import Timer
>>> mla.lockin.set_trigger_flanks(trig1_flank='positive', trig2_flank='positive')
>>> mla.lockin.enable_wait_for_trigger(True)
>>> mla.lockin.start_lockin()
>>> Timer(1, mla.lockin.abort_wait_for_trigger).start()
>>> mla.lockin.wait_for_trigger() 
-1
>>> mla.lockin.stop_lockin()
>>> mla.lockin.flush_trigger_queue()
arm_trigger(dma_channel=1, cluster_size='auto')

Arm the lockin trigger so that next time a trigger event occurs on port TRIG IN 1, all waveform and lockin calculations are reset and restared.

Parameters:
  • dma_channel – 0 or 1
  • cluster_size – passed on to start_lockin
Returns:

None

Examples

>>> mla.lockin.set_df(10)
>>> mla.lockin.arm_trigger()
>>> time.sleep(2)
>>> mla.lockin.stop_lockin()

Note

Run this command instead of mla.lockin.start_lockin() to start a triggered measurement.

blank_output(do_blank, wait_for_effect=True)

Turn on or off all output.

Parameters:
  • do_blank – boolean, True turns off the output, False turns it on.
  • wait_for_effect – boolean, when True, blocks excecution until a new data packet arrives. Effects only lockin streaming.
Returns:

None

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.blank_output(True)
>>> mla.lockin.get_pixels(n_pix=1, data_format='IQreal', unit='digital')[0] 
array([  2.889704633-05,  -1.908409882-05,  ..., -1.24725527e-05])
>>> mla.lockin.blank_output(False)
>>> mla.lockin.get_pixels(n_pix=1, data_format='IQreal', unit='digital')[0] 
array([  2.20439491e+02,  -1.00917580e+02,  ..., -1.47609380e+02])
>>> mla.lockin.stop_lockin()
enable_pixel_clock(enable=True)

When the pixel clock is enabled a trigger pulse will be sent to TRIG OUT 1 at the start of the each lockin measurement time window.

Parameters:enable – True or False
Returns:None

Note

Each trigger is 50 clock cycles long, which normally corresponds to 1 microsecond

enable_wait_for_trigger(state)

Enables lockin.Lockin.wait_for_trigger() function.

Parameters:
Returns:

None

Warning

If the data is never read using lockin.Lockin.wait_for_trigger() or lockin.Lockin.flush_trigger_queue() the queue will eventually become over-full and the software will crash.

Details:
This function makes the ethernet packet receiver, pipe the buffer position of every packet where the trigger counter incremented.

Examples

>>> from threading import Timer
>>> mla.lockin.set_trigger_flanks(trig1_flank='positive', trig2_flank='positive')
>>> mla.lockin.enable_wait_for_trigger(True)
>>> mla.lockin.start_lockin()
>>> Timer(1, mla.lockin.abort_wait_for_trigger).start()
>>> mla.lockin.wait_for_trigger() 
187
>>> mla.lockin.stop_lockin()
extract_dc(meta, port=None, units='calibrated')

Extract DC values from pixel metadata.

Parameters:
  • meta – meta data object from, for example mla.lockin.get_pixels
  • port – integer, input port number (1–4) or None for all ports
  • units – string, ‘calibrated’ or ‘native’
flush_trigger_queue()

Read out and discard all values in the trigger queue (i.e. buffer positions of packets with incremented trigger count).

Returns:None

Examples

>>> from threading import Timer
>>> mla.lockin.set_trigger_flanks(trig1_flank='positive', trig2_flank='positive')
>>> mla.lockin.enable_wait_for_trigger(True)
>>> mla.lockin.start_lockin()
>>> Timer(1, mla.lockin.abort_wait_for_trigger).start()
>>> mla.lockin.wait_for_trigger() 
-1
>>> mla.lockin.stop_lockin()
>>> mla.lockin.flush_trigger_queue()
frequency_sweep(f1, f2, df_in=1000, pts=1001, pixels_per_step=5)

Start a frequecy sweep using one single lockin.

Parameters:
  • f1 – float [Hertz], start frequency of the sweep.
  • f2 – float [Hertz], stop frequency of the sweep.
  • df_in – float [Hertz], requested measurement bandwidth.
  • pts – integer, number of steps in the sweep.
  • pixels_per_step – integer, number of measurements performed at each step.
Returns:

None

Details:
This function uses hardware-enabled functionality for a performing a fast parameter sweep without having to realy on communication between the computer and the MLA between each step in the sweep. This function only starts the sweep. Use lockin.Lockin.get_frequency_sweep() to read out the results. The sweep is not continuous but in discret steps, taken so as to avoid Fourier leakage (i.e. the lock-in measurement on an an integer number of periods). Due to this tuning at each step, the measurement bandwidth and the frequency steps are not exactly uniform, but sufficiently close for most applications. In high-Q systems it takes longer time to achieve stedady-state oscillation after a step. Use pixels_per_step to slow down the sweep and avoid transients. Only the last pixel will be used at each frequency step. The settling time before measurement is then (pixels_per_step - 1)/df.
frequency_sweep_multifreq(f1, f2, df_in=1000, pts=1001, pixels_per_step=5)

Start a frequecy sweep using all available lockins simultaneousely.

Parameters:
  • f1 – float [Hertz], start frequency of the sweep.
  • f2 – float [Hertz], stop frequency of the sweep.
  • df_in – float [Hertz], requested measurement bandwidth.
  • pts – integer, number of steps in the sweep.
  • pixels_per_step – integer, number of measurements performed at each step.
Returns:

None

Details:
Similar to lockin.Lockin.frequency_sweep(), but uses all available lockins in parallel. With multifrequency a sweep can be performed much faster but it will only give the same result as a single-freqeuncy sweep if the system is linear. A nonlinear system will intermodulate the tones of a multifrequency drive.
get_Tm()
Parameters:None
Returns:measurement time window or inverse of measurement bandwidth , Tm=1/df.
Return type:float [Seconds]

Examples

>>> mla.lockin.set_df(500)
>>> mla.lockin.get_Tm()
0.002
get_Tm_max()
Parameters:None
Returns:longest possible measurement time window.
Return type:float [Seconds]
get_Tm_min()
Parameters:None
Returns:shortest possible measurement time window.
Return type:float [Seconds]
get_amplitudes(unit='calibrated')

Return the output amplitudes.

Parameters:unit – {‘calibrated’, ‘digital’, ‘percent’ , ‘%’} unit of given amplitudes.
Returns:output amplitudes
Return type:np.array(dtype=float)
get_counter(counter='trig1', bufpos=None)

Return the value of the specified counter at the specified position in the lockin data buffer.

Parameters:
  • counter

    interger or string, must be one of the following:

    1 = ‘settings’: The settings counter increments every time a parameter is
    changed. This counter can be used to identify which data had which parameters. Note that the frequency and phase parameters will increment the settings counter by 2 when they are changed.
    2 = ‘trig2’ = ‘image_nr’ : The trig2 counter counts the number of trigger
    events recieved at port TRIG IN 2 (image trigger for SPM).
    3 = ‘trig1’ = ‘line_nr’: The trig1 counter counts the number of trigger
    events recived at in TRIG IN 1 (line trigger for SPM).
    4 = ‘pixel’: The pixel counter counts the total number of time measurement windows
    that has passed since the MLA was powered on. NOTE: this counter will continue to increase regardless of weather the data was transmitted to the computer or not.
  • bufpos – integer or None, the buffer position where to read the value. If bufpos is left at None the last value will be used.
Returns:

The value of the counter

Return type:

integer

Examples

>>> mla.lockin.set_Tm(0.1)
>>> mla.lockin.start_lockin()
>>> mla.lockin.get_counter('pixel') 
24
>>> mla.lockin.wait_for_counter('pixel', increment=5) 
29
>>> mla.lockin.get_counter('pixel') 
29
get_da_max()
Parameters:None
Returns:The highest possible output amplitude in native lockin units.
Return type:float

Note

Even though the DA converter has 16 bits the resolution of lockin drive amplitudes is significantly higher. This is necessary to allow one drive tone to fill upp the entire DA range, and, at the same time, allow multiple tones of very low amplitude to still yeald a low voltage even when interfering constructively.

get_da_min()
Parameters:None
Returns:The lowest (most negative) possible output amplitude in native lockin units.
Return type:float

Note

Even though the DA converter has 16 bits the resolution of lockin drive amplitudes is significantly higher. This is necessary to allow one drive tone to fill upp the entire DA range, and, at the same time, allow multiple tones of very low amplitude to yeild a low voltage even when interfering constructively.

get_df()
Parameters:None
Returns:measurement bandwidth in Hertz, or inverse of measurement time window, df=1/Tm.
Return type:float [Hertz]

Examples

>>> mla.lockin.set_Tm(0.001)
>>> mla.lockin.get_df()
1000.0
get_df_max()
Parameters:None
Returns:The largest possible measurement bandwidth.
Return type:float [Hertz]
get_df_min()
Parameters:None
Returns:The smallest possible measurement bandwidth.
Return type:float [Hertz]
get_frequencies()
Returns:frequencies of all tones in Hertz.
Return type:np.array(dtype=float) [Hertz]

Examples

>>> mla.lockin.set_frequencies(100e3)
>>> mla.lockin.get_frequencies()
array([ 100000.00002037,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ])
>>> mla.lockin.set_frequencies(100e3+np.arange(mla.lockin.nr_input_freq)*1e3)
>>> mla.lockin.get_frequencies()
array([ 100000.00002037,  100999.99999511,  102000.00001532,
        102999.99999006,  104000.00001027,  104999.99998501,
        106000.00000522,  106999.99997996,  108000.00000017,
        109000.00002039,  109999.99999513,  111000.00001534,
        111999.99999008,  113000.00001029,  113999.99998503,
        115000.00000524,  115999.99997998,  117000.00000019,
        118000.0000204 ,  118999.99999514,  120000.00001535,
        120999.99999009,  122000.0000103 ,  122999.99998504,
        124000.00000525,  124999.99997999,  126000.0000002 ,
        127000.00002042,  127999.99999515,  129000.00001537,
        129999.9999901 ,  131000.00001032,  131999.99998506,
        133000.00000527,  133999.99998001,  135000.00000022,
        136000.00002043,  136999.99999517,  138000.00001538,
        138999.99999012,  140000.00001033,  140999.99998507])
>>> mla.lockin.set_frequencies(300e3+np.arange(10)*1e3, idx=range(10))
>>> mla.lockin.get_frequencies()
array([ 300000.00001564,  300999.99999038,  302000.00001059,
        302999.99998533,  304000.00000554,  304999.99998028,
        306000.00000049,  307000.00002071,  307999.99999545,
        309000.00001566,  109999.99999513,  111000.00001534,
        111999.99999008,  113000.00001029,  113999.99998503,
        115000.00000524,  115999.99997998,  117000.00000019,
        118000.0000204 ,  118999.99999514,  120000.00001535,
        120999.99999009,  122000.0000103 ,  122999.99998504,
        124000.00000525,  124999.99997999,  126000.0000002 ,
        127000.00002042,  127999.99999515,  129000.00001537,
        129999.9999901 ,  131000.00001032,  131999.99998506,
        133000.00000527,  133999.99998001,  135000.00000022,
        136000.00002043,  136999.99999517,  138000.00001538,
        138999.99999012,  140000.00001033,  140999.99998507])
get_frequency_sweep(unit='calibrated')

Extract the results of a frequency sweep started by lockin.Lockin.frequency_sweep(). If executed before sweep is finished, will return partial sweep.

Parameters:unit – ‘calibrated’ or ‘digital’
Returns:(f, a, n)
  • f : np.array(dtype=float) [Hertz] frequencies of sweep.
  • a : np.array(dtype=float) [ADU] quadrature amplitudes.
  • n : integer, length of the f and a arrays.
Return type:Tupel
get_frequency_sweep_multifreq(unit='calibrated')

Extract the reults of a frequency sweep started by lockin.Lockin.frequency_sweep_multifreq(). If executed before sweep is finished, will return partial sweep.

Parameters:unit – {‘calibrated’, ‘digital’}
Returns:(f, a, n)
  • f : np.array(dtype=float) [Hertz] frequencies of sweep.
  • a : np.array(dtype=complex) [unit] quadrature amplitudes.
  • n : integer, length of the f and a arrays.
Return type:Tuple
get_fsample()
Parameters:None
Returns:The sampling frequency in Hertz.
Return type:float [Hertz]

Note

The lockin unit is clocked by the AD-converter clock. In almost all cases the DA clock should be set to have the same frequency.

See also

hardware.Hardware.set_adc_clock_divisor()

get_input_multiplexer()

Returns which input port is connected to which demodulator

Parameters:None
Returns:list of integers with port numbers 1-4.
Return type:port_array
get_line(line_length_if_first_trig=1, data_format='complex', unit='calibrated', get_meta=False)

Return all the lockin packets between two successive trigger events on port TRIG IN 1.

Parameters:
  • line_length_if_first_trig – If there is only one trigger event in the lockin data buffer, this parameter specifies how many pixels to return.
  • data_format – {‘IQreal’, ‘complex’, ‘amp’, ‘phase’} specifies return data type.
  • unit – {‘calibrated’, ‘digital’, ‘deg, ‘rad’} specifies units. ‘rad’ and ‘deg’ only for phase.
Returns:

Numpy array of pixel data as specified by the data_format and unit parameters.

Note

Other trigger methods are possile with firmware modificaitons. Please contact Intermodulation Products if you need different trigger methods.

Examples

>>> mla.lockin.set_Tm(0.1) 
>>> mla.lockin.start_lockin() 
>>> mla.lockin.wait_for_trigger() 
>>> mla.lockin.wait_for_trigger() 
>>> mla.lockin.get_line() 
get_new_pixels(throw_away=False, wait_for_new=True, rawdata=False)

Return all new lockin packets from the buffer.

Parameters:
  • throw_away – boolean (default=False) when True, all previous data will be discarded
  • wait_for_new – boolean (default=True) when True, will block program excutation until at least one new data packet arrives.
  • rawdata – Boolean (default=False) when True, returns raw Fourier sums, not devied by the number of samples and not phase corrected.
Returns:

(pixels, nr_pixels, meta)

  • pixels : two dim. np.array(dtype=float) [ADU]
    axis 0: [I_0, Q_0, I_1, Q_1, I_2, Q_2, …] axis 1: [pixel_0, pixel_1, pixel_2, …]
  • nr_pixels : integer, number of pixels returned (i.e. length of axis 0)
  • meta : two dim. np.array(dtype=uint32)
    axis 0: [header, settings_counter, trig1 counter, trig2 counter, pixel counter, trigger position, dc_data] axis 1: [pixel_0, pixel_1, pixel_2, …]

Return type:

Tuple

Usage:
Keeps track of which data has been extracted from the buffer. This function only returns NEW data that was not previously extraced. Usually issued in a loop together with plotting and other data processing commands.
get_phases(unit='rad')

Return the output phases. :param unit: ‘rad’ or ‘degree’

Returns:output phases
Return type:np.array(dtype=float)

Examples

>>> mla.lockin.set_phases([np.pi/6]*np.arange(13))
>>> mla.lockin.get_phases('degree')[:13] 
array([ 0., 30., 60., 90., 120., 150., 180., 210., 240., 270., 300., 330., 360.])
>>> mla.lockin.set_phases(30*np.arange(13), 'degree')
>>> mla.lockin.get_phases('rad')[:13] 
array([ 0.        ,  0.52359878,  1.04719755,  1.57079633,  2.0943951 ,
2.61799388,  3.14159265,  3.66519143,  4.1887902 ,  4.71238898,
5.23598776,  5.75958653,  6.28318531])
get_pixel_average(n_pix, data_format='complex', unit='calibrated', first_bufpos=None)

Extract a pixel as an average of n measured pixels

Parameters:
  • n_pix – integer number of measurement points to extract. Set to None to extract all pixels from the first_bufpos to the end.
  • data_format – {‘IQreal’, ‘complex’, ‘amp’, ‘phase’} specifies return data type.
  • unit – {‘calibrated’, ‘digital’, ‘deg, ‘rad’} specifies units. ‘rad’ and ‘deg’ only for phase.
  • first_bufpos – Specify the first buffer position to extract data from. This can be useful when extracting data with respect to a trigger position. Leave at None to extract the n_pix last pixels.
Returns:

(pixels, meta)

  • pixels : np.array(dtype=np.float) of pixels of the specified data_format and unit.
  • meta : two dim. np.array(dtype=np.uint32)
    axis 0: [header, settings_counter, trig1 counter, trig2 counter, pixel counter, trigger position, dc_data] axis 1: [pixel 1, pixel 2, pixel 3, …]

Return type:

Tuple

Examples

>>> mla.lockin.set_df(10)
>>> mla.lockin.start_lockin()
>>> mla.lockin.wait_for_new_pixels(10)
>>> pixels, meta = mla.lockin.get_pixel_average(10)
>>> pixels.shape
(42L, 1L)
>>> meta.shape
(12L, 10L)
>>> mla.lockin.stop_lockin()
get_pixels(n_pix=None, data_format='complex', unit='calibrated', first_bufpos=None)

Extract pixels from the lockin data buffer.

Parameters:
  • n_pix – integer, number of pixels to extract. Set to None to extract all pixels from the first_bufpos to the end.
  • data_format – {‘IQreal’, ‘complex’, ‘amp’, ‘phase’} specifies return data type.
  • unit – {‘calibrated’, ‘digital’, ‘deg, ‘rad’} specifies units. ‘rad’ and ‘deg’ only for phase.
  • first_bufpos – The first buffer position to extract data from. This can be useful when extracting data with respect to a trigger position. Leave at None to extract the n_pix last pixels.
Returns:

(pixels, meta)

  • pixels : np.array(dtype=float) 2D array of pixel data in specified data_format and unit.

    axis 0: [tone_0 data, tone_1 data, tone_2 data…] axis 1: [pixel_0, pixel_1, pixel_2, …]

  • meta : np.array(dtype=uint32)

    axis 0: [header, settings_counter, trig1 counter, trig2 counter, pixel counter, trigger position, dc_data] axis 1: [pixel_0, pixel_1, pixel_2, …]

Return type:

Tuple

Examples

>>> mla.lockin.set_df(10)
>>> mla.lockin.start_lockin()
>>> mla.lockin.wait_for_new_pixels(10)
>>> pixels, meta = mla.lockin.get_pixels(10)
>>> pixels.shape
(42L, 10L)
>>> meta.shape
(12L, 10L)
>>> mla.lockin.stop_lockin()
get_pixels_between_bufpos(first_bufpos, last_bufpos, data_format='complex', unit='calibrated')

Extract pixels from the lockin data buffer between two given buffer positions.

Parameters:
  • first_bufpos – integer, a position in the pixel buffer corresponding to the ealiest data to extract
  • last_bufpos – integer, a position in the pixel buffer corresponding to a later position. Data upto, but not including, this position is extracted.
  • data_format – {‘IQreal’, ‘complex’, ‘amp’, ‘phase’} specifies return data type.
  • unit – {‘calibrated’, ‘digital’, ‘deg, ‘rad’} specifies units. ‘rad’ and ‘deg’ only for phase.
Returns:

(pixels, meta)

  • pixels : np.array(dtype=float) 2D array of pixel data in specified data_format and unit.

    axis 0: [tone_0 data, tone_1 data, tone_2 data…] axis 1: [pixel_0, pixel_1, pixel_2, …]

  • meta : np.array(dtype=uint32)

    axis 0: [header, settings_counter, trig1 counter, trig2 counter, pixel counter, trigger position, dc_data] axis 1: [pixel_0, pixel_1, pixel_2, …]

Return type:

Tuple

Examples

>>> mla.lockin.set_df(10)
>>> mla.lockin.start_lockin()
>>> first_bufpos = 0
>>> last_bufpos = 10
>>> pixels, meta = mla.lockin.get_pixels(first_bufpos, last_bufpos)
>>> pixels.shape
(42L, 10L)
>>> meta.shape
(12L, 10L)
>>> mla.lockin.stop_lockin()
get_port(tone_index)
Parameters:tone_index – [integer] index of the measured tone.
Returns:port number where tone is measured.
Return type:integer
get_samples_per_pixel()
Parameters:None
Returns:ns = the number of samples in measurement time window.
Return type:integer

The number of samples per pixel (ns) is the fundamental hardware unit for the measurement time window (Tm), or measurement bandwidth (df=1/Tm). With sampling frequency fs, ns = fs*Tm = fs/df

Examples

>>> mla.lockin.set_Tm(0.001)
>>> mla.lockin.get_samples_per_pixel()
50000
get_samples_per_pixel_max()
Parameters:None
Returns:largest allowed samples_per_pixel.
Return type:int
get_samples_per_pixel_min()
Parameters:None
Returns:smallest allowed samples_per_pixel.
Return type:int
get_tone(tone_index=0, n_points=None, data_format='complex', unit='calibrated', first_bufpos=None)

Extract n_points of lockin measurement data of a single tone. The last item in the returned list will be the last data point that has arrived to the computer.

Parameters:
  • n_points – integer number of measurement points to extract
  • tone_index – integer, index of the tone to extract (use tone_index=0 for the first tone)
  • data_format – {‘IQreal’, ‘complex’, ‘I’, ‘Q’, ‘amp’, ‘phase’} specifies return data type.
  • unit – {‘calibrated’, ‘digital’, ‘deg, ‘rad’} specifies units. ‘rad’ and ‘deg’ only for phase.
Returns:

Array of n lockin measurement data points of the specified unit and data_format.

Return type:

np.array

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.set_df(100)
>>> mla.lockin.set_amplitudes([2]*mla.lockin.nr_output_freq, unit='%')
>>> mla.lockin.set_phases(0)
>>> mla.lockin.set_frequencies(100e3 + np.arange(mla.lockin.nr_input_freq)*1e3)
>>> mla.lockin.get_tone(n_points=3,  tone_index=0, data_format='complex', unit='calibrated') 
array([ 0.00868193-0.00263251j,  0.00868193-0.00263251j,
        0.00868193-0.00263251j])
>>> mla.lockin.get_tone(n_points=3,  tone_index=0, data_format='amp', unit='calibrated') 
array([ 0.00907227,  0.00907227,  0.00907227])
>>> mla.lockin.get_tone(n_points=3,  tone_index=0, data_format='phase', unit='deg') 
array([-16.86823347, -16.86823347, -16.86823347])
>>> mla.lockin.get_tone(n_points=3,  tone_index=0, data_format='phase', unit='rad') 
array([-0.29440621, -0.29440621, -0.29440621])
>>> mla.lockin.get_tone(n_points=3,  tone_index=0, data_format='IQreal', unit='digital') 
array([ 284.48073199,  -86.25959969,  284.48073199,  -86.25959969,
        284.48073199,  -86.25959969])
>>> mla.lockin.stop_lockin()
is_started()

Check if MLA is sending lockin data to the computer.

Parameters:None
Returns:boolean

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.is_started()
True
>>> mla.lockin.stop_lockin()
>>> mla.lockin.is_started()
False
line_up_phases(tones, value)

Calibrate phase measurements at specified tones to a particular value.

Parameters:
  • tones – np.array(dtype=int) indices of tones to be lined up.
  • value – float [radians] phase that MLA measures after line-up.
Returns:

None

Usage:
The lockin measurement of phase is affected by several frequency dependent things, for example digital delays, analog anti-alias filters, cables, the experimental setup etc. This function should be run after the frequencies and amplitudes have been set up. The input and output ports must also be connected, typically through the experiment. After this function has been executed, the phase is set to value. Future phase measurements reflect deviation from value.

Examples

>>> mla.lockin.set_frequencies(np.arange(mla.lockin.nr_input_freq)*100e3)
>>> mla.lockin.set_amplitudes([0.01]*mla.lockin.nr_input_freq)
load_from_file(path)

Load the lockin setup from file.

Parameters:path – [String], full path to the file from which the lockin setup should be loaded.
Returns:None
logger_start(filename, starttime=None, flush_interval=1)

Start logging lockin data to file.

Parameters:
  • filename – path to the log file
  • starttime – None or datetime (as returned by eg. datetime.datetime.now()). Time to write out as the Start time: in the log file header. If None, the local time of the computer will be used.
  • flush_interval – float [seconds] How often should the log file be written to disk.
Returns:

None

Examples

>>> mla.lockin.set_df(10)
>>> mla.lockin.locker_start('testfila.txt')
>>> mla.lockin.start_lockin()
>>> time.sleep(2)
>>> mla.lockin.logger_stop()
>>> mla.lockin.stop_lockin()
logger_stop(stop_time=None)

Stop logging lockin data to file.

Parameters:stop_time – None or datetime (as returned by eg. datetime.datetime.now()). Time to write out as the Stop time: at the end of the file. If None, the local time of the computer will be used.
Returns:None

Examples

>>> mla.lockin.set_df(10)
>>> mla.lockin.locker_start('testfila.txt')
>>> mla.lockin.start_lockin()
>>> time.sleep(2)
>>> mla.lockin.logger_stop()
>>> mla.lockin.stop_lockin()
measure_packet_rate(measurement_time=1)

Measure the rate at which lockin packets are arriving to the computer.

Parameters:measurement_time – float (seconds)
Returns:float [number of packets per second]

Note

This functions is used mostly for debugging and testing.

reset_outputs(event=True, wait_for_effect=True)

Set all output masks, amplitudes and dc offsets to zero.

Parameters:
  • event – True or False (default=True). Make the eventhandler trigger the EVT_AMPLITUDES_UPDATED event.
  • wait_for_effect – True or False (default=True). Block the execution until a data packet has arrived where the new setting has had effect. This option only has effect of the lockin is streaming, see start_lockin() and wait_for_settings_effect().
reset_tones_on_new_pixel(reset=True)

Turn on or off the phase reset at the start of each measurement time window.

Parameters:reset – [boolean] False turns off the phase reset.
Returns:None
Usage:
Corrects for slow phase drift of lockin measuremnet of intermodulaiton products when tuning is not perfect. The reset is typically turned off only when you want to generate a tone with a very exact frequency (very stable phase) and you are not interested in measuring intermodulation products.
reset_tones_on_trig1(reset=True)

Turn on or off the phase reset when a tigger event on port TRIG IN 1.

Parameters:reset – [boolean, defalut=True] Flase turns off the phase reset
Returns:None
save_to_file(path)

Save the lockin setup to a file.

Parameters:path – [string} The full path of the file to be saved
Returns:None
send_trigger()

Sends a single trigger event to the port TRIG OUT 1

Parameters:None
Returns:None

Examples

>>> mla.lockin.send_trigger()

Note: The TRIG OUT 1 will go high for 100-1000 us and then become low.

set_Tm(Tm, wait_for_effect=True)
Parameters:
  • Tm – float [seconds] measurement time window
  • wait_for_effect – bolean (default=True) when true, blocks execution until recieved lockin data reflects the action of this command.
Returns:

None

Examples

>>> mla.lockin.set_Tm(0.001)
>>> mla.lockin.get_Tm()
0.001
set_amplitudes(amplitudes, unit='calibrated', idx='all', port=None, event=True, wait_for_effect=True)

Sets the amplidues of the output tones. If the amplitudes are complex, the np.angle() function is used to set the phase. If amplitudes are pure real, the phases will be unchanged.

Parameters:
  • amplitudes – float, array_like, real or complex.
  • unit – {‘calibrated’, ‘digital’, ‘percent’ , ‘%’} unit of given amplitudes.
  • idx – array_like or ‘all’. Specifices indicies of tones for which amplitudes should be set. If ‘all’ is given, and the number of tones is larger than the length of the list, the amplitudes of the remaining tones are set to 0.
  • port – array_like or None. Specifies a port for calibration V to ADU. If None, the port calibration is determined from the output_mask. If both ports are specified in the output_mask, the first port is used. This parameter does not change the output_mask.
  • event – True or False (default=True). Make the eventhandler trigger the EVT_AMPLITUDES_UPDATED event.
  • wait_for_effect – True or False (default=True). Block the execution until a data packet has arrived where the new setting has had effect. This option only has effect of the lockin is streaming, see start_lockin() and wait_for_settings_effect().
Returns:

None

Examples

>>> mla.lockin.set_amplitudes(1) # Sets the first amplitude to 1V and the rest to 0%
>>> mla.lockin.set_amplitudes([2.5]*10, unit='%', idx=range(10)) # Set the first 10 amplitudes to 2.5%, leave the rest unchanged
set_dc_offset(port, value, unit='calibrated')

Apply a DC offset to the generated output waveforms.

Parameters:
  • port – 1 or 2, specifies output port to which dc offset is applied.
  • value – float, value to ouput.
  • unit – ‘calibrated’ or ‘digital’ (-32768 to 32767).
Returns:

None

Warning

No check is made weather the sum of all waveforms and the DC offset lies within the valid range. The waveform will wrap from max (min) to zero if value is out of range.

Examples

>>> mla.lockin.set_dc_offset(1, 0.7)
set_df(df, event=True, wait_for_effect=True)
Parameters:
  • df – [Hz] measurement bandwidth, inverse of measurement time window df=1/Tm
  • wait_for_effect – bolean (default=True) when true, blocks execution until recieved lockin data reflects the action of this command.
Returns:

None

Examples

>>> mla.lockin.set_df(1000.)
>>> mla.lockin.get_df()
1000.0
set_digital_mask(mask)

Set a mask for outputting the last three frequencies as square waves on ports TRIG OUT 1, TRIG OUT 2 and TRIG OUT 3.

Parameters:mask – list or integer mask
Returns:None

Examples

# Turn on the last frequency to TRIG OUT 3 >>> mla.lockin.set_digital_mask([0, 0, 1])

# Turn on the second last frequency to TRIG OUT 2 >>> mla.lockin.set_digital_mask([0, 1, 0])

# Turn on the third last frequency to TRIG OUT 1 >>> mla.lockin.set_digital_mask([1, 0, 0])

# Turn on all three at the same time >>> mla.lockin.set_digital_mask([1, 1, 1])

# Turn off all digital waveforms >>> mla.lockin.set_digital_mask(0)

set_frequencies(f, unit='Hz', idx='all', event=True, wait_for_effect=True)
Parameters:
  • f – np.array(dtype=float) [Hertz] frequencies of all tones.
  • idx – array_like or ‘all’, indicies of chanels to set frequencies If ‘all’ is given and number of frequencies is higher than the length of idx, remaining amplitudes are set to 0.
  • event – boolean (default=True) when True the eventhandler triggers EVT_AMPLITUDES_UPDATED event.
  • wait_for_effect – bolean (default=True) when true, blocks execution until command has taken effect.
Returns:

None

Examples

>>> mla.lockin.set_frequencies(100e3)
>>> mla.lockin.get_frequencies()
array([ 100000.00002037,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ,
             0.        ,       0.        ,       0.        ])
>>> mla.lockin.set_frequencies(100e3+np.arange(mla.lockin.nr_input_freq)*1e3)
>>> mla.lockin.get_frequencies()
array([ 100000.00002037,  100999.99999511,  102000.00001532,
        102999.99999006,  104000.00001027,  104999.99998501,
        106000.00000522,  106999.99997996,  108000.00000017,
        109000.00002039,  109999.99999513,  111000.00001534,
        111999.99999008,  113000.00001029,  113999.99998503,
        115000.00000524,  115999.99997998,  117000.00000019,
        118000.0000204 ,  118999.99999514,  120000.00001535,
        120999.99999009,  122000.0000103 ,  122999.99998504,
        124000.00000525,  124999.99997999,  126000.0000002 ,
        127000.00002042,  127999.99999515,  129000.00001537,
        129999.9999901 ,  131000.00001032,  131999.99998506,
        133000.00000527,  133999.99998001,  135000.00000022,
        136000.00002043,  136999.99999517,  138000.00001538,
        138999.99999012,  140000.00001033,  140999.99998507])
>>> mla.lockin.set_frequencies(300e3+np.arange(10)*1e3, idx=range(10))
>>> mla.lockin.get_frequencies()
array([ 300000.00001564,  300999.99999038,  302000.00001059,
        302999.99998533,  304000.00000554,  304999.99998028,
        306000.00000049,  307000.00002071,  307999.99999545,
        309000.00001566,  109999.99999513,  111000.00001534,
        111999.99999008,  113000.00001029,  113999.99998503,
        115000.00000524,  115999.99997998,  117000.00000019,
        118000.0000204 ,  118999.99999514,  120000.00001535,
        120999.99999009,  122000.0000103 ,  122999.99998504,
        124000.00000525,  124999.99997999,  126000.0000002 ,
        127000.00002042,  127999.99999515,  129000.00001537,
        129999.9999901 ,  131000.00001032,  131999.99998506,
        133000.00000527,  133999.99998001,  135000.00000022,
        136000.00002043,  136999.99999517,  138000.00001538,
        138999.99999012,  140000.00001033,  140999.99998507])
set_frequencies_by_n_and_df(n, df, tune=False, wait_for_effect=True)

An alternative way to setup the frequencies of the tones with index i, such that f_i=n_i*df, where the measurement bandwidth df and the number of oscillations of each tone n_i, are given instead of the actual frequencies. This method ensures that that the tones are tuned, which is required to avoid Fourier leakage.

Parameters:
  • n – array of integers sepcifying the number of oscillations of each tone during the measurement time window Tm=1/df.
  • df – float [Hertz] desired measurement bandwidth.
  • tune – Boolean (default=False) True enforces perfect tuning, (i.e. forces the number of samples per pixel is integer power of two).
  • wait_for_effect – Boolean (default=True). True will halt execution until a data packet has arrived where the new setting has taken effect. This option only has effect if the lockin is streaming, see lockin.Lockin.start_lockin() and lockin.Lockin.wait_for_settings_effect().
Returns:

(samples_per_pixel, df_tuned, f_hz)

  • samples_per_pixel : integer, number of samples in the measurement time window, ns=fs*Tm.
  • df_tuned : float [Hertz], the tuned measurement bandwidth.
  • f_hz : list of floats [Hertz], the tuned frequencies.

Return type:

Tuple

set_input_multiplexer(port_array, event=True)

Program the multiplexer that controls which input port should be connected to which demodulator.

Parameters:
  • port_array – list of integers with port numbers 1-4. The length of the list should equal the number of input frequencies.
  • event – True or False. Make the eventhandler trigger the EVT_MASK_UPDATED event.
Returns:

None

Examples

>>> # Only use port 1
>>> mla.lockin.set_input_multiplexer([1]*mla.lockin.nr_input_freq)
>>> # Use ports 1 and 2 alternating
>>> mla.lockin.set_input_multiplexer([1, 2]*mla.lockin.nr_input_freq/2)

See also

lockin.Lockin.get_input_multiplexer() lockin.Lockin.set_output_mode_lockin() feedback.Feedback.set_input_multiplexer()

set_output_mask(mask, port=1, event=True, wait_for_effect=True)

Each of the two lockin output ports has a separate mask. Each bit in the mask determines weather the corresponing tone should be added to the output. The same tone can be output on port 1, port 2, or both.

Parameters:
  • mask – list of 0 or 1, Boolean array, or single integer mask.
  • port – 1 or 2
  • event – True or False. Make the eventhandler trigger the EVT_MASK_UPDATED event.
  • wait_for_effect – True or False. Block the execution until a data packet has arrived where the new setting has had effect. This option only has effect of the lockin is streaming, see start_lockin()
Returns:

None

Note

All frequencies will always have the same number of samples per pixel.

Examples

>>> mla.lockin.set_output_mask([1]*mla.lockin.nr_output_freq, port=1) # Output all tones on port 1
>>> #Generate three tones with 100 kHz, 200 kHz and 300 kHz. Output to port 1 with
>>> # amplitude 0.1 V and to port 2 with amplitude 0.5 V.
>>> mla.lockin.set_output_mask([0, 1, 0, 1, 0, 1], port=1)
>>> mla.lockin.set_output_mask([1, 0, 1, 0, 1, 0], port=2)
>>> mla.lockin.set_frequencies([100e3, 100e3, 200e3, 200e3, 300e3, 300e3])
>>> mla.lockin.set_amplitudes([0.1, 0.5, 0.1, 0.5, 0.1, 0.5])
>>> mla.lockin.set_output_mask(0xF, port=1) # output tone 0,1,2,3 to port 1
set_output_mode_lockin(two_channels=False)

Set the fpga output multiplexer to output data from the lockin waveform generators, as opposed to the arbitrary waveform generators.

Parameters:two_channels – [Boolean] True will use both output ports for lockin waveform output. False will use the second port for feedback
set_phases(p, unit='rad', idx='all', event=True, correct_phases=True, wait_for_effect=True)

Set the output phases.

Parameters:
  • p – float, array_like, the phases to be set
  • unit – ‘rad’ or ‘degree’
  • idx – array_like or ‘all’. Specifices which amplitudes should be set. If ‘all’ is given, and the number of frequencies are higher than the length of the list, the remaining amplitudes are set to 0.
  • event – True or False (default=True). Make the eventhandler trigger the EVT_AMPLITUDES_UPDATED event.
  • wait_for_effect – True or False (default=True). Block the execution until a data packet has arrived where the new setting has had effect. This option only has effect of the lockin is streaming, see start_lockin() and wait_for_settings_effect().
Returns:

None

Note

The same waveform is used to both generate and demodulate the signal. Therefore, changing the phase of a tone does not change the native measurement of the phase. However, this effect is compensated for in the PC backend.

Examples

>>> mla.lockin.set_phases(np.pi/4) # Sets the first phase to pi/4 radians and the rest to 0
>>> mla.lockin.set_phases(45, unit='degree') # Sets the first phase to 45 degrees and the rest to 0
>>> mla.lockin.set_phases([30]*10, unit='degree', idx=range(10)) # Set the first 10 phases to 30 degrees, leave the rest unchanged.
set_samples_per_pixel(n, event=True, wait_for_effect=True)

Set the number of samples used to integrate one lockin reading. The integration time will then be T = samples_per_pixel*sampling_frequency

Parameters:
  • n – integer. the number of samples
  • event – True or False. Make the eventhandler trigger the EVT_SAMPLES_PER_PIXEL_UPDATED event.
  • wait_for_effect – True or False. Block the execution until a data packet has arrived where the new setting has had effect. This option only has effect of the lockin is streaming, see start_lockin()
Returns:

None

Note

All frequencies will always have the same number of samples per pixel.

Examples

>>> mla.lockin.set_samples_per_pixel(50000)
>>> mla.lockin.get_df()
1000.0
set_trigger_flanks(trig1_flank='negative', trig2_flank='negative')

Warning: This function is deprecated. Use set_trigger_in_flank instead.

Sets trigger flank for hardware to react. For AFM, trig1 and trig2 are end-of-line (EOL) and end-of-frame (EOF) respectively.

Parameters:
  • trig1_flank – ‘positive’, ‘negative’ or ‘both’. Defalut is negative.
  • trig2_flank – ‘positive’, ‘negative’ or ‘both’. Defalut is negative.
Returns:

None

Examples

>>> mla.lockin.set_trigger_flanks(trig1_flank='positive', trig2_flank='positive')
>>> mla.lockin.set_trigger_flanks(trig1_flank='negtive', trig2_flank='both')
set_trigger_in_flank(trig_in_port, flank)

Sets which type of flank that should be considered a trigger.

Parameters:
  • trig_in_port – 1 or 2.
  • flank – ‘none’, ‘negative’, ‘positive’ or ‘both’

Examples

>>> mla.lockin.set_trigger_flanks(1, 'both')
>>> mla.lockin.set_trigger_flanks(2, 'positive')
set_trigger_in_holdoff(trig_in_port, hold_off_time_seconds)

Set a time after a trigger event during which new trigger events cannot be registered.

Parameters:
  • trig_in_port – 1 or 2
  • hold_off_time_seconds – float [seconds]

Note

This is useful to aviod false trigger events in noisy or bouncing signals.

start_lockin(dma_channel=1, trigger_mode=1, cluster_size='auto')

Tell the MLA to start streaming lockin data packets.

Parameters:
  • dma_channel – 0 or 1. In standard amplications time data use dma_channel=0 and lockin data use dma_channel=1
  • trigger_mode – 1 - start immediately or 2 - start on trigger event on trigger in 1.
  • cluster_size – integer > 0, or auto. Set how many pixels should be combined into a cluseter before it is transmitted.
Returns:

None

Note

The lockin calculations (and feedback) are always running. This function only activates the ethernet transmission. Normally, you don’t run this function with trigger_mode=2. Run lockin.Lockin.arm_trigger() instead.

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.stop_lockin()
stop_lockin(dma_channel=1, force=False)

Tell the MLA to stop streaming lockin data packets.

Parameters:
  • dma_channel – 0 or 1. In standard amplications time data use dma_channel=0 and lockin data use dma_channel=1
  • force – boolean. Force the stream to stop even if there are remaining lockin recievers.
Returns:

None

Note

The lockin calculations (and feedback) are always running. This function only deactivates the ethernet transmission.

Examples

>>> mla.lockin.stop_lockin()
tune0(f, df, native_output_units=False)

Performs only the minumum amount of tuning necessary to make the requested numbers fit the corresponding digtal registers in the MLA hardware.

Parameters:
  • f (float or np.ndarray) – target frequencies in Hz.
  • df (float) – target measurement bandwidth in Hz.
  • native_output_units (bool, optional) – return f and df in digital units rather than Hertz.
Returns:

The tuned frequencies in Hz. df_tuned (float): The tuned measurment bandwidth in Hz.

Return type:

f_tuned (float or np.ndarray)

Note

This tuning does not prevent Fourier leakage. This function is only to be used in rare cases where Fourier leakage is known not to be an issue. For example when measuring strong tones well separated in frequency. If you are using this function, you will probably want to also use mla.lockin.reset_tones_on_new_pixel(False) to avoid jumps in the signal at the end of each measurement time window.

Examples

>>> f_out, df_out = mla.lockin.tune0(123456.789, 1000)
>>> mla.lockin.reset_tones_on_new_pixel(False)
>>> mla.lockin.set_frequencies(f_out)
>>> mla.lockin.set_df(df_out)
tune1(f, df, priority='f', native_output_units=False, rounding=1, regular=False)

Performs standard level of tuning, adequate for most measurements.

Parameters:
  • f (float or np.ndarray) – target frequencies in Hz.
  • df (float) – target measurement bandwidth in Hz.
  • priority (str, optional) – tuning priority, see Usage.
  • native_output_units (bool, optional) – return f and df in digital units rather than Hertz.
  • rounding (int, optional) – if set to m > 1, it will ensure Fourier leakage is minimized also in case of using a downsampling of m
  • regular (bool, optional) – require that the number of samples per pixel is a regular number, see Notes.
Returns:

The tuned frequencies in Hz. df_tuned (float): The tuned measurment bandwidth in Hz.

Return type:

f_tuned (float or np.ndarray)

Usage:
The returned bandwidth and frequencies are tuned so that they fulfill the condition f_i = n_i*df which avoids Fourier leakage. With priority ‘f’ the highest priority is put on getting the frequencies as close as possible to the target frequencies. With priority ‘df’ the highest priority is put on getting the measurement bandwidth as close as possible to the target value. This tuning greatly supresses Fourier leakage, but does not completely prevent it. This function should be used with mla.lockin.reset_tones_on_new_pixel(True), which is the default state. When the reset function is activated, Fourier leakage will be immeasurable for any reasonalbe bandwidth.

Notes

If the lockin is used in parallel with a custom FFT calculation, setting regular=True ensures that the number of samples per pixel spp has only 2, 3 or 5 as prime factors (spp is 5-smooth, or a regular number). This can significantly speed up the FFT.

Examples

>>> f_out, df_out = mla.lockin.tune1(123456.789, 1000)
>>> mla.lockin.set_frequencies(f_out)
>>> mla.lockin.set_df(df_out)
tune2(f, df, priority='f', native_output_units=False)

Performs the most rigid tuning. With this tuning there will be zero Fourier leakage and very stable phase, but it is more limited in the possible values of the measurement bandwidth.

Parameters:
  • f (float or np.ndarray) – target frequencies in Hz.
  • df (float) – target measurement bandwidth in Hz.
  • priority (str, optional) – tuning priority, see Usage.
  • native_output_units (bool, optional) – return f and df in digital units rather than Hertz.
Returns:

The tuned frequencies in Hz. df_tuned (float): The tuned measurment bandwidth in Hz.

Return type:

f_tuned (float or np.ndarray)

Usage:
The returned bandwidth and frequencies are tuned so that they fulfill the condition f_i = n_i*df which avoids Fourier leakage. With priority ‘f’ the highest priority is put on getting the frequencies as close as possible to the target frequencies. With priority ‘df’ the highest priority is put on getting the measurement bandwidth as close as possible to the target value. With either prioity, the bandwidth is chosen such that the number of samples in the measurment time window is an integer power of 2. This tuning is recomended when the MLA is snychrnoized to external generators or sampling cards.

Examples

>>> f_out, df_out = mla.lockin.tune2(123456.789, 1000)
>>> mla.lockin.set_frequencies(f_out)
>>> mla.lockin.set_df(df_out)
wait_for_counter(counter, increment=1, target_value=None)

Block computer execution until specified counter in the received lockin data has reached a specified falue.

Parameters:
  • counter

    interger or string, must be one of the following:

    1 = ‘settings’ (increments every time a parameter is
    changed. This counter can be used to identify which data had which parameters. Note that the frequency and phase parameters will increment the settings counter by 2 when they are set.)
    2 = ‘trig2’ = ‘image_nr’ (count the number of trigger
    events in TRIG IN 2)
    3 = ‘trig1’ = ‘line_nr’ (count the number of trigger
    events in TRIG IN 1)
    4 = ‘pixel’ counter for the total number of time windows
    that has passed since the MLA was powered on. Note that this counter will continue to increase regardless of weather the data was transmitted to the computer or not.
  • increment – integer, wait for the specified counter to increment by this value. Can be overridden by target_value.
  • target_value – integer or None. If integer, override the increment parameter and wait for the specified counter to reach this value.
Returns:

buffer position of the first lockin packet which contains the specified counter and value.

Return type:

integer

Note

The lockin must be running, otherwise no new data will reach the computer data buffer. To continue the execution without having receiving the specified counter you can run lockin.Lockin.abort_wait_for_counter() from another thread.

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.set_Tm(0.1)
>>> mla.lockin.wait_for_counter('pixel',  increment=10) 
1892
>>> mla.lockin.stop_lockin()
wait_for_new_pixels(n=1, timeout=9999)

Block computer execution until the specified number of new pixels has been received in the computer buffer.

Parameters:
  • n – integer, then number of new pixels to wait for
  • timeout – float or ‘auto’, raise TimeOutException after this time if not enough pixels have arrived.
Returns:

None

Note

The lockin must be running, otherwise no new data will reach the computer data buffer. To continue the execution without having receiving the specified counter you can run lockin.Lockin.abort_wait_for_new_pixels() from another thread.

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.set_Tm(0.1)
>>> mla.lockin.wait_for_new_pixels(10)
>>> mla.lockin.stop_lockin()
wait_for_settings_effect(timeout=None)

When a command that changes the setup of the lockin is executed, there will inevitably be a delay until the change has had an effect in the hardware. After the new settings have had an effect in the hardware, and new data has been measured with the new settings, there will another delay until that data is available to the user. This function blocks further execution until lockin data with settings counter cnt are available.

Parameters:timeout – float [seconds], return after this time, even if the setting was not
Returns:None

Note

This function is automatically called when a setting is changed unless the keyword wait_for_effect=False is specified when the setting is changed. The purpose if this function is to allow the user to speed up their measurment scripts that changes multiple settings in each iteration of a loop, see the example below.

Examples

>>> mla.lockin.start_lockin()
>>> mla.lockin.set_frequencies(100e3, wait_for_effect=False)
>>> mla.lockin.set_amplitudes(0.1, wait_for_effect=False)
>>> mla.lockin.set_Tm(0.01, wait_for_effect=False)
>>> mla.lockin.wait_for_settings_effect()
>>> p = mla.lockin.get_pixels(n_pix=1, data_format='IQreal', unit='digital')
>>> p                                               
array([  2.20439491e+02,  -1.00917580e+02,  ..., -1.47609380e+02])
>>> mla.lockin.stop_lockin()
wait_for_trigger()

Block computer execution until received lockin data shows incremented trigger counter. This function will only work for the port TRIG IN 1. Please contact Intermodulation Products if you need other trigger methods.

Returns:buffer position of the lockin packet with increment trigger counter.
Return type:integer

Note

The line-pipe must be enabled before you can use this function. The lockin must be running, otherwise no new data will reach the computer data buffer. To continue the execution without receiving a trigger you can run lockin.Lockin.abort_wait_for_trigger() from another thread.

Examples

>>> from threading import Timer
>>> mla.lockin.set_trigger_flanks(trig1_flank='positive', trig2_flank='positive')
>>> mla.lockin.enable_wait_for_trigger(True)
>>> mla.lockin.start_lockin()
>>> Timer(1, mla.lockin.abort_wait_for_trigger).start()
>>> bufpos = mla.lockin.wait_for_trigger()
>>> mla.lockin.trig2_cnt[bufpos] 
37
>>> mla.lockin.stop_lockin()
class lockin.LockinReceiver(lockin)

A LockinReceiver is a separate object for extracting lock-in data from the buffer. Each LockinReceiver keeps track of which data it has extracted from the buffer. Use it when you have multiple, threaded, measurements running at the same time.

get_new_pixels(data_format='complex', unit='calibrated')
Return all new lockin packets from the buffer. The lockin object keeps track of which data has been extracted

from the buffer so that this function only returns new data that was not extraced last time. This command is usually issued in a loop together with plotting and other data processing commands. Before the loop the start of the measurement is indicated with the command mla.lockin.get_new_pixels(throw_away=True) which will throw away all the data that has arrived previous to this command.

Parameters:
data_format : {‘IQreal’, ‘complex’, ‘amp’, ‘phase’} specifies return data type. unit : {‘calibrated’, ‘digital’, ‘deg, ‘rad’} specifies units. ‘rad’ and ‘deg’ only for phase.
Returns:

Tuple: pixels, nr_pixels, meta

  • pixels : np.array(dtype=float) [ADU], axis 0 = [f0, f1, f2,…], axis 1 = [pixel0, pixel1, pixel2]
  • nr_pixels (integer): number of pixels returned
  • meta (Two dimensional numpy array of integers): The meta data of the pixels, i.e. header, settings_counter, trig1 counter, trig2 counter, pixel counter, trigger position, dc_data.
Examples:
>>> mla.lockin.set_Tm(0.1)
>>> mla.lockin.start_lockin()
>>> rec = lockin.LockinReceiver(mla.lockin)
>>> rec.wait_for_new_pixels(10)
>>> p, n, m = rec.get_new_pixels()
>>> p.shape
(42L, 10L)
>>> n
10
>>> m.shape
(6L, 10L)
>>> mla.lockin.stop_lockin()
wait_for_new_pixels(n=1, timeout=100)

Block computer execution until the specified number of pixels has been received since the last call to lockin.LockinReceiver.get_new_pixels().

Parameters:
  • n – integer, then number of new pixels to wait for
  • timeout – float or ‘auto’, raise TimeOutException after this time if not enough pixels have arrived.
Returns:

None

Note

The lockin must be running, otherwise no new data will reach the computer data buffer. To continue the execution without having receiving the specified counter you can run lockin.Lockin.abort_wait_for_new_pixels() from another thread.

Examples

>>> mla.lockin.set_Tm(0.1)
>>> mla.lockin.start_lockin()
>>> rec = lockin.LockinReceiver(mla.lockin)
>>> rec.wait_for_new_pixels(10)
>>> p, n, m = rec.get_new_pixels()
>>> p.shape
(42L, 10L)
>>> n
10
>>> m.shape
(6L, 10L)
>>> mla.lockin.stop_lockin()

mla.osc

class osc.Osc(hardware)

The mla.osc object deals with sampling of time domain data. Just as with the lockin object, starting a measurement is a nonblocking command that automatically starts to fill a computer buffer. Reading out measurement data is done by a separate command.

The mla.osc object also has functions for setting up downsampling and other functions related to acquiring time domain data.

ad_is_in_safe_range(nr_samples, port=[1])

Make a number of samples with the AD converter and report weather all samples is within 96% of the AD converter range.

Parameters:
  • nr_samples (int) – number of samples to use for the test.
  • port (int or list, optional) – {1-4} select which physical port to use for the measurement. Can be a list.
Returns:

if True, all samples are within 96% of the AD converter range.

Return type:

bool

Examples

>>> mla.osc.ad_is_in_safe_range(mla.lockin.samples_per_pixel)
True
frequency_count(nsamples=0, channel=1, downsampling=1)

Acquire a number of time samples and return the frequency of the strongest tone.

Parameters:
  • [integer] (downsampling) – The number of samples to acquire.
  • [1-4] (channel) – The physical port to acquire from.
  • [integer] – Set a downsampling factor before acquiring the data
Returns:

The frequency of the strongest tone.

Return type:

float [Hz]

Examples

>>> mla.lockin.set_output_mask(1)
>>> mla.lockin.set_amplitudes(0.1)
>>> mla.lockin.set_frequencies_khz(123.456789)
>>> mla.lockin.set_df(100)
>>> mla.lockin.reset_tones_on_new_pixel(False)
>>> time.sleep(1)
>>> mla.osc.frequency_count(1e6) 
123456.78...
get_data(nr_samples, copy_data=True, timeout=None)

Extract sample data from the computer buffer. Use this command when acquiring single bursts of data, i.e. together with the restart_when_done=False keyword.

Parameters:
  • [integer] (nr_samples) – The number of samples to extract
  • [boolean] (copy_data) – If True return a copy of the data, otherwise return pointer to shared buffer.
  • timeout (float, optional) – maximum time to wait for samples in milliseconds. Seto to None (default) to let the oscilloscope calculate the timeout. Set to 0. to wait forever.
Returns:

The raw samples.

Return type:

numpy array of int16

Raises:

OscTimeoutError – if no data is available within timeout milliseconds.

Example

>>> mla.osc.start_time_stream(1e6)
>>> data = mla.osc.get_data(1e6)
>>> data                         
array([-300, -264, -260, ..., -324, -280, -268], dtype=int16)
>>> data.shape
(1000000,)
get_max_DMA_rate()

Return the maximum rate of internal memory transfer on the FPGA. The total data rate (nr ports * sample rate) can not exceed this number when running time_stream

Returns:samples per second
Return type:float [Hz]
get_n_samples_max(dma_channel=0)

Return the maximum number of time samples that fits into the MLA RAM memory in the current configuration. The MLA RAM memory can be reconfigured with hardware.Hardware.configure_memory().

Parameters:[0 or 1] (dma_channel) – Selects which DMA channel to query.
Returns:The maximum number of time samples that fits into the MLA RAM memory in the current configuration.
Return type:integer

Example

>>> M = 1<<20 # One Megabyte
>>> mla.hardware.configure_memory(M, M, M, M, 760*M, M, M, M)
>>> mla.osc.get_n_samples_max(0)
398458880
>>> mla.osc.get_n_samples_max(1)
524288
>>> mla.hardware.set_default_settings()
>>> mla.osc.get_n_samples_max(0)
67108864
>>> mla.osc.get_n_samples_max(1)
67108864
get_samplerate()

Return the sampling frequency of the fast AD converters, taking specified downsampling into account.

Returns:The sampling frequency.
Return type:float [Hz]

Note

The downsampling is associated with the DMA channel for the data transfer. Not the physical channel.

Examples

>>> mla.osc.set_downsampling(16)
>>> mla.osc.get_samplerate()
3125000.0
>>> mla.osc.set_downsampling(1)
>>> mla.osc.get_samplerate()
50000000.0
get_samplerate_raw()

Return the raw sampling frequency of the fast AD converters, not taking any downsampling into account.

Returns:The sampling frequency.
Return type:float [Hz]

Note

The downsampling is associated with the DMA channel for the data transfer. Not the physical channel.

Examples

>>> mla.hardware.set_ad_clock_divisor(25)
>>> mla.osc.get_samplerate_raw()
100000000.0
>>> mla.hardware.set_ad_clock_divisor(50)
>>> mla.osc.get_samplerate_raw()
50000000.0
get_stream_data(nr_samples, timeout=None)

Extract sample data from the computer buffer. Use this command together when acquiring data continously, i.e. together with the restart_when_done=True keyword. The idea is to use this command repeatingly: acqiure one chunks, process the data, and then acquire a new chunk. The function automatically make sure that the next chunk is

Parameters:
  • nr_samples (int) – The number of samples to extract.
  • timeout (float, optional) – maximum time to wait for samples in milliseconds. Seto to None (default) to let the oscilloscope calculate the timeout. Set to 0. to wait forever.
Returns:

The raw samples.

Return type:

numpy array of int16

Raises:

OscTimeoutError – if no data is available within timeout milliseconds.

Example

>>> # Extract the maximum of one million samples
>>> m = -32768
>>> mla.osc.start_time_stream(1e5, restart_when_done=True)
>>> for i in range(10):
...     data = mla.osc.get_stream_data(1e5)
...     m = max(m, data.max())
>>> m           
3134
>>> mla.osc.stop_time_stream()
set_downsampling(n=1, multiplier=None)

Setup downsampling in the FPGA logic. The downsampling algorithm adds n samples and multiplies the sum by a multiplier. The lowest 16 bits is then used as the output. This means multiplier=2**16 corresponds to scaling the output by 1.

Normally the multiplier can be left to None, which meas the it will be calculated automatically to preserve the magnitue of the output regardless of the number of samples, (i.e. multiplier = 2**16/n). The only reason to set the multiplier manually is when you are sure that the input signal is very low, and you want to average many samples without throwing away two least significant bits.

Parameters:
  • dma_channel – 0 or 1: select which DMA channel to activate downsampling on.
  • n – integer < 255: how many samples should be used in the downsampling
  • multiplier – integer < 2**16

Note

The downsampling is associated with the DMA channel for the data transfer. Not the physical channel.

Examples

>>> mla.osc.set_downsampling(16)
>>> mla.osc.start_time_stream(25e5, trig_mode=1)
>>> t0 = time.time()
>>> data = mla.osc.get_data(25e5)
>>> time.time()-t0          
0.8
>>> mla.osc.set_downsampling(1)
>>> mla.osc.start_time_stream(25e5, trig_mode=1)
>>> t0 = time.time()
>>> data = mla.osc.get_data(25e5)
>>> time.time()-t0          
0.05
start_time_stream(nr_samples, reset=True, dma_channel=0, restart_when_done=False, trig_mode=2, port=[1], interleave_eol=False)

Start sending raw sample data from the AD converters to the computer buffer.

Parameters:
  • [integer] (trig_mode) – The number of samples you want to acqire.
  • [boolean] (reset) – Reset the DMA before starting the transfer. Keep reset=True (reset=False is untested).
  • [None or integer] (nr_chunks) – To shorten the time until the first samples are sent, the data can be sent in smaller chunks. However, having
  • chunks may decrease the overall throughput. When restart_when_done=True there must be at least two chunks.Keeping nr_chunks=None (many) –
  • let the algorithm determine the number of chunks. (will) –
  • [0 or 1] (dma_channel) – Select which DMA channel to use to transfer the data from the FPGA logic to the MLA RAM memory. Normally,
  • 0 is used for time samples and channel 1 is used for lockin data. (channel) –
  • restart_when_done – Tells the MLA to automatically start a new transfer immediately when the previus transfer is finished. Use this command
  • transfer streams that are longer than what fits into the MLA RAM (to) –
  • [integer] – Select how to trigger the start of the data stream. See table below
  • port – [1-4]: Select which physical port to use for the measurement. Can be a list.
trig_mode Description
0 Not triggered (the stream will not start)
1 Triggered (the stream starts immediately)
2 Trigger when the lock-in unit starts a new measurement window
3 Trigger when trigger in 1 event has arrived, and the lock-in unit starts a new measurement window

Examples

>>> mla.osc.start_time_stream(50000)
>>> mla.osc.get_data(50000)  
array([-300, -260, -304, ..., -268, -272, -296], dtype=int16)
stop_time_stream(dma_channel=0)

Stop continous streaming of time data.

Examples

>>> mla.osc.start_time_stream(1e5, restart_when_done=True)
>>> data = mla.osc.get_stream_data(1e6)
>>> data         
array([-280, -296, -284, ..., -296, -288, -288], dtype=int16)
>>> data.shape
(1000000,)
>>> mla.osc.stop_time_stream()

mla.arb

class arb.Arb(hardware)
set_pulse(freq, ampl, width, port=1, nsamples=1000000, unit='calibrated', correct_delay=True)

Set a square pulse with given width.

Parameters:
  • freq – pulse repetition frequency
  • ampl – pulse height
  • width – pulse width relative to repetition period
  • port – output port, 1 or 2
  • nsamples – number of samples to generate
  • delay – shift the waveform to the right (left) if delay > 0 (< 0)
set_pulse2(freq, ampl, offset=0, width=0.5, rise=0.0, fall=0.0, port=1, nsamples=1000000, unit='calibrated', correct_delay=True)

Set a square pulse with given parameters.

Parameters:
  • freq (float) – pulse repetition frequency in Hz
  • ampl (int) – pulse amplitude in DA (digital) units
  • offset (int, optional) – pulse low value in DA (digital) units
  • width (float) – pulse width in units of repetition period in the open interval (0, 1)
  • rise (float, optional) – pulse rise time constant in units of repetition period [0, inf)
  • fall (float, optional) – pulse fall time constant in units of repetition period [0, inf)
  • port (int, optional) – output port, 1 or 2
  • nsamples (int, optional) – number of samples to generate
  • delay (bool, optional) – correct for delay in the DAC
start_arb(port=1, trig_mode=2, repeat=True)

Start ARB.

Parameters:
  • [1 or 2] (port) –
  • [integer] (trig_mode) – Select how to trigger the start of the data stream. See table below
  • [True or False] (repeat) – Restart the wavefrom from the beginning when it reaches the end
trig_mode Description
0 Not triggered (the stream will not start)
1 Triggered (the stream starts immediately)
2 Trigger when the lock-in unit starts a new measurement window
3 Trigger when trigger in 1 event has arrived, and the lock-in unit starts a new measurement window

Note: You must use mla.hardware.set_output_type(“arb”, port) before using this function

stop_arb()

Convenience function. See also mla.lockin.set_output_mode_lockin:

Set the fpga output multiplexer to output data from the lockin waveform generators, as opposed to the arbitrary waveform generators.

mla.feeback

class feedback.Feedback(hardware, lockin, osc, settings)
activate_phase(enable=True)

Activates or deactivates phase feedback on port OUT C.

Parameters:enable – True or False

See also

feedback.Feednack.set_phase_offset(), feedback.Feednack.set_phase_setpoint()

afm_engage(relative_tapping_mode_setpoint=None, event=True)

Reenable the feedback.

Parameters:relative_tapping_mode_setpoint (float, optional) – if missing, uses the last used.

Notes

sets the feedback mode and adjusts the setpoint.

See also

afm_lift

afm_lift(event=False)

Switch off the feedback and cause the AFM to lift.

Notes

Sets the feedback mode to dc_only and outputs a big dc offset.

See also

afm_engage

autosetup_afm(relative_tapping_mode_setpoint, verbose=True)

Set up the amplitude feedback and enable it on the correct output port.

Parameters:
  • relative_tapping_mode_setpoint (float) – the output will be zero when the measured amplitude is the current amplitude times this factor
  • verbose (bool, optional) – set to False to avoid printing to stdout

Notes

The output port is chosen according to settings[‘FEEDBACK’][‘fb_out_port’] The feedback type is chosen according to settings[‘FEEDBACK’][‘polarity’]

See also

set_feedback_type_on_correct_port

calculate_feedback_amplitude(pix, verbose=True)

(Re)calculates the cordic contribution to the feedback amplitude at free amplitude.

Parameters:pix (ndarray) – a scaled lockin pixel in IQreal format and digital units
Returns:the calculated cordic feedback amplitude
Return type:(int)

Notes

Reads class attributes _cordic_shift and _cordic_scale. Sets class attribute _feedback_amplitude

set_current_phase_to_value(value=0, unit='calibrated')

Make the current reading of the phase generate a specific value at OUT C.

Parameters:
  • value – float, The value that the current reading of phase should generate at OUT C
  • unit – ‘calibrated’ or ‘digital’

See also

feedback.Feednack.activate_phase(), feedback.Feednack.set_phase_offset(), Calibration

set_feedback_type(val)

0 feedback from ublaze 1 only dc value 2 cordic feedback, legacy mode 3 cordic feedback, positive photodiode polarity 4 cordic feedback, negative photodiode polarity 5 Use feedback port as a signal output port 7 Output In-phase part 8 Output Quadrature-phase part

set_feedback_type_on_correct_port(val)

0 feedback from ublaze 1 only dc value 2 cordic feedback, legacy mode 3 cordic feedback, positive photodiode polarity 4 cordic feedback, negative photodiode polarity 5 Use feedback port as a signal output port 7 In-phase part (and Quadrature-phase part on OUT C if fb_out_port is slow_dac) 8 Quadrature-phase part (only on OUT 2)

set_feedback_type_on_port(val, out_port)

0 feedback from ublaze 1 only dc value 2 cordic feedback, legacy mode 3 cordic feedback, positive photodiode polarity 4 cordic feedback, negative photodiode polarity 5 Use feedback port as a signal output port 7 In-phase part (and Quadrature-phase part on OUT C if out_port is slow_dac) 8 Quadrature-phase part

set_feedback_type_slow(val)

0 feedback from ublaze 1 only dc value 2 cordic feedback, legacy mode 3 cordic feedback, positive photodiode polarity 4 cordic feedback, negative photodiode polarity 5 Use feedback port as a signal output port 7 Output In-phase part (OUT A) and Quadrature-phase part (OUT C) instead of amplitude and phase

set_phase_offset(offset, unit='calibrated')

Add a constant offset to the phase feedback value to port OUT C.

Parameters:
  • offset – 16 bit integer, -32768 to 32767 if unit is digital
  • unit – ‘calibrated’ or ‘digital’

Note

This function is useful, both for setting a custom set point, and for avoiding jumps when the phase is wrapping.

See also

feedback.Feednack.activate_phase(), feedback.Feednack.set_phase_setpoint()

setup(gain=1.0, offset=0.0, output_port='A', unit='calibrated')

Set up an analog output voltage, proportional to the result of a lock-in measurment using the frequency at index=0.

Parameters:
  • gain (float, optional) – With gain=1.0 the output voltage will be equal the amplitude of the input voltage.
  • offset (float, optional) – Adds an offset to the output voltage.
  • output_port (int or str, optional) – {2, ‘A’, ‘both’} specify which port shall be used for the analog output. Default output port A.
  • unit (str, optional) – {‘calibrated’, ‘digital’} specify which unit to work with. When ‘calibrated’, use the units of the selected calibration. When ‘digital’, use the direct digital units of the AD- and DA-converters.
Returns:

whether the given combunation of parameters were valid.

Return type:

(bool)

Raises:

ValueError – if the values of the arguments are not supported.

Notes

Assuming the input signal is A_in * cos(w*t), setting gain=1.0 will produce an output equal to the measured (peak) amplitude A_in. For the peak-to-peak amplitude, set gain=2.0 For the RMS amplitude, set gain=1.0 / sqrt(2)

See also

feedback.Feedback.ramp()

mla.hardware

class hardware.Hardware(parent, settings, hconfig, ip_address, firmware_path, hardware_version, eh=None)

This class contains low-level functions for hardware setup and direct communication with the MLA. It also contains some auxiliary function that does not fit into any of the more user-oriented classes lockin, osc, arb or feeedback.

configure_memory(ad0, ad1, da0, da1)

Configure how the MLA should partition the available sample memory of 768 Megabytes.

Parameters:
  • ad0 – integer (default=128*MEGABYTE), sample memory for DMA ad0
  • ad1 – integer (default=128*MEGABYTE), sample memory for DMA ad1
  • da0 – integer (default=128*MEGABYTE), sample memory for DMA da0
  • da1 – integer (default=128*MEGABYTE), sample memory for DMA da1
Returns:

None

The memory is partitioned with respect to the DMA-channels (not the physical channels or ports). Adequate space must be reserved for the scatter-gather descriptors. Each SGD needs 64 bytes. For lockin data, the default is to have 200000 SGD, while for the other types of we usuallyhave only a few SGD.

Examples

>>> M = 1<<20 # One Megabyte
>>> # Optimize for one channel AD measurements
>>> mla.hardware.configure_memory(M, M, M, M, 760*M, M, M, M)
>>> # Set back the defaults
>>> mla.hardware.configure_memory(16*M, 16*M, 16*M, 16*M, 128*M, 128*M, 128*M, 128*M)
echo(value='a')

Send a string to the MLA and wait for the MLA to return the same string.

Parameters:value – string
Returns:string

This function is useful to determine of the connection to the MLA is valid.

Examples

>>> mla.hardware.echo('Hello')
'Hello'
get_firmware_version()

Return the version of the firmware in the MLA hardware unit.

Returns:firmware version
Return type:integer

This functions queries the firmware itself (it is not reading the firmware filename).

Examples

>>> mla.hardware.get_firmware_version() 
49
get_input_relay(port)

Obtain state of input relays

Returns:(se, nodamp, term, dc, gain, bypass, gain2)
Return type:tuple of booleans
get_nr_freqs_in()

Return the number of input frequencies that the MLA can analyze simultaneously.

Returns:number of frequencies
Return type:integer

This functions queries the firmware inside the MLA hardware.

Examples

>>> mla.hardware.get_nr_freqs_in() 
42
get_nr_freqs_out()

Return the number of out frequencies that the MLA can generate simultaneously.

Returns:number of frequencies
Return type:integer

This functions queries the firmware inside the MLA hardware.

Examples

>>> mla.hardware.get_nr_freqs_out() 
42
get_nr_input_ports()

Return the number of (initialized) physical input ports

get_output_relay(port)

Obtain state of output relay

Returns:boolean
get_overflow()

Read the overflow flags from the MLA and return a list of strings describing which flags are set.

Note

An overflow flag is active until it has be actively reset by hardware.Hardware.reset_overflow().

get_temperature()

Read the temperature for the FPGA chip inside the MLA.

Parameters:n_samples – integer, the number of temperature measurements to make
Returns:temperatures in degrees Celsius
Return type:np.array(dtype=float)

Any temperature below 70 degrees should be considered safe. The chip is rated for 85 degrees but such high temperature for long periods may degrade the lifetime of the chip.

Examples

>>> mla.hardware.get_temperature(3) 
array([ 42.09583664,  41.71133423,  42.14197693])
has_relays()

Test whether the current hardware has input and output relays.

Returns:(bool)
reset_overflow(flags=4294967295)

Reset overflow flags.

Parameters:flags – integer mask describing which flags should be reset,

Note

An overflow flag is active until it has be actively reset.

set_LED(val)

Set which LEDs on the front panel should be turned on.

Parameters:val – integer, 0-15
Returns:None

The LEDs are assigned to numbers as follows: NETWORK=1, MODE=2, OVERLOAD=4, ERROR=8. The val parameter should be the sum of the LED that should be turned on.

Examples

>>> mla.hardware.set_LED(0xf) # Turn on all LED
>>> mla.hardware.set_LED(6)   # Turn on MODE and OVERLOAD, turn off the rest
>>> mla.hardware.set_LED(1)   # Turn on NETWORK, turn off the rest
set_ad_clock_divisor(divisor)

Set the clock frequency of the AD-converter for port IN 1 and IN 2.

Parameters:divisor – integer, 10-1045, the clock frequency will become 2.5 GHz/divisor
Returns:None

This clock frequency will also determine the speed of the lockin calculations.

Note

For high clock frequencies, it may be necessary to hardware.Hardware.set_ad_clock_phase().

Examples

>>> mla.hardware.set_ad_clock_divisor(10)
>>> mla.hardware.set_ad_clock_phase(15)
>>> mla.hardware.set_ad_clock_divisor(50)
>>> mla.hardware.set_ad_clock_phase(0)
set_ad_clock_phase(value)

Set the timing register on the AD converter for port IN 1 and IN 2.

Parameters:value – integer, 0-15
Returns:None

Setting this value may be necessary when setting a high clock frequency to the ad converter for port IN 1 and IN 2. Typcal values are

ad_clock_divisor ad_clock_phase
10 15
20-50 0

Examples

>>> mla.hardware.set_ad_clock_divisor(10)
>>> mla.hardware.set_ad_clock_phase(15)
>>> mla.hardware.set_ad_clock_divisor(50)
>>> mla.hardware.set_ad_clock_phase(0)

References

Put references, web links, or links to other sections of the user manual here.

set_clkin_parameters(R1_divider=10, N1_divider=100, select_mode=0)

Set the parameters of reference clock. This is a low-level function. For most cases one of these functions will probably be enough hardware.Hardware.set_clkref_external_10MHz(), hardware.Hardware.set_clkref_internal()

Parameters:
  • R1_divider – integer, divides CLKin to PLL1 (default PLL1 freq is 1 MHz)
  • N1_divider – divides the internal 100 MHz to PLL1 (default PLL1 freq is 1 MHz)
  • select_mode – integer 0-7, set the mode of the input clock, see table below.
Returns:

None

select_mode Description
0 Select external clock in
1 Select internal clock in
2 Reserved
3 Pin select mode
4 Auto mode (will only work if REF CLK IN = 100 MHz (or 50 MHz, 25 MHz, or 12.5 MHz if you set the CLKin 0 divider))
5 Reserved
6 Auto mode & next clock pin select
7 Reserved

Note

The two frequencies coming from N1 and R1 dividers must be the same.

Examples

>>> # Use 10 MHZ external reference clock input
>>> mla.hardware.set_clkin_parameters(R1_divider=10, N1_divider=100, select_mode=0)
>>> # Use a 100 MHZ internal reference clock
>>> mla.hardware.set_clkin_parameters(R1_divider=100, N1_divider=100, select_mode=1)
>>> # Use the default internal reference clock
>>> mla.hardware.set_clkref_internal()
set_clkout_divisor(divisor)

Set the clock frequency of REF CLK OUT port.

Parameters:divisor – integer, 1-1045, the clock frequency will become 2.5 GHz/divisor
Returns:None

Examples

>>> mla.hardware.set_clkout_divisor(25) # Set 100 MHz
>>> mla.hardware.set_ad_clock_phase(250) # Set 10 MHz
set_clkout_power(bool_power_on)

Turn on or off the clock output signal at port REF CLK OUT

Returns:None

Examples

>>> mla.hardware.set_clkout_power(False)
>>> mla.hardware.set_clkout_power(True)
set_clkout_type(typ)

Set the output type of the port REF CLK OUT

Parameters:typ – integer, 0-14, see table below.
Returns:None
value Description
0 (0x00) Power down
1 (0x01) LVDS
2 (0x02) LVPECL (700 mVpp)
3 (0x03) LVPECL (1200 mVpp)
4 (0x04) LVPECL (1600 mVpp)
5 (0x05) LVPECL (2000 mVpp)
6 (0x06) LVCMOS (Norm/Inv)
7 (0x07) LVCMOS (Inv/Norm)
8 (0x08) LVCMOS (Norm/Norm)
9 (0x09) LVCMOS (Inv/Inv)
10 (0x0A) LVCMOS (Low/Norm)
11 (0x0A) LVCMOS (Low/Inv)
12 (0x0C) LVCMOS (Norm/Low)
13 (0x0D) LVCMOS (Inv/Low)
14 (0x0E) LVCMOS (Low/Low)

Note

Only the positive part of the diffential pair is connected to REF CLK OUT. It is first shunted to ground by 120 Ohm, and the AC-coupled with 100 nF

Examples

>>> mla.hardware.set_clkout_power(7)
>>> mla.hardware.set_clkout_power(1)
set_clkref_external_10MHz()

Lock the master clock to a 10 MHz signal at port REF CLK IN.

Returns:None

Examples

>>> mla.hardware.set_clkref_external_10MHz()
>>> mla.hardware.set_clkref_internal()
set_clkref_internal()

Lock the master clock to the internal clock reference.

Returns:None

Examples

>>> mla.hardware.set_clkref_external_10MHz()
>>> mla.hardware.set_clkref_internal()
set_dac_auxdac(port, value, unit='calibrated', state='on')

Set a DC offset to port OUT 1 or OUT 2.

Parameters:
  • port – 1 or 2
  • value – float, if unit=’digital’, value must be 0-1023
  • unit – ‘calibrated’ or ‘digital’
  • state – ‘on’ or ‘off’, this option can be used to turn off the axudac
Returns:

None

This function is connected to a separate DA-converter, which is connected to the common mode pin of the differential amplifier at the outout stage.

Examples

>>> mla.hardware.set_dac_auxdac(1, 0.7)
>>> mla.hardware.set_dac_auxdac(1, 0, unit='digital')
set_dac_clock_divisor(divisor)

Set the clock frequency of the DA-converter for port OUT 1 and OUT 2.

Parameters:divisor – integer, 10-1045, the clock frequency will become 2.5 GHz/divisor
Returns:None

Examples

>>> mla.hardware.set_dac_clock_divisor(25) # Set 100 MHz
>>> mla.hardware.set_dac_clock_divisor(50) # Set 50 MHz
set_dac_fsc(port, value=512)

Set the “full scale current” of the DA-converter. Use this command to configure the maximum output voltage on ports OUT 1 and OUT 2.

Parameters:
  • port – 1 or 2
  • val – 0-1023 (0->8.66 mA, 512->20.0 mA (default), 1023->31.66 mA)
Returns:

None

Warning

Setting another value than 512 will make the calibration invalid.

Examples

>>> mla.hardware.set_dac_fsc(1, 1023)
>>> mla.hardware.set_dac_fsc(1, 512)
set_dac_interpolation(interpolation_type)

Configure how the DAC should interpolate the data stream

Parameters:interpolation_type – integer, 0 = No interploation, 1 = linear, 2 = quadratic
Returns:None

Examples

>>> mla.hardware.set_dac_interpolation(2)
set_input_relay(port, se=False, nodamp=False, term=False, dc=False, gain=False, bypass=False, gain2=False, event=True)

Manually configure analog input stage. Switch states are displayed in the MLA GUI. See MLA manual for description of the switch states.

Parameters:
  • port – int, input port number.
  • se – bool, signal type.
  • nodamp – bool, series restance.
  • term – bool, input termination.
  • dc – bool, ac/dc coupling.
  • gain – bool, 1st stage gain.
  • bypass – bool, bypass first gain stage.
  • gain2 – bool, 2nd stage gain.
  • event – bool, make the eventhandler trigger the EVT_INPUT_RELAY_UPDATED event.
  • wait_for_effect – bool, block execution until relay safely fully switched.
Returns:

None

Note

Eeach call of this function sets all relays. Default relay state is False for each relay.

set_output_multiplexer(channel_1, channel_2)

Deprecated, please use hardware.Hardware.set_output_type() instead. Control weather the output ports shall output from the lockin waveform generators, or the arbitrary waveform generator.

Parameters:
  • channel_1 – “off”, “arb”, or “lockin”
  • channel_2 – “off”, “arb”, or “lockin”
set_output_relay(port, bypass=False, event=True)
Manually configure analog output stage.
Use to control the range of the output signal.
Parameters:
  • port – int, input port number.
  • bypass – bool, bypass 2nd stage output amplifier
  • event – bool, make the eventhandler trigger the EVT_OUTPUT_RELAY_UPDATED event.
  • wait_for_effect – bool, block execution until relay safely fully switched.
Returns:

None

set_output_type(value, port)

Control weather the output ports shall output from the lockin waveform generators, or the arbitrary waveform generator.

Parameters:
  • value – “off”, “arb”, “lockin”, “lockin+arb” or None
  • port – 1 or 2
set_slowad_clock_divisor(divisor)

Set the clock frequency of the AD-converter for port IN 3 and IN 4.

Parameters:divisor – integer, 40-1045, the clock frequency will become 2.5 GHz/divisor
Returns:None

Examples

>>> mla.hardware.set_slowad_clock_divisor(100)
>>> mla.hardware.set_ad_clock_phase(50)
set_slowdac(port, value, unit='calibrated')

Apply a voltage at port OUT A, OUT B or OUT C (or the internal out D).

Parameters:
  • port – ‘A’, ‘B’, ‘C’, ‘D’ or integer 1-4
  • value – float, The output value in the specified unit (see unit argument)
  • unit – ‘calibrated’ or ‘digital’, if unit=’digital’, value should be -32768 to 32767
Returns:

None

Note

In the standard AFM configuration, port A is used for feedback and cannot be set by this method. To deactivate the feedback and activate port ‘A’ for set_slowdac, run mla.feedback.deactivate_slowdac().

Examples

>>> mla.hardware.set_slowdac('B', 1.7)
>>> mla.hardware.set_slowdac('B', -3.5)
>>> mla.hardware.set_slowdac('B', 0)
set_slowdac_toggle(val1, val2, unit='calibrated', enable=1)

Setup port OUT B to toggle between val1 and val2 each time a trigger event is detected on port TRIG IN 1.

Parameters:
  • val1 – float (see unit argument)
  • val2 – float (see unit argument)
  • unit – ‘calibrated’ or ‘digital’, if unit=’digital’, value should be -32768 to 32767
  • enable – 0 or 1, to disable or enable this functionality
Returns:

None

At the first trigger event after this function is executed, the value of port B will be set to val1. At the second trigger event val2, etc.

Examples

>>> # Toggle between 1.5 V and 3.3 V
>>> #mla.hardware.set_slowdac_toggle(1.5, 3.3)
>>> # Toggle between 0 and full scale output
>>> #mla.hardware.set_slowdac_toggle(0, 32767, unit='digital', enable=1)
>>> # Disable toggling
>>> #mla.hardware.set_slowdac_toggle(0, 0, unit='digital', enable=0)

References

Put references, web links, or links to other sections of the user manual here.

upload_calibration(filepath, target_filename=None)

Upload a calibration file to the MLA.

Parameters:
  • filepath – String, the full path to the file that should be uploaded.
  • target_filename – String or None, set a different name of the uploaded file. If None, use the same name as the source.

Examples

>>> mla.hardware.upload_calibration(c:\calibration.ini) 
>>> mla.hardware.upload_calibration(c:\calibration.ini, cal.ini) 

See also

unit_converter.UnitConverter.set_calfile()