Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion pslab/instrument/waveform_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ def generate(
Frequency in Hz. Can be a list containing two different values when
'channel' is ['SI1', 'SI2']. Must be greater than 0.1 Hz. For
frequencies below 1 Hz the signal is noticably attenuated by AC
coupling.
coupling. Input frequency lists are not modified; the actual
generated frequencies are returned separately.
phase : float, optional
Phase between waveforms when generating waveforms on both SI1 and
SI2 in degrees. The default is 0.
Expand All @@ -157,6 +158,7 @@ def generate(
channels = ["SI1", "SI2"][:channels]

channels, frequency = _listify(channels, 2, frequency)
frequency = frequency.copy()
table_size = len(channels) * [None]
timegap = len(channels) * [None]
prescaler = len(channels) * [None]
Expand Down
40 changes: 40 additions & 0 deletions tests/test_waveform_frequency_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""Requested analog frequencies remain distinct from generated frequencies."""

from unittest.mock import Mock

import pytest

from pslab.connection import ConnectionHandler
from pslab.instrument.waveform_generator import WaveformGenerator


@pytest.mark.parametrize(
"channels,requested",
[("SI1", [1001]), ("SI2", [2003]), (["SI1", "SI2"], [1001, 2003])],
)
def test_generate_does_not_replace_requested_frequency_list(channels, requested):
generator = WaveformGenerator(Mock(spec=ConnectionHandler))
original = requested.copy()
actual = generator.generate(channels, requested)
assert requested == original
assert actual != original
names = channels if isinstance(channels, list) else [channels]
assert actual == [generator._channels[name].frequency for name in names]


def test_failed_generation_does_not_partially_replace_requested_frequencies():
generator = WaveformGenerator(Mock(spec=ConnectionHandler))
requested = [1001, 0.05]
with pytest.raises(ValueError, match="Frequency must be greater"):
generator.generate(["SI1", "SI2"], requested)
assert requested == [1001, 0.05]
assert generator._device.mock_calls == []


def test_list_and_scalar_requests_program_identical_commands():
list_generator = WaveformGenerator(Mock(spec=ConnectionHandler))
scalar_generator = WaveformGenerator(Mock(spec=ConnectionHandler))
actual = list_generator.generate(["SI1", "SI2"], [1001, 1001], phase=90)
scalar_actual = scalar_generator.generate(["SI1", "SI2"], 1001, phase=90)
assert actual == scalar_actual
assert list_generator._device.mock_calls == scalar_generator._device.mock_calls