diff --git a/CCD_I2C.py b/CCD_I2C.py index c2ffd01def2cb7bf075766083b25d27482f0afd5..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": @@ -32,7 +33,7 @@ READ_ALL = False CHECK_EEPROM = True PWR_RST = False READ_SENSOR = False - +READ_SET_FAN = True CLK_FREQ = '200MHz' dev_i2c_eeprom = I2C(0x50) dev_i2c_eeprom.bus_nr = I2CBUSNR @@ -251,53 +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(): - MAX6620 = 0x52 - REG_GLOBAL = 0x00 + # + # 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 - RUN_MONITOR = 0x02 - NOF_APS_FANS = 3 DEBUG=1 fanmonitor_dev = I2C(MAX6620) - fanmonitor_dev.bus_nr = I2CBUSNR + 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: - if DEBUG: - stri = "Device {0} at address 0x{1:X} is found ".format("MAX6620", MAX6620) - print(stri) - ret_ack, reg_before = fanmonitor_dev.read_bytes(REG_GLOBAL, 1) - fanmonitor_dev.write_bytes(REG_GLOBAL, RUN_MONITOR) - ret_ack, reg_after = fanmonitor_dev.read_bytes(REG_GLOBAL, 1) + 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 = "Reg at address 0x{0} before : {1} and after write action {2}".format(REG_GLOBAL, reg_before, reg_after) + stri = "MSP: {0}, LSB: {1}, TACH : {2}, RPM : {3:6.2f}".format(tach_msb, tach_lsb, tach, rpm) print(stri) - fan_config_reg = int((math.log(TACH_PERIODS) / math.log(2))) << 5 - for fan_cnt in range(NOF_APS_FANS): - fanmonitor_dev.write_bytes(0x02 + fan_cnt, 0x88) - fanmonitor_dev.write_bytes(0x06 + fan_cnt, fan_config_reg) - ret_ack, tach_msb = fanmonitor_dev.read_bytes(REG_TACH_MSP_REGS[fan_nr], 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[fan_nr], 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}".format(tach_msb, tach_lsb, tach) - print(stri) if CHECK_EEPROM : wr_rd_eeprom() @@ -319,8 +338,13 @@ if READ_LOCK: print("Not Locked --> No 10 MHz ref") else: print("Not locked --> PLL Error") - -read_tacho() +if READ_SET_FAN : + read_tacho() + set_fan_off() + sleep(10) + set_fan_speed(75) + sleep(10) + read_tacho() if READ_SENSOR: ccd_sensors()