2
0
forked from awendt/pyrelacs

adding doc string

This commit is contained in:
wendtalexander 2024-09-27 19:22:58 +02:00
parent bdd323ad20
commit e9a509c0f7

View File

@ -227,13 +227,13 @@ class MccDac:
def digital_trigger(self, ch: int = 0) -> None: def digital_trigger(self, ch: int = 0) -> None:
""" """
Digital Writes a 1 to a specified digital channel, if the channel is already on 1 switches it to
0 and after Nanosekond it writes a 1 to the specified digital channel
Parameters Parameters
---------- ----------
ch : int ch : int
Channel to trigger
""" """
data = self.read_bit(channel=ch) data = self.read_bit(channel=ch)
if data: if data:
@ -244,6 +244,18 @@ class MccDac:
self.write_bit(channel=ch, bit=1) self.write_bit(channel=ch, bit=1)
def write_bit(self, channel: int = 0, bit: int = 1) -> None: def write_bit(self, channel: int = 0, bit: int = 1) -> None:
"""
Writes a 0 / 1 to a specified digitial channel
Parameters
----------
channel : int
Digital channel to write
bit : int
0 / 1 for writing to the digital channel
"""
self.dio_device.d_config_bit( self.dio_device.d_config_bit(
uldaq.DigitalPortType.AUXPORT, channel, uldaq.DigitalDirection.OUTPUT uldaq.DigitalPortType.AUXPORT, channel, uldaq.DigitalDirection.OUTPUT
) )
@ -251,55 +263,36 @@ class MccDac:
uldaq.DigitalPortType.AUXPORT, bit_number=channel, data=bit uldaq.DigitalPortType.AUXPORT, bit_number=channel, data=bit
) )
def read_bit(self, channel: int = 0): def read_bit(self, channel: int = 0) -> int:
bit = self.dio_device.d_bit_in(uldaq.DigitalPortType.AUXPORT, channel) """
return bit Reads a 0 / 1 from the specified digital channel
def read_digitalio(
self,
channels: list[int],
duration,
samplerate,
ScanOptions: uldaq.ScanOption = uldaq.ScanOption.DEFAULTIO,
DInScanFlag: uldaq.DInScanFlag = uldaq.DInScanFlag.DEFAULT,
):
if channels[0] == channels[1]:
channel_len = 1
else:
channel_len = len(channels)
buffer_len = np.shape(np.arange(0, duration, 1 / samplerate))[0] Parameters
data_digital_input = uldaq.create_int_buffer(channel_len, buffer_len) ----------
channel : int
Digital channel to read from
self.dio_device.d_config_port( Returns
uldaq.DigitalPortType.AUXPORT, uldaq.DigitalDirection.INPUT -------
) bit : int
scan_rate = self.dio_device.d_in_scan( 0 or 1 from the digital channel
uldaq.DigitalPortType.AUXPORT0, """
uldaq.DigitalPortType.AUXPORT0, bit = self.dio_device.d_bit_in(uldaq.DigitalPortType.AUXPORT, channel)
len(data_digital_input), return bit
samplerate,
ScanOptions,
DInScanFlag,
data_digital_input,
)
return data_digital_input
def disconnect_dac(self): def disconnect_dac(self):
self.daq_device.disconnect() self.daq_device.disconnect()
self.daq_device.release() self.daq_device.release()
def check_attenuator(self): def check_attenuator(self) -> None:
"""
ident : attdev-1
strobepin : 6
datainpin : 5
dataoutpin: -1
cspin : 4
mutepin : 7
zcenpin : -1
""" """
For checking the attenuator in the DAC device that was implemented to attenuate the
analog signal to mV.
Writes to Channel 0 of the analog output with different attenuation levels
0, 0, -2, -5, -10, -20, -50 dB and the second 0 has a software mute
"""
SAMPLERATE = 40_000.0 SAMPLERATE = 40_000.0
DURATION = 5 DURATION = 5
AMPLITUDE = 1 AMPLITUDE = 1
@ -309,7 +302,6 @@ class MccDac:
# data_channels = np.concatenate((data, data)) # data_channels = np.concatenate((data, data))
db_values = [0, 0, -2, -5, -10, -20, -50] db_values = [0, 0, -2, -5, -10, -20, -50]
db_values = [0, -10, -20]
for i, db_value in enumerate(db_values): for i, db_value in enumerate(db_values):
log.info(f"Attenuating the Channels, with {db_value}") log.info(f"Attenuating the Channels, with {db_value}")
if i == 1: if i == 1:
@ -327,7 +319,7 @@ class MccDac:
ScanOption=uldaq.ScanOption.EXTTRIGGER, ScanOption=uldaq.ScanOption.EXTTRIGGER,
Range=uldaq.Range.BIP10VOLTS, Range=uldaq.Range.BIP10VOLTS,
) )
self.diggital_trigger() self.digital_trigger()
try: try:
self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15) self.ao_device.scan_wait(uldaq.WaitType.WAIT_UNTIL_DONE, 15)
@ -356,6 +348,16 @@ class MccDac:
mute_channel2: bool = False, mute_channel2: bool = False,
): ):
""" """
Setting the attenuation level of the chip that is connected to the DAQ
The attenuation level is set by writing to the connected digital output pin 5
where the strobepin 6 is signaling the when the bit was send.
The cspin is set from 1 to 0 for the start and 0 to 1 for signaling the end
of the data write process.
The mute pin should be set to 1 for the device to be working.
More information in the AttCS3310.pdf in the doc
ident : attdev-1 ident : attdev-1
strobepin : 6 strobepin : 6
datainpin : 5 datainpin : 5
@ -363,8 +365,23 @@ class MccDac:
cspin : 4 cspin : 4
mutepin : 7 mutepin : 7
zcenpin : -1 zcenpin : -1
"""
Parameters
----------
db_channel1 : float
dB Attenuation level for the first channel
db_channel2 : float
dB Attenuation level for the second channel
mute_channel1 : bool
Software mute for the first channel
mute_channel2 : bool
Software mute for the second channel
"""
self.activate_attenuator() self.activate_attenuator()
hardware_possible_db = np.arange(-95.5, 32.0, 0.5) hardware_possible_db = np.arange(-95.5, 32.0, 0.5)
byte_number = np.arange(1, 256) byte_number = np.arange(1, 256)
@ -391,9 +408,18 @@ class MccDac:
self.write_bit(channel=4, bit=1) self.write_bit(channel=4, bit=1)
def activate_attenuator(self): def activate_attenuator(self):
"""
Activation of the attenuator, where the cspin and mute pin is set to 1,
and the datapin and strobpin to 0
"""
for ch, b in zip([4, 5, 6, 7], [1, 0, 0, 1]): for ch, b in zip([4, 5, 6, 7], [1, 0, 0, 1]):
self.write_bit(channel=ch, bit=b) self.write_bit(channel=ch, bit=b)
def deactivate_attenuator(self): def deactivate_attenuator(self):
"""
Writes a 0 to the mute pin, which is deactivating the attenuator
"""
# mute should be enabled for starting calibration # mute should be enabled for starting calibration
self.write_bit(channel=7, bit=0) self.write_bit(channel=7, bit=0)