forked from awendt/pyrelacs
68 lines
1.7 KiB
Python
68 lines
1.7 KiB
Python
import ctypes
|
|
import faulthandler
|
|
|
|
import time
|
|
|
|
import uldaq
|
|
from IPython import embed
|
|
import numpy as np
|
|
import matplotlib.pyplot as plt
|
|
|
|
from pyrelacs.repros.mccdac import MccDac
|
|
from pyrelacs.util.logging import config_logging
|
|
|
|
log = config_logging()
|
|
faulthandler.enable()
|
|
|
|
|
|
class Calibration(MccDac):
|
|
def __init__(self) -> None:
|
|
super().__init__()
|
|
|
|
def check_amplitude(self):
|
|
self.set_attenuation_level(db_channel1=0.0, db_channel2=0.0)
|
|
# write to ananlog 1
|
|
t = np.arange(0, DURATION, 1 / SAMPLERATE)
|
|
data = AMPLITUDE * np.sin(2 * np.pi * SINFREQ * t)
|
|
data_channels = np.zeros(2 * len(data))
|
|
# c = [(i,for i,j in zip(data, data)]
|
|
|
|
stim = self.write_analog(
|
|
data,
|
|
[0, 0],
|
|
SAMPLERATE,
|
|
ScanOption=uldaq.ScanOption.EXTTRIGGER,
|
|
)
|
|
data_channel_one = self.read_analog(
|
|
[0, 0], DURATION, SAMPLERATE, ScanOption=uldaq.ScanOption.EXTTRIGGER
|
|
)
|
|
time.sleep(1)
|
|
|
|
self.diggital_trigger()
|
|
|
|
try:
|
|
self.ai_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
|
|
self.write_bit(channel=0, bit=0)
|
|
time.sleep(1)
|
|
self.set_analog_to_zero()
|
|
except uldaq.ul_exception.ULException:
|
|
log.debug("Operation timed out")
|
|
# reset the diggital trigger
|
|
self.write_bit(channel=0, bit=0)
|
|
time.sleep(1)
|
|
self.set_analog_to_zero()
|
|
self.disconnect_dac()
|
|
embed()
|
|
exit()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
SAMPLERATE = 40_000.0
|
|
DURATION = 5
|
|
AMPLITUDE = 0.5
|
|
SINFREQ = 10
|
|
|
|
cal = Calibration()
|
|
# cal.ccheck_attenuator()
|
|
cal.check_amplitude()
|