Skip to content
Snippets Groups Projects
Commit cf127ccb authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files
parents e6c3cb63 6f806ce0
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ class CcdClass:
self.frequency = "10 MHz"
self.eeprom = EepromClass()
self.pll = PllClass()
self.sensors = ApsctSensors()
self.sensors = CcdSensors()
self.ccd_id = CcdId()
def power(self, state):
......@@ -188,13 +188,20 @@ class PllClass:
if DEBUG:
print(f"Divider P : {divider_p}, Divider A : {divider_a}, Divider B : {divider_b}")
charge_pump_current = 3 # 0 is low (0.6 mA), 7 is high (4.8 mA)
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(0x04, (divider_a & 0x3F))
self.write_byte_pll(0x04, 0x00) # (divider_a & 0x3F))
# self.write_byte_pll(0x05, (divider_b & 0x1F00) >> 8)
self.write_byte_pll(0x05, 0x00) # (divider_b & 0x1F00) >> 8)
# self.write_byte_pll(0x06, (divider_b & 0x00FF))
self.write_byte_pll(0x06, 0x01) # (divider_b & 0x00FF))
self.write_byte_pll(0x07, 0x00) # No LOR
self.write_byte_pll(0x08, 0x3B) # Charge pump normal + Status bit
self.write_byte_pll(0x09, (charge_pump_current & 0x7) << 4)
self.write_byte_pll(0x0A, 0x00) # Fixed Divide 1
# self.write_byte_pll(0x08, 0x3B) # Charge pump normal + Status bit
self.write_byte_pll(0x08, 0x47) # Charge pump normal + Status bit
# self.write_byte_pll(0x08, 0x43) # Charge pump normal + Status bit
# self.write_byte_pll(0x09, (charge_pump_current & 0x7) << 4)
self.write_byte_pll(0x09, 0x50) # (charge_pump_current & 0x7) << 4)
# self.write_byte_pll(0x0A, 0x00) # Fixed Divide 1
self.write_byte_pll(0x0A, 0x40) # Fixed Divide 1
self.write_byte_pll(0x0B, 0x00)
self.write_byte_pll(0x0C, 0x01)
self.write_byte_pll(0x45, 0x00) # CLK2 as feedback clock input
......@@ -226,15 +233,15 @@ class PllClass:
#
i2_c_io_device = I2C(0x20, BUSNR=I2CBUSNR)
i2_c_io_device.write_bytes(0x06, 0x2C) # '0' is output
i2_c_io_device.write_bytes(0x07, 0x00) # '0' is output
i2_c_io_device.write_bytes(0x07, 0x0F) # '0' is output
ack, ret_value = i2_c_io_device.read_bytes(0x00, 1)
status_pll = int(ret_value, 16) & 0x04
if status_pll:
self.lock = True
stri = f"PLL is in lock"
stri = f"OK PLL is in lock"
else:
self.lock = False
stri = f"PLL is not locked"
stri = f"Error PLL is not locked"
print(stri)
return self.lock
......@@ -244,15 +251,17 @@ class PllClass:
#
i2_c_io_device_a = I2C(0x20, BUSNR=I2CBUSNR)
i2_c_io_device_a.write_bytes(0x06, 0x2C) # '0' is output
i2_c_io_device_a.write_bytes(0x07, 0x00) # '0' is output
i2_c_io_device_b = I2C(0x21, BUSNR=I2CBUSNR)
i2_c_io_device_b.write_bytes(0x06, 0x2C) # '0' is output
i2_c_io_device_b.write_bytes(0x07, 0xFF) # '0' is output
ack, ret_value = i2_c_io_device_b.read_bytes(0x01, 1)
i2_c_io_device_a.write_bytes(0x07, 0x0F) # '0' is output
# i2_c_io_device_b = I2C(0x21, BUSNR=I2CBUSNR)
# i2_c_io_device_b.write_bytes(0x06, 0x2C) # '0' is output
# i2_c_io_device_b.write_bytes(0x07, 0xFF) # '0' is output
ack, ret_value = i2_c_io_device_a.read_bytes(0x01, 1)
status_reg = int(ret_value, 16)
lol = (status_reg & 0x04)
if lol:
print(f"{self.frequency} has lost lock")
print(f"Error {self.frequency} has lost lock")
else:
print(f"OK {self.frequency} has not lost lock")
ack, ret_value = i2_c_io_device_a.read_bytes(0x01, 1)
old_reg = int(ret_value, 16)
i2_c_io_device_a.write_bytes(0x03, (old_reg | 0x20)) # '0' is output
......@@ -337,7 +346,7 @@ class CcdSensors:
self.power_supplies = list(CCD_I2C.PWR_LOCATIONS.keys())
self.voltages = {}
self.temperature = 9999
self.dev_i2c_sensor.write_bytes(0xB0, 0xB8)
# self.dev_i2c_sensor.write_bytes(0xB0, 0xB8)
def ccd_sensors(self):
#
......@@ -478,7 +487,7 @@ class CcdSensors:
class CcdtId:
class CcdId:
#
# Class to check ID pins
#
......@@ -499,6 +508,7 @@ class CcdtId:
for pin in CCD_I2C.ID_PINS:
loc_id = loc_id * 2
bit = gpio.input(pin)
print(f"DEBUG.. Bit is {bit}")
loc_id = loc_id + bit
self.id = loc_id
return self.id
......@@ -523,15 +533,13 @@ def main():
sleep(1)
Ccd.power(True)
sleep(1)
if False:
Ccd.pll.write_byte_pll(0x06, 0xA5)
Ccd.pll.write_byte_pll(0x5A, 0x01)
Ccd.pll.setup_pll()
Ccd.pll.read_lol()
Ccd.pll.read_lock()
Ccd.pll.read_all_regs_pll()
Ccd.pll.read_lol()
# Ccd.pll.read_all_regs_pll()
Ccd.sensors.check_values()
# Ccd.eeprom.wr_rd_eeprom()
Ccd.ccd_id.check_id()
if __name__ == "__main__":
main()
......@@ -145,6 +145,7 @@ if SET_PLL :
Write_byte_PLL(0x05, 0xF0)
Write_byte_PLL(0x06, 0x40) # cp inv = 0xF4 other 0xE4
Write_byte_PLL(0x07, 0x04) # Divider R = 1 dec
Read_byte_PLL(0x07, 2)
Write_byte_PLL(0x08, 0x01)
Write_byte_PLL(0x07, 0x00)
# Write_byte_PLL(0x09, 0x10) # reset
......@@ -168,7 +169,8 @@ if READ_LOCK:
print("Not locked --> PLL Error")
if READ_ALL:
Read_byte_PLL(0x00, nof_bytes = 23)
for cnt in range(32):
Read_byte_PLL(cnt, nof_bytes = 1)
if UPDATE_PLL:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment