Debian Codegraph @

pymeasure/instruments/tektronix/afg3152c.py

raw
1 #
2 # This file is part of the PyMeasure package.
3 #
4 # Copyright (c) 2013-2024 PyMeasure Developers
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in
14 # all copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 # THE SOFTWARE.
23 #
24 from math import sqrt, log10
25 from pymeasure.instruments import Instrument, Channel, SCPIUnknownMixin
26 from pymeasure.instruments.validators import strict_range, strict_discrete_set
27
28
29 class AFG3152CChannel(Channel):
30 SHAPES = {
31 "sinusoidal": "SIN",
32 "square": "SQU",
33 "pulse": "PULS",
34 "ramp": "RAMP",
35 "prnoise": "PRN",
36 "dc": "DC",
37 "sinc": "SINC",
38 "gaussian": "GAUS",
39 "lorentz": "LOR",
40 "erise": "ERIS",
41 "edecay": "EDEC",
42 "haversine": "HAV",
43 }
44 FREQ_LIMIT = [1e-6, 150e6] # Frequency limit for sinusoidal function
45 DUTY_LIMIT = [0.001, 99.999]
46 AMPLITUDE_LIMIT = {
47 "VPP": [20e-3, 10],
48 "VRMS": list(map(lambda x: round(x / 2 / sqrt(2), 3), [20e-3, 10])),
49 "DBM": list(
50 map(lambda x: round(20 * log10(x / 2 / sqrt(0.1)), 2), [20e-3, 10])
51 ),
52 } # Vpp, Vrms and dBm limits
53 UNIT_LIMIT = ["VPP", "VRMS", "DBM"]
54 IMP_LIMIT = [1, 1e4]
55
56 shape = Instrument.control(
57 "function:shape?",
58 "function:shape %s",
59 """ Control the shape of the output. (str)""",
60 validator=strict_discrete_set,
61 values=SHAPES,
62 map_values=True,
63 )
64
65 unit = Instrument.control(
66 "voltage:unit?",
67 "voltage:unit %s",
68 """ Control the amplitude unit. (str)""",
69 validator=strict_discrete_set,
70 values=UNIT_LIMIT,
71 )
72
73 amp_vpp = Instrument.control(
74 "voltage:amplitude?",
75 "voltage:amplitude %eVPP",
76 """Control the output amplitude in Vpp. (float)""",
77 validator=strict_range,
78 values=AMPLITUDE_LIMIT["VPP"],
79 )
80
81 amp_dbm = Instrument.control(
82 "voltage:amplitude?",
83 "voltage:amplitude %eDBM",
84 """ Control the output amplitude in dBm. (float)""",
85 validator=strict_range,
86 values=AMPLITUDE_LIMIT["DBM"],
87 )
88
89 amp_vrms = Instrument.control(
90 "voltage:amplitude?",
91 "voltage:amplitude %eVRMS",
92 """ Control the output amplitude in Vrms. (float)""",
93 validator=strict_range,
94 values=AMPLITUDE_LIMIT["VRMS"],
95 )
96
97 offset = Instrument.control(
98 "voltage:offset?",
99 "voltage:offset %e",
100 """ Control the amplitude offset. It is always in Volt. (float)""",
101 )
102
103 frequency = Instrument.control(
104 "frequency:fixed?",
105 "frequency:fixed %e",
106 """ Control the frequency. (float)""",
107 validator=strict_range,
108 values=FREQ_LIMIT,
109 )
110
111 duty = Instrument.control(
112 "pulse:dcycle?",
113 "pulse:dcycle %.3f",
114 """ Control the duty cycle of pulse. (float))""",
115 validator=strict_range,
116 values=DUTY_LIMIT,
117 )
118
119 impedance = Instrument.control(
120 "output:impedance?",
121 "output:impedance %d",
122 """ Control the output impedance of the channel. Be careful with this.""",
123 validator=strict_range,
124 values=IMP_LIMIT,
125 cast=int,
126 )
127
128 def insert_id(self, command):
129 """Prepend the channel id for most writes."""
130 return f'source{self.id}:{command}'
131
132 def enable(self):
133 self.parent.write("output%d:state on" % self.number)
134
135 def disable(self):
136 self.parent.write("output%d:state off" % self.number)
137
138 def waveform(
139 self, shape="SIN", frequency=1e6, units="VPP", amplitude=1, offset=0
140 ):
141 """General setting method for a complete wavefunction"""
142 self.write("function:shape %s" % shape)
143 self.write("frequency:fixed %e" % frequency)
144 self.write("voltage:unit %s" % units)
145 self.write("voltage:amplitude %e%s" % (amplitude, units))
146 self.write("voltage:offset %eV" % offset)
147
148
149 class AFG3152C(SCPIUnknownMixin, Instrument):
150 """Represents the Tektronix AFG 3000 series (one or two channels)
151 arbitrary function generator and provides a high-level for
152 interacting with the instrument.
153
154 .. code-block:: python
155
156 afg=AFG3152C("GPIB::1") # AFG on GPIB 1
157 afg.reset() # Reset to default
158 afg.ch1.shape='sinusoidal' # Sinusoidal shape
159 afg.ch1.unit='VPP' # Sets CH1 unit to VPP
160 afg.ch1.amp_vpp=1 # Sets the CH1 level to 1 VPP
161 afg.ch1.frequency=1e3 # Sets the CH1 frequency to 1KHz
162 afg.ch1.enable() # Enables the output from CH1
163 """
164
165 def __init__(self, adapter, name="Tektronix AFG3152C arbitrary function generator", **kwargs):
166 super().__init__(
167 adapter,
168 name,
169 **kwargs
170 )
171 self.ch1 = AFG3152CChannel(self, 1)
172 self.ch2 = AFG3152CChannel(self, 2)
173
174 def beep(self):
175 self.write("system:beep")
176
177 def opc(self):
178 return int(self.ask("*OPC?"))