Examples#

single_replay_mode.py#

An example of using single replay mode. If external reference clock is used, set USE_EXTERNAL_CLOCK to True, and set the EXTERNAL_REF_FREQUENCY to the reference clock frequency.

from spcm.spcm import DrvHandle, GatedReplayMode, SingleReplayMode, SingleReplayRestartMode
import matplotlib.pyplot as plt
from spcm.py_header.regs import *
import time
import numpy as np
from spcm.enums import *
from scipy.constants import *

USE_EXTERNAL_CLOCK = True
EXTERNAL_REF_FREQUENCY = int(10 * mega)

d = SingleReplayMode("/dev/spcm0")

# verbose information
print("Card Name:", d.card_name)
print("Driver Version:", d.driver_version)
print("Sample Rate [Hz]:", d.sample_rate)

if USE_EXTERNAL_CLOCK:
    d.clock_mode = SPC_CM.SPC_CM_EXTREFCLOCK
    d.reference_clock = EXTERNAL_REF_FREQUENCY

# infinitely replay
d.loops = 0

# enable channel 0
d.enable_output(0)

# 1 ms time sequence
t = d.make_time_series(1 * milli)

# 20 MHz signal
v = np.cos(2 * np.pi * 20 * mega * t)
v = v * (2 ** 15 - 1)
v = v.astype(np.int16)

d.transfer_data(v)

d.start()

single_replay_mode_dual_channel.py#

from spcm.spcm import DrvHandle, GatedReplayMode, SingleReplayMode, SingleReplayRestartMode
import matplotlib.pyplot as plt
from spcm.py_header.regs import *
import time
import numpy as np
from spcm.enums import *
from scipy.constants import *

USE_EXTERNAL_CLOCK = True
EXTERNAL_REF_FREQUENCY = int(10 * mega)

# use channel 0 and 1
d = SingleReplayMode("/dev/spcm0", channels=(0, 1))

# verbose information
print("Card Name:", d.card_name)
print("Driver Version:", d.driver_version)
print("Sample Rate [Hz]:", d.sample_rate)

if USE_EXTERNAL_CLOCK:
    d.clock_mode = SPC_CM.SPC_CM_EXTREFCLOCK
    d.reference_clock = EXTERNAL_REF_FREQUENCY

# infinitely replay
d.loops = 0

# enable channel 0 amd 1
d.enable_output(0)
d.enable_output(1)

# 1 ms time sequence
t = d.make_time_series(1 * milli)

# 20 MHz signal for channel 0
v0 = np.cos(2 * np.pi * 20 * mega * t)
v0 = v0 * (2 ** 15 - 1)
v0 = v0.astype(np.int16)

# 20 MHz signal for channel 1
v1 = np.cos(2 * np.pi * 10 * mega * t)
v1 = v1 * (2 ** 15 - 1)
v1 = v1.astype(np.int16)

v = [v0, v1]  # from small to large channel number

d.transfer_data(v)
print(d.ch_count)
d.start()

single_replay_mode_digital_output#

This example shows how to use the digital output of the AWG.

from spcm.spcm import DrvHandle, GatedReplayMode, SingleReplayMode, SingleReplayRestartMode
import matplotlib.pyplot as plt
from spcm.py_header.regs import *
import time
import numpy as np
from spcm.enums import *
from scipy.constants import *

USE_EXTERNAL_CLOCK = True
EXTERNAL_REF_FREQUENCY = int(10 * mega)

# use channel 0 and 1
d = SingleReplayMode("/dev/spcm0", channels=(0, 1))

# verbose information
print("Card Name:", d.card_name)
print("Driver Version:", d.driver_version)
print("Sample Rate [Hz]:", d.sample_rate)

if USE_EXTERNAL_CLOCK:
    d.clock_mode = SPC_CM.SPC_CM_EXTREFCLOCK
    d.reference_clock = EXTERNAL_REF_FREQUENCY

# infinitely replay
d.loops = 0

# enable channel 0 amd 1
d.enable_output(0)
d.enable_output(1)

# 1 ms time sequence
t = d.make_time_series(1 * milli)

# 20 MHz signal for channel 0
v0 = np.cos(2 * np.pi * 20 * mega * t)
v0 = v0 * (2 ** 15 - 1)
v0 = v0.astype(np.int16)

# 10 MHz signal for channel 1
v1 = np.cos(2 * np.pi * 10 * mega * t)
v1 = v1 * (2 ** 15 - 1)
v1 = v1.astype(np.int16)

v = [v0, v1]  # from small to large channel number

# 20 Mhz chopping
v0_digital = v0 > 0

# Configure the digital output
d.x1_mode = SPCM_XMODE.SPCM_XMODE_DIGOUT | SPCM_XMODE.SPCM_XMODE_DIGOUTSRC_CH1 | SPCM_XMODE.SPCM_XMODE_DIGOUTSRC_BIT15

d.transfer_data(v, [v0_digital])
d.start()