Skip to content
Snippets Groups Projects

Draft: Temp fix

Closed Lucas Mollier requested to merge temp-fix into master
@@ -1351,97 +1351,22 @@ class Lpgbt(Hardware):
f.close()
logger.warning("The parameters and/or ID couldn't be find in the csv calibration file")
def read_monitor_voltage(self, adc_channel = 10):
'''Measure voltage from the dedicated adc channel
adc_channel is either equal to 10 (VDDTX), 11 (VDDRX), 12 (VDD), 13(VDDA)
Args:
adc_channel (int) is the channel that one wants to read the voltage from. Could be 0,1,10,11,12,13
disable_monitor_after_measurement (boolean) is used to disable the vddmon.
Returns:
the voltage in V from the desired channel.
'''
assert (adc_channel == 13 or adc_channel ==12 or adc_channel == 11 or adc_channel == 10), 'Invalid adc_channely'
self.enable_voltage_monitor(adc_channel,True)
adc_value = self.read_adc(adcchannel=adc_channel)
adc_v = self.calibrate_adc_to_voltage(adc_value)
vsup = v_adc * (vdd_mon_slope + temperature * vdd_mon_slope_temp)
self.enable_voltage_monitor(adc_channel,False)
logger.info("The voltage monitor of channel %i is %.2f V" %(adc_channel,vsup))
return vsup
def read_temperature_NTC(self,estimate_resistance = 10000):
def read_temperature_PTAT(self):
"""
First give an estimage of the resistance (10kohm) and send a reasonable current to the NTC. Then read the voltage. Then measure the resistance.
Args:
estimate_resistance (int) is used to compute the current that needs to be applied.
Returns:
The temperature in degree based on the NTC.
Read the external pin from the ADC of the lpbgt channel 3 , PTAT. And converts it to temperature.
The conversion is done with the calibration values from the bpol manual.
Returns: The temperature of the PTAT (Bpol) in degree Celsius. Not calibrated.
"""
try:
B = 3453 #K
R0 = 10000 # Ohm
T0 = 25 + 273 #K
current_temperature = self.read_onchip_temperature()
#Defining the current that needs to be set
vref = 0.5
current = vref / estimate_resistance
assert 0<= current < 1e-3,"Invalid CDAC current"
if len(self.lpgbt_calibration) == 0:
self.read_lpgbt_calibration_file()
CDAC3_SLOPE = self.lpgbt_calibration['CDAC3_SLOPE']
CDAC3_SLOPE_TEMP = self.lpgbt_calibration['CDAC3_SLOPE_TEMP']
CDAC3_OFFSET = self.lpgbt_calibration['CDAC3_OFFSET']
CDAC3_OFFSET_TEMP = self.lpgbt_calibration['CDAC3_OFFSET_TEMP']
CDAC3_R0 = self.lpgbt_calibration['CDAC3_R0']
CDAC3_R0_TEMP = self.lpgbt_calibration['CDAC3_R0_TEMP']
print("====")
print("a = " + str(CDAC3_SLOPE))
print("b = " + str(current_temperature * CDAC3_SLOPE_TEMP))
print("i = " + str(current))
print("(a+b)*i = " +str((CDAC3_SLOPE+ current_temperature * CDAC3_SLOPE_TEMP)* current ))
print("c = " + str(CDAC3_OFFSET))
print("d = " + str(current_temperature * CDAC3_OFFSET_TEMP))
print("(a+b)*i + c + d = " + str((CDAC3_SLOPE+ current_temperature * CDAC3_SLOPE_TEMP)* current + CDAC3_OFFSET+ current_temperature * CDAC3_OFFSET_TEMP))
print("current temperature is " + str(current_temperature))
print("====")
adc_current = round((CDAC3_SLOPE+ current_temperature * CDAC3_SLOPE_TEMP)* current + CDAC3_OFFSET+ current_temperature * CDAC3_OFFSET_TEMP)
if adc_current <= 0 or adc_current > 256:
logger.error("adc_current can not deliver requested current")
return None
#enabling the current in the channel
adc_value = self.read_adc(3)
self.write_read(reg="DACConfigH",reg_field="CURDACEnable",reg_data=1)
self.write_read(reg="CURDACValue", reg_field = None,reg_data=adc_current)
self.write_read(reg="CURDACCHN", reg_field = None,reg_data=0x08) #adc 3
input("press enter to continue")
#reading all the parameters
r_out = (CDAC3_R0+ current_temperature * CDAC3_R0_TEMP)/ max((1,adc_current))
adc_value = self.read_adc(3)
v_adc = self.calibrate_adc_to_voltage(adc_value)
r_measured = v_adc/current
print("adc_value is %.2f " %adc_value)
print("adc_current is %.2f " %adc_current)
print("current is %.2f mA" % (1000*current))
print("v_adc is %.2f V" %v_adc)
print("r_out is %.1f Ohm" %r_out)
print("r_measured is %.1f Ohm" %r_measured)
print("adc_value of channel 4 is %.1f" %self.read_adc(4))
print("-------------------------------------------")
#compute the resistance and then the temperature
R = r_measured/(1- r_measured/r_out)
print("R is %.2f Ohm"%R)
T = 1/(1/T0 + (2.3026 * (math.log10(R) - math.log10(R0)) /B )) -273 #Formula taken from the farnell NTC manual (https://www.farnell.com/datasheets/3097877.pdf)
#disabling the current in the channel
logger.info("The temperature is %.1f C" %T)
return T
except:
logger.warning("The temperature couldn't be read. Putting the current to 0.")
finally:
self.write_read(reg="DACConfigH",reg_field="CURDACEnable",reg_data=0)
self.write_read(reg="CURDACValue", reg_field = None,reg_data=0)
self.write_read(reg="CURDACCHN", reg_field = None,reg_data=0)
adc_value = self.read_adc(3)
v_adc = self.calibrate_adc_to_voltage(adc_value)
conversion_voltage_temp = 4/1000 #mV/C, taken from the bpol manual
conversion_offset = 0.4666 #V for 25C, did it manually, not really good to do that!!!
#Maybe it's better to use it as a differential measurement???
T = 25.7 + (v_adc - conversion_offset)/conversion_voltage_temp
logger.info("The temperature of PTAT is %.4f C (not calibrated...)" %(T))
return T
def calibrate_adc_to_voltage(self,adc_value):
"""
@@ -1526,15 +1451,3 @@ class Lpgbt(Hardware):
t=self.write_read(reg="ADCMon",reg_field=power_supply_name,reg_data=0)
return t
def set_voltage(self, voltage):
if len(self.lpgbt_calibration) == 0:
self.read_lpgbt_calibration_file()
CAL_VDAC_SLOPE = self.lpgbt_calibration['VDAC_SLOPE']
CAL_VDAC_SLOPE_TEMP = self.lpgbt_calibration['VDAC_SLOPE_TEMP']
CAL_VDAC_OFFSET = self.lpgbt_calibration['VDAC_OFFSET']
CAL_VDAC_OFFSET_TEMP = self.lpgbt_calibration['VDAC_OFFSET_TEMP']
VOLDACValue = round(voltage * (CAL_VDAC_SLOPE + 25 * CAL_VDAC_SLOPE_TEMP) +CAL_VDAC_OFFSET + 25 * CAL_VDAC_OFFSET_TEMP)
self.write_read(reg="DACConfigH",reg_field="VOLDACEnable",reg_data=1)
self.write_read(reg="VOLDACValue", reg_field = None,reg_data=VOLDACValue)
self.write_read(reg="CURDACCHN", reg_field = None,reg_data=0x08) #adc 3
Loading