diff --git a/APSCT_CLK_I2C.py b/APSCT_CLK_I2C.py
index 1599e6ac84e9d046ae542876aeb6e0c40fc628b4..a89d11f0d5111821c290eb6b7d6e1ef9b8ccff92 100644
--- a/APSCT_CLK_I2C.py
+++ b/APSCT_CLK_I2C.py
@@ -24,14 +24,15 @@ else:
     from I2C_serial import *
 
 DEBUG = False
-I2CBUSNR=3
-sleep_time = 0.05
+I2CBUSNR=5
+sleep_time = 0.15
 SET_PLL = True
-READ_LOCK = True
-READ_ALL = False
-CHECK_EEPROM = True
-PWR_RST = False
+READ_LOCK = False #True
+READ_ALL = True #False
+CHECK_EEPROM = False
+PWR_RST = True #False
 READ_SENSOR = True
+READ_REGS = False #True
 
 CLK_FREQ = '200MHz'
 dev_i2c_eeprom = I2C(0x50)
@@ -51,7 +52,7 @@ def Write_byte_PLL(reg_address, wr_data, ADDRESS=0x20):
     #
     I2C_device = I2C(ADDRESS, BUSNR=I2CBUSNR)
     PLL_rw = 0x00 # 0 for write, 1 for read
-    stri = "Write : 0x{0:{fill}2x} to Address : 0x{1:{fill}2x}".format(wr_data, reg_address, fill='0')
+    stri = "Write to address : 0x{1:{fill}2x} value  0x{0:{fill}2x}".format(wr_data, reg_address, fill='0')
     print(stri)
     I2C_device.write_bytes(0x06, 0x2C)
     if DEBUG:
@@ -90,13 +91,12 @@ def Read_byte_PLL(reg_address, nof_bytes=1, ADDRESS=0x20 ):
     I2C_device.write_bytes(0x06, 0x2C)
     data =  ( reg_address << 7 ) + PLL_rw
 
-
     bit_array = "{0:{fill}8b}".format(data, fill='0')
     for bit in bit_array:
         for clk in range(2):
             Write_data = 0x02 | (0 << CS) | (clk << SCLK) | ( int(bit) << SDI)
             I2C_device.write_bytes(0x02, Write_data)
-#            sleep(sleep_time)
+            sleep(sleep_time)
 
 #    print("read byte")
     read_bit = ''
@@ -117,6 +117,33 @@ def Read_byte_PLL(reg_address, nof_bytes=1, ADDRESS=0x20 ):
     print(stri)
     return read_bit;
 
+def read_all_regs_pll(pll_frequency='200MHz') :
+    I2C_device = I2C(0x20, BUSNR=I2CBUSNR) #clock selection
+    I2C_device.write_bytes(0x07, 0x00)
+    if pll_frequency == '160MHz':
+        print("Read PLL 160 MHz")
+        pll_address = PLL_160M
+#        I2C_device.write_bytes(0x03, 0x0F)
+    else:
+        print("Read PLL 200 MHz")
+        pll_address=PLL_200M
+#        I2C_device.write_bytes(0x03, 0xF8)
+#    for reg_cnt in range(0x15):
+    bytes_to_read = 24
+    ret_value = Read_byte_PLL(0, nof_bytes = bytes_to_read, ADDRESS=pll_address)
+    for cnt in range(bytes_to_read):
+        start = cnt*8
+        stri = "Reg nr 0x{:0>2x} value: 0x{:0>2x}".format(cnt, int(ret_value[start:start+8], 2))
+        print(stri)
+
+def read_IO_expanderis():
+    i2c_addr = [0x20, 0x21]
+    for addr in i2c_addr:
+        I2C_device = I2C(addr, BUSNR=I2CBUSNR) #clock selection
+        for reg_cnt in range(8):
+            ack, ret_value = I2C_device.read_bytes(reg_cnt, 2)
+            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 setup_pll(pll_frequency='200MHz') :
     I2C_device = I2C(0x20, BUSNR=I2CBUSNR) #clock selection
@@ -124,13 +151,13 @@ def setup_pll(pll_frequency='200MHz') :
     if pll_frequency == '160MHz':
         print("Set PLL to 160 MHz mode")
         pll_address = PLL_160M
-        I2C_device.write_bytes(0x03, 0x08)
+        I2C_device.write_bytes(0x03, 0x0F)
     else:
         print("Set PLL to 200 MHz mode")
         pll_address=PLL_200M
-        I2C_device.write_bytes(0x03, 0xF8)
+        I2C_device.write_bytes(0x03, 0xFF)
     Write_byte_PLL(0x03, 0x08, pll_address)
