Skip to content
Snippets Groups Projects
Commit 37bef031 authored by Gijs Schoonderbeek's avatar Gijs Schoonderbeek
Browse files

Added fan control on CCD

parent b33fb937
No related branches found
No related tags found
No related merge requests found
...@@ -16,6 +16,7 @@ Set CCD ...@@ -16,6 +16,7 @@ Set CCD
''' '''
import sys import sys
import time import time
import math
sys.path.insert(0,'.') sys.path.insert(0,'.')
import os import os
if os.name =="posix": if os.name =="posix":
...@@ -32,7 +33,7 @@ READ_ALL = False ...@@ -32,7 +33,7 @@ READ_ALL = False
CHECK_EEPROM = True CHECK_EEPROM = True
PWR_RST = False PWR_RST = False
READ_SENSOR = False READ_SENSOR = False
READ_SET_FAN = True
CLK_FREQ = '200MHz' CLK_FREQ = '200MHz'
dev_i2c_eeprom = I2C(0x50) dev_i2c_eeprom = I2C(0x50)
dev_i2c_eeprom.bus_nr = I2CBUSNR dev_i2c_eeprom.bus_nr = I2CBUSNR
...@@ -251,39 +252,57 @@ def read_temp(): ...@@ -251,39 +252,57 @@ def read_temp():
else: else:
print("Error reading tempeature") 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(): def read_tacho():
MAX6620 = 0x52 #
REG_GLOBAL = 0x00 # Read the fan speed
#
MAX6620 = 0x29
REG_TACH_MSP_REGS = [ 0x10, 0x12, 0x14] REG_TACH_MSP_REGS = [ 0x10, 0x12, 0x14]
REG_TACH_LSP_REGS = [ 0x11, 0x13, 0x15] REG_TACH_LSP_REGS = [ 0x11, 0x13, 0x15]
TACH_PERIODS = 16 TACH_PERIODS = 16
TACH_COUNT_FREQ = 8192 TACH_COUNT_FREQ = 8192
FAN_TACHS = 1 FAN_TACHS = 1
RUN_MONITOR = 0x02
NOF_APS_FANS = 3
DEBUG=1 DEBUG=1
fanmonitor_dev = I2C(MAX6620) 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) ret_ack, ret_value = fanmonitor_dev.read_bytes(1)
if ret_ack < 1: if ret_ack < 1:
stri = " Device {0} at address 0x{1:X} not found".format("MAX6620", MAX6620) stri = " Device {0} at address 0x{1:X} not found".format("MAX6620", MAX6620)
print(stri) print(stri)
status = False status = False
else: ret_ack, tach_msb = fanmonitor_dev.read_bytes(REG_TACH_MSP_REGS[0], 1)
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)
if DEBUG:
stri = "Reg at address 0x{0} before : {1} and after write action {2}".format(REG_GLOBAL, reg_before, reg_after)
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 tach_msb = int(tach_msb, 16) & 0xFF
if tach_msb > 254: if tach_msb > 254:
if DEBUG : if DEBUG :
...@@ -291,12 +310,12 @@ def read_tacho(): ...@@ -291,12 +310,12 @@ def read_tacho():
tach = 99999 tach = 99999
rpm = 0 rpm = 0
else: else:
ret_ack, tach_lsb = fanmonitor_dev.read_bytes(REG_TACH_LSP_REGS[fan_nr], 1) ret_ack, tach_lsb = fanmonitor_dev.read_bytes(REG_TACH_LSP_REGS[0], 1)
tach_lsb = int(tach_lsb, 16) & 0xE0 tach_lsb = int(tach_lsb, 16) & 0xE0
tach = tach_msb*16 + tach_lsb/8 tach = tach_msb*16 + tach_lsb/8
rpm = float((TACH_COUNT_FREQ*TACH_PERIODS*60))/(FAN_TACHS*tach) rpm = float((TACH_COUNT_FREQ*TACH_PERIODS*60))/(FAN_TACHS*tach)
if DEBUG: if DEBUG:
stri = "MSP: {0}, LSB: {1}, TACH : {2}".format(tach_msb, tach_lsb, tach) stri = "MSP: {0}, LSB: {1}, TACH : {2}, RPM : {3:6.2f}".format(tach_msb, tach_lsb, tach, rpm)
print(stri) print(stri)
if CHECK_EEPROM : if CHECK_EEPROM :
...@@ -319,7 +338,12 @@ if READ_LOCK: ...@@ -319,7 +338,12 @@ if READ_LOCK:
print("Not Locked --> No 10 MHz ref") print("Not Locked --> No 10 MHz ref")
else: else:
print("Not locked --> PLL Error") print("Not locked --> PLL Error")
if READ_SET_FAN :
read_tacho()
set_fan_off()
sleep(10)
set_fan_speed(75)
sleep(10)
read_tacho() read_tacho()
if READ_SENSOR: if READ_SENSOR:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment