##// END OF EJS Templates
analog disco: Enabled filtering on acq and added analog out enable/disable functions
analog disco: Enabled filtering on acq and added analog out enable/disable functions

File last commit:

r9:142b4267322d default
r13:669810a4267c default
Show More
discoply.py
87 lines | 2.6 KiB | text/x-python | PythonLexer
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""Simple python library to drive the analog discovery module from www.digilentinc.com
With Discoply addon connected https://hephaistos.lpp.polytechnique.fr/rhodecode/HG_REPOSITORIES/LPP/INSTRUMENTATION/PCB/DiscoPli
"""
from ctypes import *
import time
import sys
import os
import matplotlib.pyplot as plt
import numpy as np
from lppinstru import discovery
__author__ = "Alexis Jeandet"
__copyright__ = "Copyright 2015, Laboratory of Plasma Physics"
__credits__ = []
__license__ = "GPLv2"
__version__ = "1.0.0"
__maintainer__ = "Alexis Jeandet"
__email__ = "alexis.jeandet@member.fsf.org"
__status__ = "Production"
class discoply(discovery.Discovery):
_gains={
"LTC-6910-1":[0, 1, 2, 5, 10, 20, 50, 100],
"LTC-6910-2":[0, 1, 2, 4, 8, 16, 32, 64],
"LTC-6910-3":[0, 1, 2, 3, 4, 5, 6, 7]
}
def __init__(self,card=-1,model="LTC-6910-1",gain_ch1=1,gain_ch2=1):
super(discoply,self).__init__(card)
self._model=model
self.set_power()
self.digital_io_output_enable(0x3F)
self.gain_idx = [gain_ch1,gain_ch2]
def auto_remove_offset(self,channel=0):
out=0.0
for i in range(10):
self.analog_out_gen(shape="DC",offset=out)
time.sleep(0.2)
mean=super(discoply,self).analog_in_read(frequency=1e5,samplesCount=8192)[0][channel].mean()
out+=-mean*14./self.gain[channel]
return mean
def analog_in_read(self,ch1=True,ch2=True,frequency=100000000,samplesCount=100,ch1range=5.0,ch2range=5.0,trigger=discovery.trigsrcNone):
data=super(discoply,self).analog_in_read(ch1,ch2,frequency,samplesCount,ch1range,ch2range,trigger)
if self.gain[0] !=0:
data[0][0]=data[0][0]/self.gain[0]
if self.gain[1] !=0:
data[0][1]=data[0][1]/self.gain[1]
return data
@property
def offset(self):
data=super(discoply,self).analog_in_read(frequency=1e4,samplesCount=8192)[0]
return [data[0].mean(),data[1].mean()]
@property
def gain(self):
return [
self._gains[self._model][self.gain_idx[0]],
self._gains[self._model][self.gain_idx[1]]]
@property
def gain_idx(self):
dio=self.digital_io
return [dio&7,(dio>>3)&7]
@gain_idx.setter
def gain_idx(self,value):
self.digital_io =(value[0]&7) + ((value[1]&7)<<3)
def set_gain_idx(self,value,channel):
gain = self.gain & ~(7 << [0,3][channel])
self.gain_idx = gain + (value << [0,3][channel])
if __name__ == '__main__':
quit()