first version of lakeshore 340 driver
Change-Id: Ie9a68be61e142802b2e71420b87623b7a4b4f645
This commit is contained in:
parent
ee708f7b02
commit
a384664639
36
cfg/ls340_cfg.py
Normal file
36
cfg/ls340_cfg.py
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
Node('ls340test.psi.ch',
|
||||||
|
'ls340 test',
|
||||||
|
'tcp://5000',
|
||||||
|
)
|
||||||
|
Mod('io',
|
||||||
|
'frappy_psi.lakeshore.Ls340IO',
|
||||||
|
'communication to ls340',
|
||||||
|
uri = 'tcp://ldmprep56-ts:3002'
|
||||||
|
)
|
||||||
|
|
||||||
|
Mod('T',
|
||||||
|
'frappy_psi.lakeshore.TemperatureLoop340',
|
||||||
|
'sample temperature',
|
||||||
|
output_module = 'Heater',
|
||||||
|
target = Param(max=470),
|
||||||
|
io = 'io',
|
||||||
|
channel = 'A',
|
||||||
|
)
|
||||||
|
|
||||||
|
Mod('T_cold_finger',
|
||||||
|
'frappy_psi.lakeshore.Sensor340',
|
||||||
|
'cold finger temperature',
|
||||||
|
io = 'io',
|
||||||
|
channel = 'B'
|
||||||
|
)
|
||||||
|
|
||||||
|
Mod('Heater',
|
||||||
|
'frappy_psi.lakeshore.HeaterOutput',
|
||||||
|
'heater output',
|
||||||
|
channel = 'A',
|
||||||
|
io = 'io',
|
||||||
|
resistance = 50,
|
||||||
|
max_power = 50,
|
||||||
|
current = 1
|
||||||
|
)
|
||||||
|
|
173
frappy_psi/lakeshore.py
Normal file
173
frappy_psi/lakeshore.py
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# *****************************************************************************
|
||||||
|
# This program is free software; you can redistribute it and/or modify it under
|
||||||
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
|
# Foundation; either version 2 of the License, or (at your option) any later
|
||||||
|
# version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
||||||
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
||||||
|
# details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License along with
|
||||||
|
# this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
# Module authors:
|
||||||
|
# Oksana Shliakhtun <oksana.shliakhtun@psi.ch>
|
||||||
|
# *****************************************************************************
|
||||||
|
from math import log2
|
||||||
|
|
||||||
|
from frappy.core import Readable, Parameter, IntRange, EnumType, FloatRange, \
|
||||||
|
StringIO, HasIO, StringType, Property, Writable, Drivable, IDLE, ERROR, \
|
||||||
|
Attached
|
||||||
|
from frappy_psi.mixins import HasOutputModule, HasControlledBy
|
||||||
|
|
||||||
|
|
||||||
|
class Ls340IO(StringIO):
|
||||||
|
"""communication with 340CT"""
|
||||||
|
end_of_line = '\r'
|
||||||
|
wait_before = 0.05
|
||||||
|
identification = [('*IDN?', r'LSCI,MODEL340,.*')]
|
||||||
|
|
||||||
|
|
||||||
|
class Sensor340(HasIO, Readable):
|
||||||
|
"""A channel of 340TC"""
|
||||||
|
|
||||||
|
# define the communication class to create the IO module
|
||||||
|
ioClass = Ls340IO
|
||||||
|
|
||||||
|
channel = Property('lakeshore channel', StringType())
|
||||||
|
# define or alter the parameters
|
||||||
|
# as Readable.value exists already, we give only the modified property 'unit'
|
||||||
|
value = Parameter(unit='K')
|
||||||
|
|
||||||
|
def read_value(self):
|
||||||
|
reply = self.communicate(f'KRDG?{self.channel}')
|
||||||
|
return float(reply)
|
||||||
|
|
||||||
|
def read_status(self):
|
||||||
|
c = int(self.communicate(f'RDGST? {self.channel}'))
|
||||||
|
if c >= 128:
|
||||||
|
return ERROR, 'units overrange'
|
||||||
|
if c >= 64:
|
||||||
|
return ERROR, 'units zero'
|
||||||
|
if c >= 32:
|
||||||
|
return ERROR, 'temperature overrange'
|
||||||
|
if c >= 16:
|
||||||
|
return ERROR, 'temperature underrange'
|
||||||
|
if c >= 2:
|
||||||
|
return ERROR, 'old reading'
|
||||||
|
if c >= 1:
|
||||||
|
return ERROR, 'invalid reading'
|
||||||
|
return IDLE, ''
|
||||||
|
|
||||||
|
|
||||||
|
class HeaterOutput(HasControlledBy, HasIO, Writable):
|
||||||
|
loop = Property('lakeshore loop', IntRange(1, 2), default=1)
|
||||||
|
channel = Property('attached channel', StringType())
|
||||||
|
max_power = Parameter('max heater power', datatype=FloatRange(0, 100), unit='W', readonly=False)
|
||||||
|
value = Parameter('heater output', datatype=FloatRange(0, 100), unit='W')
|
||||||
|
target = Parameter('manual heater output', datatype=FloatRange(0, 100), unit='W')
|
||||||
|
resistance = Property('heater resistance', datatype=FloatRange(10, 1000))
|
||||||
|
current = Property('heater current', datatype=FloatRange(0, 2))
|
||||||
|
_range = 0
|
||||||
|
|
||||||
|
MAXCURRENTS = {1: 0.25, 2: 0.5, 3: 1.0, 4: 2.0}
|
||||||
|
RANGES = {1: 1e4, 2: 1e3, 3: 1e2, 4: 1e1, 5: 1}
|
||||||
|
|
||||||
|
SETPOINTLIMS = 999
|
||||||
|
max_current = 0
|
||||||
|
|
||||||
|
STATUS_MAP = {
|
||||||
|
0: (IDLE, ''),
|
||||||
|
1: (ERROR, 'Power supply over voltage'),
|
||||||
|
2: (ERROR, 'Power supply under voltage'),
|
||||||
|
3: (ERROR, 'Output digital-to-analog Converter error'),
|
||||||
|
4: (ERROR, 'Current limit digital-to-analog converter error'),
|
||||||
|
5: (ERROR, 'Open heater load'),
|
||||||
|
6: (ERROR, 'Heater load less than 10 ohms')
|
||||||
|
}
|
||||||
|
|
||||||
|
def earlyInit(self):
|
||||||
|
super().earlyInit()
|
||||||
|
self.CHOICES = sorted([(maxcurrent ** 2 * factor, icurrent, irange)
|
||||||
|
for irange, factor in self.RANGES.items()
|
||||||
|
for icurrent, maxcurrent in self.MAXCURRENTS.items()])
|
||||||
|
|
||||||
|
def write_max_power(self, max_power):
|
||||||
|
prev = 0
|
||||||
|
for i, (factor, icurrent, irange) in enumerate(self.CHOICES):
|
||||||
|
power = min(factor * self.resistance, 2500 / self.resistance)
|
||||||
|
if power >= max_power:
|
||||||
|
if prev >= max_power * 0.9 or prev == power:
|
||||||
|
icurrent, irange = self.CHOICES[i - 1][1:3]
|
||||||
|
break
|
||||||
|
prev = power
|
||||||
|
self._range = irange
|
||||||
|
# CLIMIT + RANGE (using setpoint limit 999)
|
||||||
|
self.communicate(f'CLIMIT {self.loop},{self.SETPOINTLIMS},0,0,{icurrent},{irange}; RANGE {irange};'
|
||||||
|
f'CDISP {self.loop},1,{self.resistance},0;CDISP?{self.loop}')
|
||||||
|
return self.read_max_power()
|
||||||
|
|
||||||
|
def read_max_power(self):
|
||||||
|
setplimit, _, _, icurrent, irange = [
|
||||||
|
float(s) for s in self.communicate(f'CLIMIT? {self.loop}').split(',')]
|
||||||
|
# max_power from codes disregarding voltage limit:
|
||||||
|
self._max_power = self.MAXCURRENTS[icurrent] ** 2 * self.RANGES[irange] * self.resistance
|
||||||
|
# voltage limit = 50V:
|
||||||
|
max_power = min(self._max_power, 2500 / self.resistance)
|
||||||
|
return max_power
|
||||||
|
|
||||||
|
def set_range(self):
|
||||||
|
self.communicate(f'RANGE {self._range}; RANGE?')
|
||||||
|
|
||||||
|
def percent_to_power(self, percent):
|
||||||
|
return min((percent / 100) ** 2 * self._max_power,
|
||||||
|
2500 / self.resistance)
|
||||||
|
|
||||||
|
def power_to_percent(self, power):
|
||||||
|
return (power / self._max_power) ** (1/2) * 100 # limit
|
||||||
|
|
||||||
|
def read_value(self):
|
||||||
|
return self.percent_to_power(float(self.communicate(f'HTR?')))
|
||||||
|
|
||||||
|
def read_status(self):
|
||||||
|
return self.STATUS_MAP[int(self.communicate(f'HTRST?'))]
|
||||||
|
|
||||||
|
def write_target(self, target):
|
||||||
|
self.self_controlled()
|
||||||
|
self.write_max_power(self.max_power)
|
||||||
|
self.set_heater_mode(3)
|
||||||
|
self.set_range()
|
||||||
|
percent = self.power_to_percent(target)
|
||||||
|
reply = self.communicate(f'MOUT {self.loop},{percent:g};MOUT? {self.loop}')
|
||||||
|
return self.percent_to_power(float(reply))
|
||||||
|
|
||||||
|
def set_heater_mode(self, mode):
|
||||||
|
self.communicate(f'CSET {self.loop},{self.channel},1,1,0; CMODE {self.loop},{int(mode)}; CMODE?{self.loop}')
|
||||||
|
|
||||||
|
|
||||||
|
class TemperatureLoop340(HasOutputModule, Sensor340, Drivable):
|
||||||
|
target = Parameter(unit='K')
|
||||||
|
# max_power = Parameter('max heater power', datatype=FloatRange(0, 100), unit='W', readonly=False)
|
||||||
|
# max_current = Parameter('max heater current', datatype=float, unit='A', readonly=False)
|
||||||
|
loop = Property('lakeshore loop', IntRange(1, 2), default=1)
|
||||||
|
|
||||||
|
def write_target(self, target):
|
||||||
|
out = self.output_module
|
||||||
|
if out.controlled_by != self.name:
|
||||||
|
out.write_target(0)
|
||||||
|
out.set_heater_mode(1)
|
||||||
|
out.write_max_power(out.max_power)
|
||||||
|
self.activate_output()
|
||||||
|
out.set_range()
|
||||||
|
reply = self.communicate(f'SETP {self.loop},{target};SETP? {self.loop}')
|
||||||
|
return float(reply)
|
||||||
|
|
||||||
|
def read_target(self):
|
||||||
|
return float(self.communicate(f'SETP?{self.loop}'))
|
||||||
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user