-    Write_byte_PLL(0x04, 0xCF, pll_address) # CF disable not used outputs, 00 enable all
+    Write_byte_PLL(0x04, 0x00, pll_address) # CF disable not used outputs, 00 enable all
     Write_byte_PLL(0x05, 0x97, pll_address)
     Write_byte_PLL(0x06, 0x10, pll_address) # cp inv = 0xF4 other 0xE4
     Write_byte_PLL(0x07, 0x04, pll_address) # Divider R = 1 dec
@@ -142,6 +169,7 @@ def setup_pll(pll_frequency='200MHz') :
     else:
         Write_byte_PLL(0x0A, 0x14, pll_address)
     Write_byte_PLL(0x09, 0x00, pll_address)
+    Write_byte_PLL(0x0C, 0x80, pll_address)
     Write_byte_PLL(0x0D, 0x01, pll_address) # Dig CLK     = 200/1 = 200 MHz
     Write_byte_PLL(0x0F, 0x01, pll_address) # RCU CLK     = 200/1 = 200 MHz
     Write_byte_PLL(0x11, 0x01, pll_address) # PPS ref CLK = 200/1 = 200 MHz
@@ -149,6 +177,8 @@ def setup_pll(pll_frequency='200MHz') :
 
 
 def power(state):
+    stri = "Power to {}".format(state)
+    print(stri)
     I2C_IO_device_A = I2C(0x20, BUSNR=I2CBUSNR)
     I2C_IO_device_A.write_bytes(0x06, 0x2C) # '0' is output
     I2C_IO_device_A.write_bytes(0x07, 0x00) # '0' is output
@@ -218,7 +248,7 @@ def read_voltage(input_channel=0):
     if DEBUG:
         stri = "Word to select sens input is 0x{0:x}".format(channel_select_word)
         print(stri)
-    sleep(0.5)
+    sleep(0.1)
     I2C_device.write_bytes(channel_select_word, 0xB8)
     sleep(0.5)
     ret_ack, ret_value = I2C_device.read_last_reg(3)
@@ -257,6 +287,8 @@ def read_temp():
     else:
         print("Error reading tempeature")
 
+#if READ_REGS:
+#    read_all_regs_pll(CLK_FREQ)
 
 if CHECK_EEPROM :
     wr_rd_eeprom()
@@ -283,5 +315,12 @@ if READ_LOCK:
     else:
         print("Not locked --> PLL Error")
 
+if READ_REGS:
+    read_all_regs_pll(CLK_FREQ)
+
+if READ_ALL:
+    read_all_regs_pll(CLK_FREQ)
+    read_IO_expanderis()
+
 if READ_SENSOR:
     apsct_sensors()
