Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Standford Research SR860 lock-in amplifier driver improvements #1160

Merged
merged 25 commits into from Jul 5, 2018

Conversation

sohailc
Copy link
Member

@sohailc sohailc commented Jun 25, 2018

An update for the driver for Standford Research lock-in amplifiers SR86x and SR860 in particular. The work is done together with @astafan8.

BUG FIXES:

  • Fix maximum frequency for SRS860 - it is 500 kHz, not 500 Hz
  • get_capture_data uses the above functions; it does not have the 64kB limit anymore, instead it's limit is the current capture length (via _get_raw_capture_data function)
  • sine_outdc can set the value below 1 mV, the instrument can handle that

NEW DRIVER METHODS:

  • add caprture_one_sample_per_trigger that captures a given number of samples per each trigger signal; a callable argument starts the trigger pulses train
  • add start_capture_at_trigger that captures a given number of samples once it receives a trigger signal; a callable argument initiates sending a trigger signal
  • add set_capture_length_to_fit_samples to conveniently set the capture length for the number of sample (not kilobytes)
  • add wait_until_samples_captured to conveniently wait until the given number of samples is captured

NEW DRIVER PARAMETERS:

  • add parameter for the source of the trigger signal
  • add parameter for the source of the reference signal
  • _get_raw_capture_data_block implements the direct low-level call to CAPTUREGET command of the instrument
  • _get_raw_capture_data allows to get data from the beginning of the buffer avoiding the instrument's 64kB-reading-per-time limit

EXAMPLE NOTEBOOK UPDATED

  • more descriptive
  • covers capture modes

Code improvements related to capturing data via the buffer

  • add min_capture_length_in_kb as a property
  • add max_capture_length_in_kb as a property
  • make _set_capture_len_parser object method from static method
  • make _set_capture_len_parser use new capture-length-related properties
  • make _calc_capture_size_in_kb reuse _set_capture_len_parser
  • add convenient set_capture_rate_to_maximum method
  • add convenient _get_list_of_capture_variable_names and reuse it
  • add convenient _get_number_of_capture_variables and reuse it

@jenshnielsen @WilliamHPNielsen @Dominik-Vogel

… samples per each trigger signal; a callable argument starts the trigger pulses train

- add start_capture_at_trigger that captures a given number of samples once it receives a trigger signal
- add parameter for the source of trigger signal
- add parameter for the source of reference signal
- capture only the requested number of samples
  in start_capture_at_trigger, not the full buffer
- add min_capture_length_in_kb property
- add max_capture_length_in_kb property
- make _set_capture_len_parser object method from static method
- make _set_capture_len_parser use new capture-length-related properties
- make _calc_capture_size_in_kb reuse _set_capture_len_parser
- add convenient set_capture_rate_to_maximum method
- add convenient _get_list_of_capture_variable_names and reuse it
- add convenient _get_number_of_capture_variables and reuse it
- remove capture_samples method because it does not make much sense
@codecov
Copy link

codecov bot commented Jun 25, 2018

Codecov Report

Merging #1160 into master will not change coverage.
The diff coverage is n/a.

@@           Coverage Diff           @@
##           master    #1160   +/-   ##
=======================================
  Coverage   79.67%   79.67%           
=======================================
  Files          47       47           
  Lines        6661     6661           
=======================================
  Hits         5307     5307           
  Misses       1354     1354

@sohailc sohailc force-pushed the sr860_capture_n_at_trigger branch from 78ee2cb to 06447a9 Compare June 25, 2018 19:09
@WilliamHPNielsen
Copy link
Contributor

Not-so-useful comment: It would make my editor happy if we could stick to a maximum line length of 79.

argument to True allows this method to be used as well for set commands of the instrument parameters.

Args:
capture_length_in_kb (int): The desired capture length in kB.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is superfluous to write the type down here again. (same for subsequent docstrings)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. i will remove it.

capture_len_in_kb (int)
"""
if capture_length_in_kb % 2:
capture_length_in_kb += 1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is a good idea to give the user anything else than either exactly what they ask for or a big fat exception. I realise that this is a private method, but I think that principle is still valid.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i will make it an exception. users will have to be explicit and the driver will be straightforward.

Just for the record, the lock-in itself when given an odd number can convert it to even internally.

@WilliamHPNielsen
Copy link
Contributor

I left a few minor comments. Else it looks sensible. Have you tested it on real hardware, @sohailc and @astafan8?

"""
return self._parse_capture_length(capture_len_in_kb, issue_warning=True)

def _parse_capture_length(self, capture_length_in_kb: int, issue_warning: bool=False) -> int:
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this function has a wrong name; it does not really parse anything. Additionally, I think maybe William is right when he says that the function should return exactly what the user asked (see his comment below). In this case, I think the function should be "validate_capture_length" and should not return anything

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WilliamHPNielsen Yes, this has all been tested on real hardware

- _get_raw_capture_data_block implements the direct low-level call to
  CAPTUREGET command of the instrument
- _get_raw_capture_data allows to get data from the beginning of the
  buffer avoiding the instrument's 64kB-reading-per-time limit
- get_capture_data uses the above functions; it does not have the 64kB
  limit anymore, instead it's limit is the current capture length (via
  _get_raw_capture_data function)
Copy link
Contributor

@astafan8 astafan8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rigorously tested by @astafan8 on the device

- set_capture_length_to_fit_samples
- wait_until_samples_captured
Copy link
Contributor

@Dominik-Vogel Dominik-Vogel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.
@sohailc or @astafan8 could you add an example for set_capture_length_to_fit_samples to the example notebook notebook?

sohailc and others added 8 commits July 2, 2018 15:54
It has been accidentally removed, but now it is back and implemented in
a better way rather than "sleeping" for "capture_rate*sample_count"
amount of time.
This is more consistent with the names of other methods. It is also
a more correct name since the capture is not only started but also
stopped within this method.
Before it was not, which resulted in a bug for cases where the capture
config had more than one variable, that the function would
return before the requested number of samples is acquired.
In "continuous" capture mode, this function does not work at high
capture rates because the buffer starts getting overwritten *before*
wait_until_samples_captured realizes that enough samples have been
captured. This occurs due to the fact that VISA call to
capture_bytes in the while in wait_until_samples_captured cannot
keep up with the lock-in acquisition speed at high capture rates, hence
the data gets "wrapped" (in other words, the buffer gets overwritten)
which results in the value returned by capture_bytes to be small again,
thus the while loop is not escaped.
It is now up to date with the driver implementation, and covers three
popular capture modes.
@astafan8 astafan8 dismissed Dominik-Vogel’s stale review July 5, 2018 12:50

updated the notebook

name
instrument
This argument is unused, but needed because the add_parameter
method of the Instrument base class adds this as a kwarg.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why the instrument is just not passed to the super method so that the paramter is bound to the instrument. (I realize this is nothing new)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed. smth to fix later

The device can actually handle that, so now specifying 1e-6, 5e-9, etc.
works without any problems.
@astafan8 astafan8 merged commit 0d85481 into microsoft:master Jul 5, 2018
@sohailc sohailc deleted the sr860_capture_n_at_trigger branch July 5, 2018 13:42
giulioungaretti pushed a commit that referenced this pull request Jul 5, 2018
Merge: 2162c5e 6d3a49d
Author: Mikhail Astafev <astafan8@gmail.com>

    Merge pull request #1160 from sohailc/sr860_capture_n_at_trigger
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants