Skip to content

Commit

Permalink
ENH: started on test_configuration + hardware write read tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rpartzsch committed Dec 20, 2024
1 parent b655f6e commit c86a6f6
Show file tree
Hide file tree
Showing 7 changed files with 375 additions and 192 deletions.
39 changes: 39 additions & 0 deletions aidatlu/hardware/dac_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,42 @@ def _set_dac_value(self, channel: int, value: int, dac: int = 0) -> None:
self.i2c.write_array(self.i2c.modules["dac_1"], mem_addr, char)
if dac == 2:
self.i2c.write_array(self.i2c.modules["dac_2"], mem_addr, char)

def _get_thresholds_dac_value(self, trigger_channel: int) -> tuple | list:
"""Returns the values of the threshold DACs
Returns:
list | tuple: Threshold DAC values of the two threshold DACs
"""
channel = trigger_channel - 1 # shift channel number by 1
# calculates the DAC value for the threshold DAC

# Get threshold for the different channels. The different handling of the channels comes from the weird connections of the ADC.
if channel == 6:
return self._get_dac_value(channel + 1, 1), self._get_dac_value(
channel + 1, 2
)
# The DAC channels are connected in reverse order. The first two channels sit on DAC 1 in reverse order.
elif channel < 2:
return self._get_dac_value(1 - channel, 1)
# The last 4 channels sit on DAC 2 in reverse order.
elif channel > 1 and channel < 6:
return self._get_dac_value(3 - (channel - 2), 2)

def _get_dac_value(self, channel: int, dac: int = 0) -> int:
"""Get the output value of the power DAC
Args:
channel (int): DAC channel
dac (int): 0 is the power dac, 1 and 2 are DAC 1 and DAC 2 for the thresholds. Defaults to 0.
"""
if channel < 0 or channel > 7:
raise ValueError("Channel has to be between 0 and 7")

mem_addr = 0x18 + (channel & 0x7)
if dac == 0:
return self.i2c.read(self.i2c.modules["pwr_dac"], mem_addr)
if dac == 1:
return self.i2c.read(self.i2c.modules["dac_1"], mem_addr)
if dac == 2:
return self.i2c.read(self.i2c.modules["dac_2"], mem_addr)
2 changes: 1 addition & 1 deletion aidatlu/main/config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def get_data_handling(self) -> tuple:
tuple: two bools, save and interpret data.
"""

return self.conf["save_data"], self.conf["save_data"]
return self.conf["save_data"]

def get_stop_condition(self) -> tuple:
"""Information about tlu stop condition.
Expand Down
9 changes: 5 additions & 4 deletions aidatlu/main/tlu.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@
from aidatlu.hardware.trigger_controller import TriggerLogic
from aidatlu.main.config_parser import TLUConfigure
from aidatlu.main.data_parser import interpret_data
from aidatlu.test.utils import MockI2C


class AidaTLU:
def __init__(self, hw, config_path, clock_config_path) -> None:
self.log = logger.setup_main_logger(__class__.__name__)

self.i2c = I2CCore(hw)
# self.i2c = I2CCore(hw)
self.i2c = MockI2C(None)
self.i2c_hw = hw
self.log.info("Initializing IPbus interface")
self.i2c.init()
Expand Down Expand Up @@ -422,7 +424,7 @@ def run(self) -> None:
first_event = True
self.stop_condition = False
# prepare data handling and zmq connection
save_data, interpret_data_bool = self.config_parser.get_data_handling()
save_data = self.config_parser.get_data_handling()
self.zmq_address = self.config_parser.get_zmq_connection()
self.max_trigger, self.timeout = self.config_parser.get_stop_condition()

Expand Down Expand Up @@ -489,8 +491,8 @@ def run(self) -> None:

if save_data:
self.h5_file.close()
if interpret_data_bool:
interpret_data(self.raw_data_path, self.interpreted_data_path)

self.log.success("Run finished")


Expand All @@ -505,5 +507,4 @@ def run(self) -> None:
tlu = AidaTLU(hw, config_path, clock_path)

tlu.configure()

tlu.run()
Loading

0 comments on commit c86a6f6

Please sign in to comment.