KCL-BMEIS / spectrumdevice

Python library for communicating with digitisers manufactured by Spectrum Instrumentation
MIT License
6 stars 2 forks source link

Implement synchronous digital outputs for AWG #40

Open crnbaker opened 9 months ago

crnbaker commented 9 months ago

from the M2p-65xx AWG manual: "This mode allows the user to replay up to four additional digital channels that are synchronous and phase stable along with the analog data."

The digital waveform must be encoded in the analog samples like this:

def write_digital_waveform_to_bit_15_of_analog(

    digital_waveform: NDArray[bool_], analog_waveform: NDArray[int16]

) -> NDArray[int16]:

    if analog_waveform.shape != digital_waveform.shape:

        raise ValueError("Analog and digital waveforms must have the same shape.")

    analog_waveform &= ~1  # Clear the least significant bit

    analog_waveform |= digital_waveform.astype(int16)  # Set the least significant bit using bitwise OR

    return analog_waveform

and then the mode enabled something like this:

analog_waveform = write_digital_waveform_to_bit_15_of_analog(digital_wfm, analog_wfm)
card.io_lines[0].set_mode(IOLineMode.SPCM_XMODE_DIGOUT)

card.io_lines[0].set_dig_out_settings(
    
DigOutIOLineModeSettings(

        source_channel=DigOutSourceChannel.SPCM_XMODE_DIGOUTSRC_CH0,
        source_bit=DigOutSourceBit.SPCM_XMODE_DIGOUTSRC_BIT15,

     )
)