-
Notifications
You must be signed in to change notification settings - Fork 0
/
instLDC_Prototype.m
109 lines (99 loc) · 3.83 KB
/
instLDC_Prototype.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
%% instLDC_Prototype.m MN 2020-06-26
% Template for LDC (Laser Diode Controller: IV + TEC) interface
%
% Requirements:
% - VISA interface functions in path
% - Equipment is connected on specified VISA address
%
% Usage: [current, voltage, temperature] = instLDC_Prototype(visaAddr, option[, value])
% Returns:
% current: Returns diode output current
% voltage: Returns diode output voltage
% temperautre: Returns TEC temperature reading
%
% Parameters:
% visaAddr: Valid VISA address with a diode controller connected
% 'option': One of available options below
% 'value': Value for options that require it
%
% Options:
% 'reset': Resets/initializes LDC
% 'read' | 'curstate' | 'measure': Returns present [I, V, T]
% 'state', %i: Turns diode output on or off
% 'on': Same as 'state', 1
% 'off': Same as 'state', 0
% 'current', %f: Sets output current to this if possible (amps)
% 'limit', [%f, %f]: Sets diode output current and voltage limits (amps, volts)
% 'set', %f: Changes TEC temperature setpoint to this; <0 for 'off'
%
% TODO:
% - Add more options
% - Confirm units
function [current, voltage, temperature] = instLDC_Prototype(visaAddr, option, value)
%% Helper functions
ldcWrite = @(x) visaWrite(visaAddr, x);
ldcQuery = @(x) str2double(visaRead(visaAddr, x));
%% Defaults and magic numbers
current = NaN; voltage = NaN; temperature = NaN;
%% Execute selected command
switch lower(option)
case 'reset'
% Set standard settings
ldcWrite('*RST'); pause(0.5); ldcWrite('*CAL?');
ldcWrite('LAS:OUT 0;LAS:LIM:V 5;LAS:RAN 2;LAS:LDI 15e-3');
ldcWrite('TEC:OUT 0;TEC:MODE:T;TEC:T 20');
case {'state', 'on', 'off'}
if ~exist('value', 'var'); value = find(strcmpi(option, {'off', 'on'}),1)-1; end % Find the state if not specified
% Set state
switch value>0
case 1
ldcWrite('LAS:MODE:ILBW'); % Constant-current mode
ldcWrite('LAS:OUT 1');
case 0
ldcWrite('LAS:OUT 0');
end
case {'read', 'curstate', 'measure'}
% Read the current output values
current = ldcQuery('LAS:LDI?')*1e3; % Return A
voltage = ldcQuery('LAS:LDV?');
temperature = ldcQuery('TEC:T?');
case 'current'
% Set diode output current
if ~exist('value', 'var'); error('Value not provided for diode current!'); end
% This model has two ranges: 200mA and 500mA
if value <= 0.2
ldcWrite('LAS:RAN 2');
else
ldcWrite('LAS:RAN 5');
end
ldcWrite(sprintf('LAS:LDI %f', double(value*1e3))); % Input in A
case 'limit'
% Set diode current and voltage limits
if ~exist('value', 'var'); error('Value not provided for diode output limits!'); end
% This model has two ranges: 200mA and 500mA
if value(1) <= 0.2
ldcWrite(sprintf('LAS:LIM:I2 %f', double(value(1)*1e3))); % Input in A
ldcWrite('LAS:RAN 2');
else
ldcWrite(sprintf('LAS:LIM:I5 %f', double(value(1)*1e3))); % Input in A
ldcWrite('LAS:RAN 5');
end
if length(value) > 1
ldcWrite(sprintf('LAS:LIM:V %f', double(value(2))));
end
case 'set'
% Set TEC temperature
if ~exist('value', 'var'); error('Value not provided for TEC setpoint!'); end
ldcWrite('TEC:OUT 0;TEC:MODE:T');
if value >= 0
ldcWrite(sprintf('TEC:T %f', double(value)));
if (ldcRead('TEC:T?') - value) < 1e-2 % Setpoint mismatch
ldcWrite('TEC:OUT 1');
else
error('Attempted to set temperature to %f, but inconsistent values: aborting!', value);
end
end
end
%% Clean up
% ldcWrite('LOCAL'); % Switch back to local mode
end