-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #45 from KCL-BMEIS/42_pulse_gen
Pulse generator function
- Loading branch information
Showing
32 changed files
with
1,651 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
src/example_scripts/trigger_awg_with_pulse_generator_example.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from time import sleep | ||
|
||
from numpy import int16 | ||
|
||
from spectrumdevice.devices.awg.awg_card import SpectrumAWGCard | ||
from spectrumdevice.devices.awg.synthesis import make_full_scale_sine_waveform | ||
from spectrumdevice.settings import TriggerSettings, TriggerSource, ExternalTriggerMode, IOLineMode | ||
from spectrumdevice.settings.channel import OutputChannelStopLevelMode | ||
from spectrumdevice.settings.device_modes import GenerationMode | ||
from spectrumdevice.settings.pulse_generator import ( | ||
PulseGeneratorOutputSettings, | ||
PulseGeneratorTriggerSettings, | ||
PulseGeneratorTriggerMode, | ||
PulseGeneratorTriggerDetectionMode, | ||
PulseGeneratorMultiplexer1TriggerSource, | ||
PulseGeneratorMultiplexer2TriggerSource, | ||
) | ||
|
||
|
||
SAMPLE_RATE = 40000000 | ||
|
||
|
||
if __name__ == "__main__": | ||
|
||
card = SpectrumAWGCard(device_number=0) | ||
|
||
card_trigger_settings = TriggerSettings( | ||
trigger_sources=[TriggerSource.SPC_TMASK_EXT2], # ext1 trigger source is first IOLine | ||
external_trigger_mode=ExternalTriggerMode.SPC_TM_POS, | ||
) | ||
|
||
t, analog_wfm = make_full_scale_sine_waveform( | ||
frequency_in_hz=1e6, sample_rate_hz=SAMPLE_RATE, num_cycles=1, dtype=int16 | ||
) | ||
|
||
# Set up AWG card | ||
card.configure_trigger(card_trigger_settings) | ||
card.set_sample_rate_in_hz(SAMPLE_RATE) | ||
card.set_generation_mode(GenerationMode.SPC_REP_STD_SINGLERESTART) | ||
card.set_num_loops(1) | ||
card.transfer_waveform(analog_wfm) | ||
card.analog_channels[0].set_stop_level_mode(OutputChannelStopLevelMode.SPCM_STOPLVL_ZERO) | ||
card.analog_channels[0].set_is_switched_on(True) | ||
card.analog_channels[0].set_signal_amplitude_in_mv(1000) | ||
|
||
pulse_trigger_settings = PulseGeneratorTriggerSettings( | ||
trigger_mode=PulseGeneratorTriggerMode.SPCM_PULSEGEN_MODE_SINGLESHOT, | ||
trigger_detection_mode=PulseGeneratorTriggerDetectionMode.RISING_EDGE, | ||
multiplexer_1_source=PulseGeneratorMultiplexer1TriggerSource.SPCM_PULSEGEN_MUX1_SRC_UNUSED, | ||
multiplexer_1_output_inversion=False, | ||
multiplexer_2_source=PulseGeneratorMultiplexer2TriggerSource.SPCM_PULSEGEN_MUX2_SRC_SOFTWARE, | ||
multiplexer_2_output_inversion=False, | ||
) | ||
|
||
pulse_output_settings = PulseGeneratorOutputSettings( | ||
period_in_seconds=1e-3, duty_cycle=0.5, num_pulses=10, delay_in_seconds=0.0, output_inversion=False | ||
) | ||
|
||
card.io_lines[0].set_mode(IOLineMode.SPCM_XMODE_PULSEGEN) | ||
card.io_lines[0].pulse_generator.configure_trigger(pulse_trigger_settings) | ||
card.io_lines[0].pulse_generator.configure_output(pulse_output_settings) | ||
|
||
card.start() | ||
|
||
card.io_lines[0].pulse_generator.force_trigger() | ||
sleep(1) | ||
card.stop() | ||
card.disconnect() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/spectrumdevice/devices/abstract_device/channel_interfaces.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
"""Defines a common public interface for controlling all Spectrum devices and their channels.""" | ||
|
||
# Christian Baker, King's College London | ||
# Copyright (c) 2021 School of Biomedical Engineering & Imaging Sciences, King's College London | ||
# Licensed under the MIT. You may obtain a copy at https://opensource.org/licenses/MIT. | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import TypeVar, Generic | ||
|
||
from spectrumdevice.features.pulse_generator.interfaces import PulseGeneratorInterface | ||
from spectrumdevice.settings import ( | ||
SpectrumRegisterLength, | ||
IOLineMode, | ||
) | ||
from spectrumdevice.settings.channel import SpectrumAnalogChannelName, SpectrumChannelName | ||
from spectrumdevice.settings.io_lines import SpectrumIOLineName | ||
|
||
ChannelNameType = TypeVar("ChannelNameType", bound=SpectrumChannelName) | ||
|
||
|
||
class SpectrumChannelInterface(Generic[ChannelNameType], ABC): | ||
"""Defines the common public interface for control of the channels of Digitiser and AWG devices including | ||
Multipurpose IO Lines. All properties are read-only and must be set with their respective setter methods.""" | ||
|
||
@property | ||
@abstractmethod | ||
def name(self) -> ChannelNameType: | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def write_to_parent_device_register( | ||
self, | ||
spectrum_register: int, | ||
value: int, | ||
length: SpectrumRegisterLength = SpectrumRegisterLength.THIRTY_TWO, | ||
) -> None: | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def read_parent_device_register( | ||
self, | ||
spectrum_register: int, | ||
length: SpectrumRegisterLength = SpectrumRegisterLength.THIRTY_TWO, | ||
) -> int: | ||
raise NotImplementedError() | ||
|
||
|
||
class SpectrumAnalogChannelInterface(SpectrumChannelInterface[SpectrumAnalogChannelName], ABC): | ||
"""Defines the common public interface for control of the analog channels of Digitiser and AWG devices. All | ||
properties are read-only and must be set with their respective setter methods.""" | ||
|
||
pass | ||
|
||
|
||
class SpectrumIOLineInterface(SpectrumChannelInterface[SpectrumIOLineName], ABC): | ||
"""Defines the common public interface for control of the Multipurpose IO Lines of Digitiser and AWG devices. All | ||
properties are read-only and must be set with their respective setter methods.""" | ||
|
||
@property | ||
@abstractmethod | ||
def mode(self) -> IOLineMode: | ||
"""Returns the current mode of the IO Line.""" | ||
raise NotImplementedError() | ||
|
||
@abstractmethod | ||
def set_mode(self, mode: IOLineMode) -> None: | ||
"""Sets the current mode of the IO Line""" | ||
raise NotImplementedError() | ||
|
||
@property | ||
@abstractmethod | ||
def pulse_generator(self) -> PulseGeneratorInterface: | ||
"""Gets the IO line's pulse generator.""" | ||
raise NotImplementedError() |
Oops, something went wrong.