From fd1793c391182d3dee53b716fec6a80886cadc39 Mon Sep 17 00:00:00 2001
From: Gijs Schoonderbeek <schoonderbeek@astron.nl>
Date: Fri, 6 Jan 2023 13:44:36 +0100
Subject: [PATCH] tested production_apsct on HW

---
 apsct_lib.py | 24 ++++++++++++++++++++----
 1 file changed, 20 insertions(+), 4 deletions(-)

diff --git a/apsct_lib.py b/apsct_lib.py
index 357f09e..a377886 100644
--- a/apsct_lib.py
+++ b/apsct_lib.py
@@ -158,7 +158,7 @@ class PllClass:
             for clk in range(2):
                 Write_data = 0x02 | (0 << CS) | (clk << SCLK) | (int(bit) << SDI)
                 self.dev_i2c_pll.write_bytes(0x02, Write_data)
-                time.sleep(sleep_time)
+                sleep(sleep_time)
         read_bit = ''
         for cnt in range(8*nof_bytes):
             for clk in [0, 1]:  # Read after rizing edge
@@ -219,6 +219,19 @@ class PllClass:
             stri = "Reg nr 0x{:0>2x} value: 0x{:0>2x}".format(cnt, int(ret_value[start:start+8], 2))
             print(stri)
 
+    def read_lock(self):
+        #
+        # Read lock status
+        #
+        ret_value = self.Read_byte_PLL(0x00, nof_bytes = 1)
+        status_pll = int(ret_value,2)
+        if status_pll == 0x04:
+            print("PLL in lock")
+        elif (status_pll & 0x10) > 0:
+            print("Not Locked --> No 10 MHz ref")
+        else:
+            print("Not locked --> PLL Error")
+
     def read_lol(self, pll_frequency='200MHz'):
         #
         # Read loss of lock status
@@ -233,9 +246,9 @@ class PllClass:
         ack, ret_value = I2C_IO_device_B.read_bytes(0x01, 1)
         status_reg = int(ret_value, 16)
         if (pll_frequency == '200MHz') & ((status_reg & 0x10) > 0):
-            print("lost lock 200MHz")
+            print("200MHz has lost lock")
         if ((status_reg & 0x20) > 0) & (pll_frequency == '160MHz'):
-            print("lost lock 160MHz")
+            print("160MHz has last lock")
         ack, ret_value = I2C_IO_device_A.read_bytes(0x01, 1)
         old_reg = int(ret_value, 16)
         I2C_IO_device_A.write_bytes(0x03, (old_reg | 0x10))  # '0' is output
@@ -287,7 +300,9 @@ class EepromClass:
             return False
         else:
             ret_ack, ret_value = self.dev_i2c_eeprom.read_bytes(address, nof_bytes)
-            str_return = bytes.fromhex(ret_value[:nof_bytes * 2]).decode('UTF-8')
+            ret_value = bytes.fromhex(ret_value[:nof_bytes * 2])
+            #print(" ret value = {}".format(ret_value))
+            str_return = ret_value.decode('UTF-8')
             return str_return
 
     def wr_rd_eeprom(self, value="APSPU-1", address=0):
@@ -300,6 +315,7 @@ class EepromClass:
         #
         if self.write_eeprom(value, address=0):
             ret_value = self.read_eeprom(address=0, nof_bytes=len(value))
+            print(ret_value)
             stri = "Wrote to EEPROM register 0x{2:x} : {0}, Read from EEPROM: {1}".format(value, ret_value, address)
             print(stri)
             if ret_value == value:
-- 
GitLab