From 387ce96b1140251d3188fe1a7b98c8746dee279e Mon Sep 17 00:00:00 2001 From: Gijs Schoonderbeek <schoonderbeek@astron.nl> Date: Fri, 6 Jan 2023 17:39:05 +0100 Subject: [PATCH] small modification to get is working on HW --- apsct_lib.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/apsct_lib.py b/apsct_lib.py index 6eb00df..e306a62 100644 --- a/apsct_lib.py +++ b/apsct_lib.py @@ -26,7 +26,7 @@ else: I2CBUSNR = 5 sleep_time = 0.15 - +DEBUG = False class ApsctClass: # @@ -96,6 +96,9 @@ class ApsctClass: self.power(False) def check_apsct(self): + # + # Check voltages, temp and lock on APSCT + # result = self.sensors.check_values() if self.frequency == "200MHz": self.pll_200.read_lock() @@ -129,11 +132,12 @@ class PllClass: # Write Byte to the PLL # pll_rw = 0x00 # 0 for write, 1 for read - stri = "Write to address : 0x{1:{fill}2x} value 0x{0:{fill}2x}".format(wr_data, reg_address, fill='0') - print(stri) + if DEBUG: + stri = "Write to address : 0x{1:{fill}2x} value 0x{0:{fill}2x}".format(wr_data, reg_address, fill='0') + print(stri) self.dev_i2c_pll.write_bytes(0x06, 0x2C) + rd_bytes = self.dev_i2c_pll.read_bytes(0x06, 1) if DEBUG: - rd_bytes = self.dev_i2c_pll.read_bytes(0x06, 1) stri = "IO expander wrote 0x{0:x}, read 0x{1}".format(0x2C, rd_bytes[1]) print(stri) data = (reg_address << 9) + (pll_rw << 8) + wr_data @@ -188,6 +192,7 @@ class PllClass: # # Set registers on the PLL # + print(f"Setup PPL {self.frequency}") self.dev_i2c_pll.write_bytes(0x07, 0x00) if self.frequency == '160MHz': self.dev_i2c_pll.write_bytes(0x03, 0x08) @@ -367,17 +372,18 @@ class ApsctSensors: # # return result, True when OK, False in case of error # + print("Check power sensor values") result = True self.read_all_voltages() self.read_temp() for pwr in self.power_supplies: expected = APSCT_I2C.PWR_VOUT[pwr] - if 0.9*expected > self.voltages[pwr] > 1.1*expected: + if not (0.9*expected < self.voltages[pwr] < 1.1*expected): result = False - print(f"Error {pwr} expected {expected} V read {self.voltages[pwr]} V") - if 15 > self.temperature > 50: + print(f"Error: {pwr: <9} expected: {expected} V read: {self.voltages[pwr]:4.2f} V") + if not (15 < self.temperature < 50): result = False - print(f"Error temperature read {self.temperature} °C") + print(f"Error temperature read {self.temperature:4.2f} °C") return result def read_voltage(self, input_channel=0): @@ -394,7 +400,7 @@ class ApsctSensors: if DEBUG: stri = "Word to select sens input is 0x{0:x}".format(channel_select_word) print(stri) - sleep(0.1) + sleep(0.2) self.dev_i2c_sensor.write_bytes(channel_select_word, 0xB8) sleep(0.5) ret_ack, ret_value = self.dev_i2c_sensor.read_last_reg(3) @@ -407,8 +413,9 @@ class ApsctSensors: steps = (int(ret_value, 16) & 0x1FFFFF) >> 6 voltage = one_step * steps voltage = ((4.7+2.2)/2.2)*2*voltage - string = "Voltage sens line {1} is {0:.4f} V".format(voltage, input_channel) - print(string) + if DEBUG: + string = "Voltage sens line {1} is {0:.4f} V".format(voltage, input_channel) + print(string) return voltage def read_temp(self): -- GitLab