diff --git a/CCD_I2C.py b/CCD_I2C.py
index 0f012075305074c70a73601e4b4505c579d18eb9..ceda9df958f5d929277a7d31a5aeb17950fdb0d1 100644
--- a/CCD_I2C.py
+++ b/CCD_I2C.py
@@ -16,6 +16,7 @@ Set CCD
 '''
 import sys
 import time
+import math
 sys.path.insert(0,'.')
 import os
 if os.name =="posix":
@@ -31,8 +32,8 @@ READ_LOCK = True
 READ_ALL = False
 CHECK_EEPROM = True
 PWR_RST = False
-READ_SENSOR = True
-
+READ_SENSOR = False
+READ_SET_FAN = True
 CLK_FREQ = '200MHz'
 dev_i2c_eeprom = I2C(0x50)
 dev_i2c_eeprom.bus_nr = I2CBUSNR
@@ -121,16 +122,16 @@ def setup_pll() :
     I2C_device = I2C(0x20, BUSNR=I2CBUSNR) #clock selection
     I2C_device.write_bytes(0x07, 0x00)
     Write_byte_PLL(0x03, 0x08, PLL_addr)
-    Write_byte_PLL(0x04, 0xCF, PLL_addr) # CF disable not used outputs, 00 enable all
-    Write_byte_PLL(0x05, 0xF0, PLL_addr)
-    Write_byte_PLL(0x06, 0x40, PLL_addr)  # cp inv = 0xF4 other 0xE4
+    Write_byte_PLL(0x04, 0xFF, PLL_addr) # CF disable not used outputs, 00 enable all
+    Write_byte_PLL(0x05, 0xD7, PLL_addr)
+    Write_byte_PLL(0x06, 0xE0, PLL_addr)  # cp inv = 0xF4 other 0xE4
     Write_byte_PLL(0x07, 0x04, PLL_addr)  # Divider R = 1 dec
     Write_byte_PLL(0x08, 0x01, PLL_addr)
     Write_byte_PLL(0x07, 0x00, PLL_addr)
-    Write_byte_PLL(0x09, 0x04, PLL_addr)
+    Write_byte_PLL(0x09, 0x10, PLL_addr)
     Write_byte_PLL(0x0A, 0x01, PLL_addr)
     Write_byte_PLL(0x09, 0x00, PLL_addr)
-    Write_byte_PLL(0x0B, 0x40, PLL_addr)
+    Write_byte_PLL(0x0B, 0x00, PLL_addr)
     Write_byte_PLL(0x0D, 0x01, PLL_addr)
     Write_byte_PLL(0x0E, 0x00, PLL_addr)
     Write_byte_PLL(0x0F, 0x01, PLL_addr)
@@ -251,6 +252,71 @@ def read_temp():
     else:
         print("Error reading tempeature")
 
+def set_fan_off():
+    #
+    # Switch CCD fan off
+    #
+    print("Switch fan off")
+    MAX6620          = 0x29
+    fanmonitor_dev = I2C(MAX6620)
+    fanmonitor_dev.bus_nr = 3
+    fanmonitor_dev.write_bytes(0x00, 0x10)
+    fanmonitor_dev.write_bytes(0x02, 0x08)
+    fanmonitor_dev.write_bytes(0x28, 0x00)
+    fanmonitor_dev.write_bytes(0x29, 0x00)
+
+def set_fan_speed(speed):
+    #
+    # Set control voltage of fan PNP 
+    #
+    stri = "Set fan to {} %".format(speed)
+    print(stri)
+    MAX6620          = 0x29
+    reg_a = ((0xFF*speed)/100) & 0xFF
+    fanmonitor_dev = I2C(MAX6620)
+    fanmonitor_dev.bus_nr = 3
+    fanmonitor_dev.write_bytes(0x00, 0x00)
+    fanmonitor_dev.write_bytes(0x02, 0x08)
+    fanmonitor_dev.write_bytes(0x01, 0x0F)
+    fanmonitor_dev.write_bytes(0x06, 0x60)
+    fanmonitor_dev.write_bytes(0x28, reg_a)
+    fanmonitor_dev.write_bytes(0x29, 0x80) 
+
+
+def read_tacho():
+    #
+    # Read the fan speed
+    #
+    MAX6620          = 0x29
+    REG_TACH_MSP_REGS = [ 0x10, 0x12, 0x14]
+    REG_TACH_LSP_REGS = [ 0x11, 0x13, 0x15]
+    TACH_PERIODS = 16
+    TACH_COUNT_FREQ = 8192
+    FAN_TACHS = 1
+    DEBUG=1
+    fanmonitor_dev = I2C(MAX6620)
+    fanmonitor_dev.bus_nr = 3
+    fan_nr=0
+    ret_ack, ret_value = fanmonitor_dev.read_bytes(1)
+    if ret_ack < 1:
+        stri = " Device {0} at address 0x{1:X} not found".format("MAX6620", MAX6620)
+        print(stri)
+        status = False
+    ret_ack, tach_msb = fanmonitor_dev.read_bytes(REG_TACH_MSP_REGS[0], 1)
+    tach_msb = int(tach_msb, 16) & 0xFF
+    if tach_msb > 254:
+        if DEBUG :
+            tach_lsb = 255
+            tach = 99999
+        rpm = 0
+    else:
+        ret_ack, tach_lsb = fanmonitor_dev.read_bytes(REG_TACH_LSP_REGS[0], 1)
+        tach_lsb = int(tach_lsb, 16) & 0xE0
+        tach = tach_msb*16 + tach_lsb/8
+        rpm = float((TACH_COUNT_FREQ*TACH_PERIODS*60))/(FAN_TACHS*tach)
+    if DEBUG:
+        stri = "MSP: {0}, LSB: {1}, TACH : {2}, RPM : {3:6.2f}".format(tach_msb, tach_lsb, tach, rpm)
+        print(stri)
 
 if CHECK_EEPROM :
     wr_rd_eeprom()
@@ -272,6 +338,13 @@ if READ_LOCK:
         print("Not Locked --> No 10 MHz ref")
     else:
         print("Not locked --> PLL Error")
+if READ_SET_FAN :
+    read_tacho()
+    set_fan_off()
+    sleep(10)
+    set_fan_speed(75)
+    sleep(10)
+    read_tacho()
 
 if READ_SENSOR:
     ccd_sensors()