from __future__ import print_function
import numpy as np
gains=[1,2,4,5,8,10,16,32]
#-----------------------Classes for input sources----------------------
allAnalogChannels = ['CH1','CH2','CH3','MIC','CAP','SEN','AN8']
bipolars = ['CH1','CH2','CH3','MIC']
inputRanges={'CH1':[16.5,-16.5], #Specify inverted channels explicitly by reversing range!!!!!!!!!
'CH2':[16.5,-16.5],
'CH3':[-3.3,3.3], #external gain control analog input
'MIC':[-3.3,3.3], #connected to MIC amplifier
'CAP':[0,3.3],
'SEN':[0,3.3],
'AN8':[0,3.3]
}
picADCMultiplex={'CH1':3,'CH2':0,'CH3':1,'MIC':2,'AN4':4,'SEN':7,'CAP':5,'AN8':8,}
'''
for a in ['CH1']:
x=analogInputSource(a)
print (x.name,x.calPoly10#,calfacs[x.name][0])
print ('CAL:',x.calPoly10(0),x.calPoly10(1023))
x.setOffset(1.65)
x.setGain(32)
print (x.name,x.calPoly10#,calfacs[x.name][0])
print ('CAL:',x.calPoly10(0),x.calPoly10(1023))
'''
#---------------------------------------------------------------------
[docs]class analogAcquisitionChannel:
'''
This class takes care of oscilloscope data fetched from the device.
Each instance may be linked to a particular input.
Since only up to two channels may be captured at a time with the vLabtool, only two instances will be required
Each instance will be linked to a particular inputSource instance by the capture routines.
When data is requested , it will return after applying calibration and gain details
stored in the selected inputSource
'''
def __init__(self,a):
self.name=''
self.gain=0
self.channel=a
self.channel_names=allAnalogChannels
#REFERENCE VOLTAGE = 3.3 V
self.calibration_ref196=1.#measured reference voltage/3.3
self.resolution=10
self.xaxis=np.zeros(10000)
self.yaxis=np.zeros(10000)
self.length=100
self.timebase = 1.
self.source = analogInputSource('CH1') #use CH1 for initialization. It will be overwritten by set_params
[docs] def fix_value(self,val):
#val[val>1020]=np.NaN
#val[val<2]=np.NaN
if self.resolution==12:
return self.calibration_ref196*self.source.calPoly12(val)
else:return self.calibration_ref196*self.source.calPoly10(val)
[docs] def set_yval(self,pos,val):
self.yaxis[pos] = self.fix_value(val)
[docs] def set_xval(self,pos,val):
self.xaxis[pos] = val
[docs] def set_params(self,**keys):
self.gain = keys.get('gain',self.gain)
self.name = keys.get('channel',self.channel)
self.source = keys.get('source',self.source)
self.resolution = keys.get('resolution',self.resolution)
l = keys.get('length',self.length)
t = keys.get('timebase',self.timebase)
if t != self.timebase or l != self.length:
self.timebase = t
self.length = l
self.regenerate_xaxis()
[docs] def regenerate_xaxis(self):
for a in range(int(self.length)): self.xaxis[a] = self.timebase*a
[docs] def get_xaxis(self):
return self.xaxis[:self.length]
[docs] def get_yaxis(self):
return self.yaxis[:self.length]