Skip to content
Snippets Groups Projects

Apsct ad9511

1 file
+ 27
27
Compare changes
  • Side-by-side
  • Inline
+ 27
27
@@ -63,6 +63,7 @@ class ApsctClass:
stri = "Expander : 0x{:0>2x}, Reg 0x{:0>2x}, value 0x{}{}".format(addr, reg_cnt, ret_value[0],
ret_value[1]) # [start+2:start])
print(stri)
def read_all_io_device_registers(self, device, registers=8):
print(f"Read IO-expander at register 0x{device.I2C_Address:X}")
for register in range(registers):
@@ -93,9 +94,9 @@ class ApsctClass:
bits_to_set_a2 = 0x08
bits_to_set_b1 = 0x02 | (1 << APSCT_I2C.CS) | (0 << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
else:
bits_to_set_a1 = 0x00 # | (1 << APSCT_I2C.CS) | (0 << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
bits_to_set_a1 = 0x00 # | (1 << APSCT_I2C.CS) | (0 << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
bits_to_set_a2 = 0x00
bits_to_set_b1 = 0x00 # | (1 << APSCT_I2C.CS) | (0 << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
bits_to_set_b1 = 0x00 # | (1 << APSCT_I2C.CS) | (0 << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
i2c_io_device_a.write_bytes(0x02, bits_to_set_a1)
i2c_io_device_a.write_bytes(0x03, bits_to_set_a2)
i2c_io_device_b.write_bytes(0x02, bits_to_set_b1)
@@ -103,7 +104,6 @@ class ApsctClass:
self.read_all_io_device_registers(i2c_io_device_a)
self.read_all_io_device_registers(i2c_io_device_b)
def set_apsct(self):
#
# set APSCT to 200MHz, 160MHz or off
@@ -163,7 +163,7 @@ class PllClass:
write_data = 0x02 | (0 << APSCT_I2C.CS) | (0 << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
self.dev_i2c_pll.write_bytes(0x02, write_data)
for cnt in range(4):
for clk in [0,1,0]:
for clk in [0, 1, 0]:
write_data = 0x02 | (0 << APSCT_I2C.CS) | (clk << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
self.dev_i2c_pll.write_bytes(0x02, write_data)
sleep(sleep_time)
@@ -179,18 +179,18 @@ class PllClass:
if DEBUG:
stri = "Write to address : 0x{1:{fill}2x} value 0x{0:{fill}2x}".format(wr_data, reg_address, fill='0')
print(stri)
rw_reg_pll = 0b00101101 # 1 is input
rw_reg_pll = 0b00101101 # 1 is input
self.dev_i2c_pll.write_bytes(0x06, rw_reg_pll)
rd_bytes = self.dev_i2c_pll.read_bytes(0x06, 1)
if DEBUG:
stri = "IO expander wrote 0x{0:x}, read 0x{1}".format(rw_reg_pll, rd_bytes[1])
print(stri)
nof_bytes = 1
data = (pll_rw << 23) + ((nof_bytes-1) << 21) + (reg_address << 8) + wr_data
data = (pll_rw << 23) + ((nof_bytes-1) << 21) + (reg_address << 8) + wr_data
bit_array = "{0:{fill}24b}".format(data, fill='0')
self.dev_i2c_pll.write_bytes(0x02, 0x02 | (0x1 << APSCT_I2C.CS))
for bit in bit_array:
for clk in [0, 1, 0]: #range(2):
for clk in [0, 1, 0]: # range(2):
write_data = 0x02 | (0 << APSCT_I2C.CS) | (clk << APSCT_I2C.SCLK) | (int(bit) << APSCT_I2C.SDI)
self.dev_i2c_pll.write_bytes(0x02, write_data)
sleep(sleep_time)
@@ -212,13 +212,13 @@ class PllClass:
self.dev_i2c_pll.write_bytes(0x02, write_data)
sleep(sleep_time)
for bit in bit_array:
for clk in [0,1,0]:
for clk in [0, 1, 0]:
write_data = 0x02 | (0 << APSCT_I2C.CS) | (clk << APSCT_I2C.SCLK) | (int(bit) << APSCT_I2C.SDI)
self.dev_i2c_pll.write_bytes(0x02, write_data)
sleep(sleep_time)
self.dev_i2c_pll.write_bytes(0x06, 0xAC)
for cnt in range(8*nof_bytes):
for clk in [0, 1]: #[0, 1, 0]: # Read after rizing edge
for clk in [0, 1]: # Read after rizing edge
write_data = 0x02 | (0 << APSCT_I2C.CS) | (clk << APSCT_I2C.SCLK) | (0 << APSCT_I2C.SDI)
self.dev_i2c_pll.write_bytes(0x02, write_data)
sleep(sleep_time)
@@ -257,7 +257,7 @@ class PllClass:
dev_i2c_pll_sel.write_bytes(0x03, 0x08)
else:
self.dev_i2c_pll.write_bytes(0x03, 0x28)
self.write_byte_pll(0x04, 1) #(divider_a & 0x3F))
self.write_byte_pll(0x04, (divider_a & 0x3F))
self.write_byte_pll(0x05, (divider_b & 0x1F00) >> 8)
self.write_byte_pll(0x06, (divider_b & 0x00FF))
self.write_byte_pll(0x07, 0x00) # No LOR
@@ -279,7 +279,6 @@ class PllClass:
self.write_byte_pll(0x53, 0x80) # OUT4 bypass divider
self.write_byte_pll(0x5A, 0x0F) # Update registers
def read_all_regs_pll(self):
#
# Read all registers on the PLL and print on screen
@@ -290,7 +289,7 @@ class PllClass:
stri = f"Reg nr 0x{cnt:0>2x} value: 0x{ret_value:0>2x}"
print(stri)
def read_lock(self, print_on=True):
def read_lock(self):
#
# Read lock status
#
@@ -302,7 +301,7 @@ class PllClass:
i2_c_io_device.write_bytes(0x07, 0x00) # '0' is output
ack, ret_value = i2_c_io_device.read_bytes(0x00, 1)
status_pll = int(ret_value, 16) & 0x04
if status_pll :
if status_pll:
self.lock = True
stri = f"PLL {self.frequency} is in lock"
else:
@@ -323,11 +322,11 @@ class PllClass:
i2_c_io_device_b.write_bytes(0x07, 0xFF) # '0' is output
ack, ret_value = i2_c_io_device_b.read_bytes(0x01, 1)
status_reg = int(ret_value, 16)
if (self.frequency == '200MHz'):
if self.frequency == '200MHz':
lol = (status_reg & 0x10)
else:
lol = (status_reg & 0x20)
if lol :
if lol:
print(f"{self.frequency} has lost lock")
ack, ret_value = i2_c_io_device_a.read_bytes(0x01, 1)
old_reg = int(ret_value, 16)
@@ -426,7 +425,7 @@ class ApsctSensors:
self.read_temp()
return True
def read_all_avg_voltages(self, avg_nr = 6):
def read_all_avg_voltages(self, avg_nr=6):
#
# Function to read and process one sensline
#
@@ -435,22 +434,22 @@ class ApsctSensors:
# To remove errors, repeat measurement when returned voltage is < 3 V
#
self.read_all_voltages()
sum_values= {"INPUT": [],
"PLL_160M": [],
"PLL_200M": [],
"DIST_A": [],
"DIST_B": [],
"DIST_C": [],
"DIST_D": [],
"CTRL": []}
sum_values = {"INPUT": [],
"PLL_160M": [],
"PLL_200M": [],
"DIST_A": [],
"DIST_B": [],
"DIST_C": [],
"DIST_D": [],
"CTRL": []}
for cnt in range(avg_nr):
self.read_all_voltages()
for pwr in self.power_supplies:
sum_values[pwr].append( self.voltages[pwr])
sum_values[pwr].append(self.voltages[pwr])
for pwr in self.power_supplies:
median_value = np.median(sum_values[pwr])
if DEBUG:
print(f"Power {pwr} last value {self.voltages[pwr]:.2f} V median {median_value:.2f} V" )
print(f"Power {pwr} last value {self.voltages[pwr]:.2f} V median {median_value:.2f} V")
self.voltages[pwr] = median_value
def read_all_voltages(self):
@@ -542,7 +541,7 @@ class ApsctSensors:
while (self.temperature > 100) & (loops < 2):
loops = loops + 1
ret_ack, ret_value = self.dev_i2c_sensor.read_last_reg(3)
if ret_ack :
if ret_ack:
raw_value = (int(ret_value, 16) & 0x1FFFFF) >> 6
temperature_k = (raw_value/temp_slope)
self.temperature = temperature_k-273
@@ -693,5 +692,6 @@ def main():
# apsct.pll_200.read_all_regs_pll()
apsct.sensors.check_values()
if __name__ == "__main__":
main()
Loading