]> sigrok.org Git - libsigrok.git/blame - src/hardware/scpi-pps/profiles.c
scpi-pps: Add profile for Rigol DP821A.
[libsigrok.git] / src / hardware / scpi-pps / profiles.c
CommitLineData
d4eabea8
BV
1/*
2 * This file is part of the libsigrok project.
3 *
4 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
22c18b03 20#include <string.h>
d4eabea8
BV
21#include "protocol.h"
22
23#define CH_IDX(x) (1 << x)
24
22c18b03
BV
25const char *pps_vendors[][2] = {
26 { "RIGOL TECHNOLOGIES", "Rigol" },
bc4a2a46 27 { "HEWLETT-PACKARD", "HP" },
c3eadb07 28 { "PHILIPS", "Philips" },
d4eabea8
BV
29};
30
22c18b03
BV
31const char *get_vendor(const char *raw_vendor)
32{
33 unsigned int i;
34
35 for (i = 0; i < ARRAY_SIZE(pps_vendors); i++) {
36 if (!strcasecmp(raw_vendor, pps_vendors[i][0]))
37 return pps_vendors[i][1];
38 }
39
40 return raw_vendor;
41}
42
584560f1 43static const uint32_t devopts_none[] = { };
bfc86799 44
d4eabea8 45/* Rigol DP800 series */
584560f1 46static const uint32_t rigol_dp800_devopts[] = {
9d9cf1c4 47 SR_CONF_CONTINUOUS | SR_CONF_SET,
5827f61b 48 SR_CONF_OVER_TEMPERATURE_PROTECTION | SR_CONF_GET | SR_CONF_SET,
d4eabea8
BV
49};
50
584560f1 51static const uint32_t rigol_dp800_devopts_cg[] = {
5827f61b
BV
52 SR_CONF_OUTPUT_REGULATION | SR_CONF_GET,
53 SR_CONF_OVER_VOLTAGE_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
54 SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
55 SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
56 SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
57 SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
58 SR_CONF_OVER_CURRENT_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
59 SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
ca95e90f 60 SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
5827f61b 61 SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
ca95e90f 62 SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
5827f61b 63 SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
d4eabea8
BV
64};
65
cfcdf576
ML
66struct channel_spec rigol_dp821a_ch[] = {
67 { "1", { 0, 60, 0.001 }, { 0, 1, 0.0001 } },
68 { "2", { 0, 8, 0.001 }, { 0, 10, 0.001 } },
69};
70
3222ee10
BV
71struct channel_spec rigol_dp831_ch[] = {
72 { "1", { 0, 8, 0.001 }, { 0, 5, 0.0003 } },
73 { "2", { 0, 30, 0.001 }, { 0, 2, 0.0001 } },
74 { "3", { 0, -30, 0.001 }, { 0, 2, 0.0001 } },
d4eabea8
BV
75};
76
3222ee10
BV
77struct channel_spec rigol_dp832_ch[] = {
78 { "1", { 0, 30, 0.001 }, { 0, 3, 0.001 } },
79 { "2", { 0, 30, 0.001 }, { 0, 3, 0.001 } },
80 { "3", { 0, 5, 0.001 }, { 0, 3, 0.001 } },
81};
82
cfcdf576
ML
83struct channel_group_spec rigol_dp820_cg[] = {
84 { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
85 { "2", CH_IDX(1), PPS_OVP | PPS_OCP },
86};
87
88struct channel_group_spec rigol_dp830_cg[] = {
d4eabea8
BV
89 { "1", CH_IDX(0), PPS_OVP | PPS_OCP },
90 { "2", CH_IDX(1), PPS_OVP | PPS_OCP },
91 { "3", CH_IDX(2), PPS_OVP | PPS_OCP },
92};
93
3222ee10 94struct scpi_command rigol_dp800_cmd[] = {
60475cd7
BV
95 { SCPI_CMD_REMOTE, "SYST:REMOTE" },
96 { SCPI_CMD_LOCAL, "SYST:LOCAL" },
ee2860ee
BV
97 { SCPI_CMD_BEEPER, "SYST:BEEP:STAT?" },
98 { SCPI_CMD_BEEPER_ENABLE, "SYST:BEEP:STAT ON" },
99 { SCPI_CMD_BEEPER_DISABLE, "SYST:BEEP:STAT OFF" },
60475cd7
BV
100 { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
101 { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
102 { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
103 { SCPI_CMD_GET_MEAS_POWER, ":MEAS:POWE?" },
104 { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
105 { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
106 { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
107 { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
108 { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
109 { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
110 { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
111 { SCPI_CMD_GET_OUTPUT_REGULATION, ":OUTP:MODE?" },
d4eabea8 112 { SCPI_CMD_GET_OVER_TEMPERATURE_PROTECTION, ":SYST:OTP?" },
53a81803
BV
113 { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_ENABLE, ":SYST:OTP ON" },
114 { SCPI_CMD_SET_OVER_TEMPERATURE_PROTECTION_DISABLE, ":SYST:OTP OFF" },
60475cd7
BV
115 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ENABLED, ":OUTP:OVP?" },
116 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_ENABLE, ":OUTP:OVP ON" },
117 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_DISABLE, ":OUTP:OVP OFF" },
118 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":OUTP:OVP:QUES?" },
119 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL?" },
120 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":OUTP:OVP:VAL %.6f" },
121 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":OUTP:OCP?" },
122 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":OUTP:OCP:STAT ON" },
123 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":OUTP:OCP:STAT OFF" },
124 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":OUTP:OCP:QUES?" },
125 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL?" },
126 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_THRESHOLD, ":OUTP:OCP:VAL %.6f" },
d4eabea8
BV
127};
128
bfc86799 129/* HP 663xx series */
584560f1 130static const uint32_t hp_6632b_devopts[] = {
9d9cf1c4 131 SR_CONF_CONTINUOUS | SR_CONF_SET,
5827f61b
BV
132 SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
133 SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
134 SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
ca95e90f
BV
135 SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
136 SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
bc4a2a46
BV
137};
138
139struct channel_spec hp_6632b_ch[] = {
140 { "1", { 0, 20.475, 0.005 }, { 0, 5.1188, 0.00132 } },
141};
142
143struct channel_group_spec hp_6632b_cg[] = {
144 { "1", CH_IDX(0), 0 },
145};
146
147struct scpi_command hp_6632b_cmd[] = {
148 { SCPI_CMD_GET_OUTPUT_ENABLED, "OUTP:STAT?" },
53a81803
BV
149 { SCPI_CMD_SET_OUTPUT_ENABLE, "OUTP:STAT ON" },
150 { SCPI_CMD_SET_OUTPUT_DISABLE, "OUTP:STAT OFF" },
bc4a2a46
BV
151 { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
152 { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
ca95e90f
BV
153 { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
154 { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
155 { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
156 { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
bc4a2a46
BV
157};
158
c3eadb07 159/* Philips/Fluke PM2800 series */
9d9cf1c4
BV
160static const uint32_t philips_pm2800_devopts[] = {
161 SR_CONF_CONTINUOUS | SR_CONF_SET,
162};
163
c3eadb07
BV
164static const uint32_t philips_pm2800_devopts_cg[] = {
165 SR_CONF_OUTPUT_ENABLED | SR_CONF_GET | SR_CONF_SET,
166 SR_CONF_OUTPUT_VOLTAGE | SR_CONF_GET,
167 SR_CONF_OUTPUT_VOLTAGE_TARGET | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
168 SR_CONF_OUTPUT_CURRENT | SR_CONF_GET,
169 SR_CONF_OUTPUT_CURRENT_LIMIT | SR_CONF_GET | SR_CONF_SET | SR_CONF_LIST,
170 SR_CONF_OVER_VOLTAGE_PROTECTION_ACTIVE | SR_CONF_GET,
171 SR_CONF_OVER_VOLTAGE_PROTECTION_THRESHOLD | SR_CONF_GET | SR_CONF_SET,
172 SR_CONF_OVER_CURRENT_PROTECTION_ENABLED | SR_CONF_GET | SR_CONF_SET,
173 SR_CONF_OVER_CURRENT_PROTECTION_ACTIVE | SR_CONF_GET,
174 SR_CONF_OUTPUT_REGULATION | SR_CONF_GET,
175};
176
177enum philips_pm2800_modules {
178 PM2800_MOD_30V_10A = 1,
179 PM2800_MOD_60V_5A,
180 PM2800_MOD_60V_10A,
181 PM2800_MOD_8V_15A,
182 PM2800_MOD_60V_2A,
183 PM2800_MOD_120V_1A,
184};
185
186static struct philips_pm2800_module_spec {
187 /* Min, max, programming resolution. */
188 float voltage[3];
189 float current[3];
190} philips_pm2800_module_specs[] = {
191 /* Autoranging modules. */
192 [PM2800_MOD_30V_10A] = { { 0, 30, 0.0075 }, { 0, 10, 0.0025 } },
193 [PM2800_MOD_60V_5A] = { { 0, 60, 0.015 }, { 0, 5, 0.00125 } },
194 [PM2800_MOD_60V_10A] = { { 0, 60, 0.015 }, { 0, 10, 0.0025 } },
195 /* Linear modules. */
196 [PM2800_MOD_8V_15A] = { { 0, 8, 0.002 }, { -15, 15, 0.00375 } },
197 [PM2800_MOD_60V_2A] = { { 0, 60, 0.015 }, { -2, 2, 0.0005 } },
198 [PM2800_MOD_120V_1A] = { { 0, 120, 0.030 }, { -1, 1, 0.00025 } },
199};
200
201static struct philips_pm2800_model {
202 unsigned int chassis;
203 unsigned int num_modules;
204 unsigned int set;
205 unsigned int modules[3];
206} philips_pm2800_matrix[] = {
207 /* Autoranging chassis. */
208 { 1, 1, 0, { PM2800_MOD_30V_10A, 0, 0 } },
209 { 1, 1, 1, { PM2800_MOD_60V_5A, 0, 0 } },
210 { 1, 2, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, 0 } },
211 { 1, 2, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, 0 } },
212 { 1, 2, 2, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, 0 } },
213 { 1, 2, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_10A, 0 } },
214 { 1, 2, 4, { PM2800_MOD_60V_5A, PM2800_MOD_60V_10A, 0 } },
215 { 1, 3, 0, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_30V_10A } },
216 { 1, 3, 1, { PM2800_MOD_60V_5A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
217 { 1, 3, 2, { PM2800_MOD_30V_10A, PM2800_MOD_30V_10A, PM2800_MOD_60V_5A } },
218 { 1, 3, 3, { PM2800_MOD_30V_10A, PM2800_MOD_60V_5A, PM2800_MOD_60V_5A } },
219 /* Linear chassis. */
220 { 3, 1, 0, { PM2800_MOD_60V_2A, 0, 0 } },
221 { 3, 1, 1, { PM2800_MOD_120V_1A, 0, 0 } },
222 { 3, 1, 2, { PM2800_MOD_8V_15A, 0, 0 } },
223 { 3, 2, 0, { PM2800_MOD_60V_2A, 0, 0 } },
224 { 3, 2, 1, { PM2800_MOD_120V_1A, 0, 0 } },
225 { 3, 2, 2, { PM2800_MOD_60V_2A, PM2800_MOD_120V_1A, 0 } },
226 { 3, 2, 3, { PM2800_MOD_8V_15A, PM2800_MOD_8V_15A, 0 } },
227};
228
229static char *philips_pm2800_names[] = { "1", "2", "3" };
230
231static int philips_pm2800_probe_channels(struct sr_dev_inst *sdi,
232 struct sr_scpi_hw_info *hw_info,
233 struct channel_spec **channels, unsigned int *num_channels,
234 struct channel_group_spec **channel_groups, unsigned int *num_channel_groups)
235{
236 struct philips_pm2800_model *model;
237 struct philips_pm2800_module_spec *spec;
238 unsigned int chassis, num_modules, set, module, m, i;
239
240 (void)sdi;
241
242 /*
243 * The model number as reported by *IDN? looks like e.g. PM2813/11,
244 * Where "PM28" is fixed, followed by the chassis code (1 = autoranging,
245 * 3 = linear series) and the number of modules: 1-3 for autoranging,
246 * 1-2 for linear.
247 * After the slash, the first digit denotes the module set. The
248 * digit after that denotes front (5) or rear (1) binding posts.
249 */
250 chassis = hw_info->model[4] - 0x30;
251 num_modules = hw_info->model[5] - 0x30;
252 set = hw_info->model[7] - 0x30;
253 for (m = 0; m < ARRAY_SIZE(philips_pm2800_matrix); m++) {
254 model = &philips_pm2800_matrix[m];
255 if (model->chassis == chassis && model->num_modules == num_modules
256 && model->set == set)
257 break;
258 }
259 if (m == ARRAY_SIZE(philips_pm2800_matrix)) {
260 sr_dbg("Model %s not found in matrix.", hw_info->model);
261 return SR_ERR;
262 }
263
264 sr_dbg("Found %d output channel%s:", num_modules, num_modules > 1 ? "s" : "");
265 *channels = g_malloc0(sizeof(struct channel_spec) * num_modules);
266 *channel_groups = g_malloc0(sizeof(struct channel_group_spec) * num_modules);
267 for (i = 0; i < num_modules; i++) {
268 module = model->modules[i];
269 spec = &philips_pm2800_module_specs[module];
270 sr_dbg("output %d: %.0f - %.0fV, %.0f - %.0fA", i + 1,
271 spec->voltage[0], spec->voltage[1],
272 spec->current[0], spec->current[1]);
273 (*channels)[i].name = philips_pm2800_names[i];
274 memcpy(&((*channels)[i].voltage), spec, sizeof(float) * 6);
275 (*channel_groups)[i].name = philips_pm2800_names[i];
276 (*channel_groups)[i].channel_index_mask = 1 << i;
277 (*channel_groups)[i].features = PPS_OTP | PPS_OVP | PPS_OCP;
278 }
279 *num_channels = *num_channel_groups = num_modules;
280
281 return SR_OK;
282}
283
284struct scpi_command philips_pm2800_cmd[] = {
285 { SCPI_CMD_SELECT_CHANNEL, ":INST:NSEL %s" },
286 { SCPI_CMD_GET_MEAS_VOLTAGE, ":MEAS:VOLT?" },
287 { SCPI_CMD_GET_MEAS_CURRENT, ":MEAS:CURR?" },
288 { SCPI_CMD_GET_VOLTAGE_TARGET, ":SOUR:VOLT?" },
289 { SCPI_CMD_SET_VOLTAGE_TARGET, ":SOUR:VOLT %.6f" },
290 { SCPI_CMD_GET_CURRENT_LIMIT, ":SOUR:CURR?" },
291 { SCPI_CMD_SET_CURRENT_LIMIT, ":SOUR:CURR %.6f" },
292 { SCPI_CMD_GET_OUTPUT_ENABLED, ":OUTP?" },
293 { SCPI_CMD_SET_OUTPUT_ENABLE, ":OUTP ON" },
294 { SCPI_CMD_SET_OUTPUT_DISABLE, ":OUTP OFF" },
295 { SCPI_CMD_GET_OUTPUT_REGULATION, ":SOUR:FUNC:MODE?" },
296 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_ACTIVE, ":SOUR:VOLT:PROT:TRIP?" },
297 { SCPI_CMD_GET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV?" },
298 { SCPI_CMD_SET_OVER_VOLTAGE_PROTECTION_THRESHOLD, ":SOUR:VOLT:PROT:LEV %.6f" },
299 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ENABLED, ":SOUR:CURR:PROT:STAT?" },
300 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_ENABLE, ":SOUR:CURR:PROT:STAT ON" },
301 { SCPI_CMD_SET_OVER_CURRENT_PROTECTION_DISABLE, ":SOUR:CURR:PROT:STAT OFF" },
302 { SCPI_CMD_GET_OVER_CURRENT_PROTECTION_ACTIVE, ":SOUR:CURR:PROT:TRIP?" },
303};
304
bc4a2a46 305
d4eabea8 306SR_PRIV const struct scpi_pps pps_profiles[] = {
bc4a2a46
BV
307 /* HP 6632B */
308 { "HP", "6632B", 0,
309 ARRAY_AND_SIZE(hp_6632b_devopts),
bfc86799 310 ARRAY_AND_SIZE(devopts_none),
bc4a2a46
BV
311 ARRAY_AND_SIZE(hp_6632b_ch),
312 ARRAY_AND_SIZE(hp_6632b_cg),
313 ARRAY_AND_SIZE(hp_6632b_cmd),
c3eadb07 314 .probe_channels = NULL,
bc4a2a46
BV
315 },
316
d4eabea8 317 /* Rigol DP800 series */
cfcdf576
ML
318 { "Rigol", "^DP821A$", PPS_OTP,
319 ARRAY_AND_SIZE(rigol_dp800_devopts),
320 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
321 ARRAY_AND_SIZE(rigol_dp821a_ch),
322 ARRAY_AND_SIZE(rigol_dp820_cg),
323 ARRAY_AND_SIZE(rigol_dp800_cmd),
324 .probe_channels = NULL,
325 },
3222ee10
BV
326 { "Rigol", "^DP831A$", PPS_OTP,
327 ARRAY_AND_SIZE(rigol_dp800_devopts),
328 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
329 ARRAY_AND_SIZE(rigol_dp831_ch),
cfcdf576 330 ARRAY_AND_SIZE(rigol_dp830_cg),
3222ee10 331 ARRAY_AND_SIZE(rigol_dp800_cmd),
c3eadb07 332 .probe_channels = NULL,
3222ee10
BV
333 },
334 { "Rigol", "^(DP832|DP832A)$", PPS_OTP,
335 ARRAY_AND_SIZE(rigol_dp800_devopts),
336 ARRAY_AND_SIZE(rigol_dp800_devopts_cg),
337 ARRAY_AND_SIZE(rigol_dp832_ch),
cfcdf576 338 ARRAY_AND_SIZE(rigol_dp830_cg),
3222ee10 339 ARRAY_AND_SIZE(rigol_dp800_cmd),
c3eadb07
BV
340 .probe_channels = NULL,
341 },
342
343 /* Philips/Fluke PM2800 series */
344 { "Philips", "^PM28[13][123]/[01234]{1,2}$", 0,
9d9cf1c4 345 ARRAY_AND_SIZE(philips_pm2800_devopts),
c3eadb07
BV
346 ARRAY_AND_SIZE(philips_pm2800_devopts_cg),
347 NULL, 0,
348 NULL, 0,
349 ARRAY_AND_SIZE(philips_pm2800_cmd),
350 philips_pm2800_probe_channels,
d4eabea8
BV
351 },
352};
353SR_PRIV unsigned int num_pps_profiles = ARRAY_SIZE(pps_profiles);
354