Skip to content

Commit

Permalink
#34 - implemented channel input impedance and coupling
Browse files Browse the repository at this point in the history
  • Loading branch information
crnbaker committed Oct 13, 2023
1 parent ebc55cd commit aed68da
Show file tree
Hide file tree
Showing 12 changed files with 120 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/example_scripts/continuous_averaging_fifo_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ExternalTriggerMode,
TriggerSettings,
AcquisitionSettings,
InputImpedance,
)


Expand Down Expand Up @@ -56,6 +57,7 @@ def continuous_averaging_multi_fifo_example(
enabled_channels=[0],
vertical_ranges_in_mv=[200],
vertical_offsets_in_percent=[0],
input_impedances=[InputImpedance.ONE_MEGA_OHM],
timestamping_enabled=True,
number_of_averages=num_averages,
)
Expand Down
2 changes: 2 additions & 0 deletions src/example_scripts/continuous_multi_fifo_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ExternalTriggerMode,
TriggerSettings,
AcquisitionSettings,
InputImpedance,
)


Expand Down Expand Up @@ -56,6 +57,7 @@ def continuous_multi_fifo_example(
enabled_channels=[0],
vertical_ranges_in_mv=[200],
vertical_offsets_in_percent=[0],
input_impedances=[InputImpedance.ONE_MEGA_OHM],
timestamping_enabled=True,
batch_size=batch_size,
)
Expand Down
2 changes: 2 additions & 0 deletions src/example_scripts/finite_multi_fifo_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
ExternalTriggerMode,
TriggerSettings,
AcquisitionSettings,
InputImpedance,
)


Expand Down Expand Up @@ -54,6 +55,7 @@ def finite_multi_fifo_example(
enabled_channels=[0],
vertical_ranges_in_mv=[200],
vertical_offsets_in_percent=[0],
input_impedances=[InputImpedance.ONE_MEGA_OHM],
timestamping_enabled=True,
batch_size=batch_size,
)
Expand Down
2 changes: 2 additions & 0 deletions src/example_scripts/standard_single_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ExternalTriggerMode,
TriggerSettings,
AcquisitionSettings,
InputImpedance,
)


Expand Down Expand Up @@ -54,6 +55,7 @@ def standard_single_mode_example(
enabled_channels=[0],
vertical_ranges_in_mv=[200],
vertical_offsets_in_percent=[0],
input_impedances=[InputImpedance.ONE_MEGA_OHM],
timestamping_enabled=True,
)

Expand Down
6 changes: 4 additions & 2 deletions src/example_scripts/star_hub_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
ExternalTriggerMode,
AcquisitionMode,
AcquisitionSettings,
InputImpedance,
)


Expand Down Expand Up @@ -67,8 +68,9 @@ def connect_to_star_hub_example(
pre_trigger_length_in_samples=0,
timeout_in_ms=1000,
enabled_channels=[0, 8], # at least 1 channel from each child card must be enabled
vertical_ranges_in_mv=[200],
vertical_offsets_in_percent=[0],
vertical_ranges_in_mv=[200, 200],
vertical_offsets_in_percent=[0, 0],
input_impedances=[InputImpedance.ONE_MEGA_OHM, InputImpedance.ONE_MEGA_OHM],
timestamping_enabled=True,
batch_size=5,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,22 @@ def configure_acquisition(self, settings: AcquisitionSettings) -> None:
)
self.set_timeout_in_ms(settings.timeout_in_ms)
self.set_enabled_channels(settings.enabled_channels)
for channel, v_range, v_offset in zip(
self.channels, settings.vertical_ranges_in_mv, settings.vertical_offsets_in_percent

# Apply channel dependent settings
for channel, v_range, v_offset, impedance in zip(
self.channels,
settings.vertical_ranges_in_mv,
settings.vertical_offsets_in_percent,
settings.input_impedances,
):
cast(SpectrumDigitiserChannel, channel).set_vertical_range_in_mv(v_range)
cast(SpectrumDigitiserChannel, channel).set_vertical_offset_in_percent(v_offset)
cast(SpectrumDigitiserChannel, channel).set_input_impedance(impedance)

# Only some hardware has software programmable input coupling, so coupling can be None
if settings.input_couplings is not None:
for channel, coupling in zip(self.channels, settings.input_couplings):
cast(SpectrumDigitiserChannel, channel).set_input_coupling(coupling)

# Write the configuration to the card
self.write_to_spectrum_device_register(SPC_M2CMD, M2CMD_CARD_WRITESETUP)
Expand Down
26 changes: 22 additions & 4 deletions src/spectrumdevice/devices/digitiser/digitiser_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@
)
from spectrumdevice.exceptions import SpectrumCardIsNotADigitiser
from spectrumdevice.settings.card_dependent_properties import CardType
from spectrumdevice.settings.channel import INPUT_IMPEDANCE_COMMANDS, InputImpedance, VERTICAL_OFFSET_COMMANDS, \
VERTICAL_RANGE_COMMANDS
from spectrumdevice.settings.channel import (
INPUT_IMPEDANCE_COMMANDS,
InputImpedance,
VERTICAL_OFFSET_COMMANDS,
VERTICAL_RANGE_COMMANDS,
InputCoupling,
INPUT_COUPLING_COMMANDS,
)


