Skip to content

Commit 70570b8

Browse files
authored
Merge pull request fossasia#22 from fossasia/development
merge from development
2 parents 90e8511 + b6e0730 commit 70570b8

File tree

3 files changed

+455
-42
lines changed

3 files changed

+455
-42
lines changed

PSL/sciencelab.py

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ class ScienceLab():
5959
6060
6161
62-
63-
6462
"""
6563

6664
CAP_AND_PCS=0
@@ -75,6 +73,7 @@ class ScienceLab():
7573
DAC_SHIFTS_PV2B=7
7674
DAC_SHIFTS_PV3A=8
7775
DAC_SHIFTS_PV3B=9
76+
LOC_DICT = {'PV1':[4,5],'PV2':[6,7],'PV3':[8,9]}
7877
BAUD = 1000000
7978
WType={'W1':'sine','W2':'sine'}
8079
def __init__(self,timeout=1.0,**kwargs):
@@ -128,7 +127,7 @@ def __runInitSequence__(self,**kwargs):
128127
self.achans=[analogAcquisitionChannel(a) for a in ['CH1','CH2','CH3','MIC']]
129128
self.gain_values=gains
130129
self.buff=np.zeros(10000)
131-
self.SOCKET_CAPACITANCE = 0# 42e-12 is typical for the SEElablet. Actual values will be updated during calibration loading
130+
self.SOCKET_CAPACITANCE = 42e-12# 42e-12 is typical for the SEElablet. Actual values will be updated during calibration loading
132131
self.resistanceScaling = 1.
133132

134133
self.digital_channel_names=digital_channel_names
@@ -190,7 +189,7 @@ def __runInitSequence__(self,**kwargs):
190189
self.aboutArray.append(['ADC INL Correction found',adc_shifts[0],adc_shifts[1],adc_shifts[2],'...'])
191190
poly_sections = polynomials.split('STOP') #The 2K array is split into sections containing data for ADC_INL fit, ADC_CHANNEL fit, DAC_CHANNEL fit, PCS, CAP ...
192191

193-
adc_slopes_offsets = poly_sections[0]
192+
adc_slopes_offsets = poly_sections[0]
194193
dac_slope_intercept = poly_sections[1]
195194
inl_slope_intercept = poly_sections[2]
196195
#print('COMMON#########',self.__stoa__(slopes_offsets))
@@ -268,7 +267,7 @@ def __runInitSequence__(self,**kwargs):
268267

269268
def get_resistance(self):
270269
V = self.get_average_voltage('SEN')
271-
if V>3.295:return 'Open'
270+
if V>3.295:return np.Inf
272271
I = (3.3-V)/5.1e3
273272
res = V/I
274273
return res*self.resistanceScaling
@@ -705,36 +704,6 @@ def capture_fullspeed_hr(self,chan,samples,tg,*args):
705704

706705
return x,self.analogInputSources[chan].calPoly12(y)
707706

708-
def __charge_cap__(self,state,t):
709-
try:
710-
self.H.__sendByte__(CP.ADC)
711-
self.H.__sendByte__(CP.SET_CAP)
712-
self.H.__sendByte__(state)
713-
self.H.__sendInt__(t)
714-
self.H.__get_ack__()
715-
except Exception as ex:
716-
self.raiseException(ex, "Communication Error , Function : "+inspect.currentframe().f_code.co_name)
717-
718-
def __capture_capacitance__(self,samples,tg):
719-
from PSL.analyticsClass import analyticsClass
720-
self.AC = analyticsClass()
721-
self.__charge_cap__(1,50000)
722-
try:
723-
x,y=self.capture_fullspeed_hr('CAP',samples,tg,'READ_CAP')
724-
except Exception as ex:
725-
self.raiseException(ex, "Communication Error , Function : "+inspect.currentframe().f_code.co_name)
726-
try:
727-
fitres = self.AC.fit_exp(x,y)
728-
if fitres:
729-
cVal,newy = fitres
730-
return x,y,newy,cVal
731-
else:
732-
return None
733-
except Exception as ex:
734-
raise RuntimeError(" Fit Failed ")
735-
736-
def capacitance_via_RC_discharge(self,samples,tg):
737-
return self.__capture_capacitance__(samples,tg)[3]
738707

739708
def __retrieveBufferData__(self,chan,samples,tg):
740709
'''
@@ -1161,6 +1130,7 @@ def set_gain(self,channel,gain,Force=False):
11611130
refresh = False
11621131
if self.gains[channel] != gain:
11631132
self.gains[channel] = gain
1133+
time.sleep(0.01)
11641134
refresh = True
11651135
if refresh or Force:
11661136
try:
@@ -1281,7 +1251,7 @@ def get_average_voltage(self,channel_name,**kwargs):
12811251

12821252
def __get_raw_average_voltage__(self,channel_name,**kwargs):
12831253
"""
1284-
Return the average of 16 raw 10-bit ADC values of the voltage on the selected channel
1254+
Return the average of 16 raw 12-bit ADC values of the voltage on the selected channel
12851255
12861256
.. tabularcolumns:: |p{3cm}|p{11cm}|
12871257
@@ -2571,6 +2541,55 @@ def readPulseCount(self):
25712541
except Exception as ex:
25722542
self.raiseException(ex, "Communication Error , Function : "+inspect.currentframe().f_code.co_name)
25732543