class SpectrumDigitiserChannel(AbstractSpectrumChannel, SpectrumDigitiserChannelInterface):
Expand Down Expand Up @@ -90,5 +96,17 @@ def input_impedance(self) -> InputImpedance:
return InputImpedance(impedance_binary_value)

def set_input_impedance(self, input_impedance: InputImpedance) -> None:
self._parent_device.write_to_spectrum_device_register(INPUT_IMPEDANCE_COMMANDS[self._number],
input_impedance.value)
self._parent_device.write_to_spectrum_device_register(
INPUT_IMPEDANCE_COMMANDS[self._number], input_impedance.value
)

@property
def input_coupling(self) -> InputCoupling:
"""The current input impedance setting of the channel (50 Ohm or 1 MOhm)"""
coupling_binary_value = self._parent_device.read_spectrum_device_register(INPUT_COUPLING_COMMANDS[self._number])
return InputCoupling(coupling_binary_value)

def set_input_coupling(self, input_coupling: InputCoupling) -> None:
self._parent_device.write_to_spectrum_device_register(
INPUT_COUPLING_COMMANDS[self._number], input_coupling.value
)
11 changes: 10 additions & 1 deletion src/spectrumdevice/devices/digitiser/digitiser_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from spectrumdevice.devices.abstract_device import SpectrumChannelInterface, SpectrumDeviceInterface
from spectrumdevice.settings import AcquisitionMode, AcquisitionSettings
from spectrumdevice import Measurement
from spectrumdevice.settings.channel import InputImpedance
from spectrumdevice.settings.channel import InputImpedance, InputCoupling


class SpectrumDigitiserChannelInterface(SpectrumChannelInterface, ABC):
Expand Down Expand Up @@ -52,6 +52,15 @@ def input_impedance(self) -> InputImpedance:
def set_input_impedance(self, input_impedance: InputImpedance) -> None:
raise NotImplementedError()

@property
@abstractmethod
def input_coupling(self) -> InputCoupling:
raise NotImplementedError()

@abstractmethod
def set_input_coupling(self, input_coupling: InputCoupling) -> None:
raise NotImplementedError()


class SpectrumDigitiserInterface(SpectrumDeviceInterface, ABC):
"""Defines the public interface for control of all Spectrum digitiser devices, be they StarHub composite devices
Expand Down
4 changes: 3 additions & 1 deletion src/spectrumdevice/settings/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

from spectrumdevice.settings.card_dependent_properties import ModelNumber
from spectrumdevice.settings.card_features import CardFeature, AdvancedCardFeature
from spectrumdevice.settings.channel import InputImpedance
from spectrumdevice.settings.channel import InputImpedance, InputCoupling
from spectrumdevice.settings.device_modes import AcquisitionMode, ClockMode
from spectrumdevice.settings.io_lines import IOLineMode, AvailableIOModes
from spectrumdevice.settings.transfer_buffer import (
Expand Down Expand Up @@ -87,6 +87,8 @@ class AcquisitionSettings:
SpectrumDigitiserCard.get_waveforms()."""
number_of_averages: int = 1
"""If an averaging AcquisitionMode is selected, this defines the number of averages."""
input_couplings: Optional[List[InputCoupling]] = None
"""The coupling (AC or DC) to apply to each channel. Only available on some hardware, so default is None."""


class SpectrumRegisterLength(Enum):
Expand Down
53 changes: 51 additions & 2 deletions src/spectrumdevice/settings/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
SPCM_STOPLVL_HOLDLAST,
SPCM_STOPLVL_LOW,
SPCM_STOPLVL_ZERO,
SPC_50OHM0, SPC_50OHM1, SPC_50OHM10, SPC_50OHM11, SPC_50OHM12, SPC_50OHM13, SPC_50OHM14, SPC_50OHM15, SPC_50OHM2,
SPC_50OHM0,
SPC_50OHM1,
SPC_50OHM10,
SPC_50OHM11,
SPC_50OHM12,
SPC_50OHM13,
SPC_50OHM14,
SPC_50OHM15,
SPC_50OHM2,
SPC_50OHM3,
SPC_50OHM4,
SPC_50OHM5,
Expand Down Expand Up @@ -101,6 +109,22 @@
CHANNEL13,
CHANNEL14,
CHANNEL15,
SPC_ACDC0,
SPC_ACDC1,
SPC_ACDC2,
SPC_ACDC3,
SPC_ACDC4,
SPC_ACDC5,
SPC_ACDC6,
SPC_ACDC7,
SPC_ACDC8,
SPC_ACDC9,
SPC_ACDC10,
SPC_ACDC11,
SPC_ACDC12,
SPC_ACDC13,
SPC_ACDC14,
SPC_ACDC15,
)

VERTICAL_RANGE_COMMANDS = (
Expand Down Expand Up @@ -251,4 +275,29 @@ class InputImpedance(Enum):
SPC_50OHM13,
SPC_50OHM14,
SPC_50OHM15,
)
)


class InputCoupling(Enum):
AC = 1
DC = 0


INPUT_COUPLING_COMMANDS = (
SPC_ACDC0,
SPC_ACDC1,
SPC_ACDC2,
SPC_ACDC3,
SPC_ACDC4,
SPC_ACDC5,
SPC_ACDC6,
SPC_ACDC7,
SPC_ACDC8,
SPC_ACDC9,
SPC_ACDC10,
SPC_ACDC11,
SPC_ACDC12,
SPC_ACDC13,
SPC_ACDC14,
SPC_ACDC15,
)
6 changes: 3 additions & 3 deletions src/tests/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ class SpectrumTestMode(Enum):

# Set to TestMode.MOCK_HARDWARE for software-only testing, even if Spectrum drivers are found on the system
# Set to TestMode.REAL_HARDWARE to run tests on a real hardware device as configured below.
SINGLE_CARD_TEST_MODE = SpectrumTestMode.MOCK_HARDWARE
STAR_HUB_TEST_MODE = SpectrumTestMode.MOCK_HARDWARE
SINGLE_CARD_TEST_MODE = SpectrumTestMode.REAL_HARDWARE
STAR_HUB_TEST_MODE = SpectrumTestMode.REAL_HARDWARE

# Set IP address of real spectrum device (for use if TestMode.REAL_HARDWARE is set above). Set to None to run tests on
# a local (PCIe) card.
Expand All @@ -36,7 +36,7 @@ class SpectrumTestMode(Enum):
MOCK_DEVICE_TEST_FRAME_RATE_HZ = 10.0

# Trigger source to use for integration tests. Has no effect in SpectrumTestMode.MOCK_HARDWARE
INTEGRATION_TEST_TRIGGER_SOURCE = TriggerSource.SPC_TMASK_EXT0
INTEGRATION_TEST_TRIGGER_SOURCE = TriggerSource.SPC_TMASK_SOFTWARE


if SINGLE_CARD_TEST_MODE == SpectrumTestMode.REAL_HARDWARE and not SPECTRUM_DRIVERS_FOUND:
Expand Down
6 changes: 6 additions & 0 deletions src/tests/test_single_channel.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from unittest import TestCase

from spectrumdevice import SpectrumDigitiserChannel
from spectrumdevice.settings import InputImpedance
from tests.device_factories import create_spectrum_card_for_testing


Expand All @@ -21,3 +22,8 @@ def test_vertical_offset(self) -> None:
offset = 1
self._channel.set_vertical_offset_in_percent(offset)
self.assertEqual(offset, self._channel.vertical_offset_in_percent)

def test_input_impedance(self) -> None:
impedance = InputImpedance.ONE_MEGA_OHM
self._channel.set_input_impedance(impedance)
self.assertEqual(impedance, self._channel.input_impedance)

0 comments on commit aed68da

Please sign in to comment.