2544+
2545+
2546+
def __charge_cap__(self,state,t):
2547+
try:
2548+
self.H.__sendByte__(CP.ADC)
2549+
self.H.__sendByte__(CP.SET_CAP)
2550+
self.H.__sendByte__(state)
2551+
self.H.__sendInt__(t)
2552+
self.H.__get_ack__()
2553+
except Exception as ex:
2554+
self.raiseException(ex, "Communication Error , Function : "+inspect.currentframe().f_code.co_name)
2555+
2556+
def __capture_capacitance__(self,samples,tg):
2557+
from PSL.analyticsClass import analyticsClass
2558+
self.AC = analyticsClass()
2559+
self.__charge_cap__(1,50000)
2560+
try:
2561+
x,y=self.capture_fullspeed_hr('CAP',samples,tg,'READ_CAP')
2562+
except Exception as ex:
2563+
self.raiseException(ex, "Communication Error , Function : "+inspect.currentframe().f_code.co_name)
2564+
try:
2565+
fitres = self.AC.fit_exp(x*1e-6,y)
2566+
if fitres:
2567+
cVal,newy = fitres
2568+
#from pylab import *
2569+
#plot(x,newy)
2570+
#show()
2571+
return x,y,newy,cVal
2572+
else:
2573+
return None
2574+
except Exception as ex:
2575+
raise RuntimeError(" Fit Failed ")
2576+
2577+
def capacitance_via_RC_discharge(self):
2578+
cap = self.get_capacitor_range()[1]
2579+
T = 2*cap*20e3*1e6 #uS
2580+
samples = 500
2581+
try:
2582+
if T>5000 and T<10e6:
2583+
if T>50e3:samples=250
2584+
RC = self.__capture_capacitance__(samples,int(T/samples))[3][1]
2585+
return RC/10e3
2586+
else:
2587+
return 0
2588+
except Exception as e:
2589+
self.__print__(e)
2590+
return 0
2591+
2592+
25742593
def __get_capacitor_range__(self,ctime):
25752594
try:
25762595
self.__charge_cap__(0,30000)
@@ -2632,7 +2651,7 @@ def get_capacitance(self): #time in uS
26322651
#self.__print__('vals',CR,',',CT)
26332652
if CT>65000:
26342653
self.__print__('CT too high')
2635-
return 0
2654+
return self.capacitance_via_RC_discharge()
26362655
V,C = self.__get_capacitance__(CR,0,CT)
26372656
#print(CR,CT,V,C)
26382657
if CT>30000 and V<0.1:
@@ -2653,11 +2672,13 @@ def get_capacitance(self): #time in uS
26532672
elif V<=0.1 and CR<3:
26542673
CR+=1
26552674
elif CR==3:
2656-
self.__print__('Constant voltage mode ')
2657-
return self.get_capacitor_range()[1]
2675+
self.__print__('Capture mode ')
2676+
return self.capacitance_via_RC_discharge()
26582677
except Exception as ex:
26592678
self.raiseException(ex, "Communication Error , Function : "+inspect.currentframe().f_code.co_name)
26602679

2680+
2681+
26612682
def __calibrate_ctmu__(self,scalers):
26622683
#self.currents=[0.55e-3/scalers[0],0.55e-6/scalers[1],0.55e-5/scalers[2],0.55e-4/scalers[3]]
26632684
self.currents=[0.55e-3,0.55e-6,0.55e-5,0.55e-4]
@@ -3983,7 +4004,7 @@ def opticalArray(self,SS,delay,channel = 'CH3',**kwargs):
39834004
self.H.__sendByte__(CP.TCD1304_HEADER)
39844005
if res==10:self.H.__sendByte__(self.__calcCHOSA__(channel)) #10-bit
39854006
else:self.H.__sendByte__(self.__calcCHOSA__(channel)|0x80) #12-bit
3986-
self.H.__sendByte__(tweak) #Tweak the SH lwo to ICG high space. =tweak*delay
4007+
self.H.__sendByte__(tweak) #Tweak the SH low to ICG high space. =tweak*delay
39874008
self.H.__sendInt__(delay)
39884009
self.H.__sendInt__(int(SS*64))
39894010
self.timebase = SS
@@ -4059,6 +4080,6 @@ def raiseException(self,ex, msg):
40594080
eg.
40604081
I.get_average_voltage('CH1')
40614082
""")
4083+
#I=connect(verbose = True)
4084+
#print (I.get_capacitance())
40624085
#I=connect(verbose=True,load_calibration=False)
4063-
4064-

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy