-
Notifications
You must be signed in to change notification settings - Fork 0
/
InitOscilloscope.m
142 lines (130 loc) · 6.82 KB
/
InitOscilloscope.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
function InitOscilloscope(ScopeObj, range, delay, vrange)
% Instrument Configuration and Control
% Communicating with instrument object, obj1.
%time base settings%
OsciStruct.timebase_range=num2str(range);%something like 400E-6
OsciStruct.timebase_delay=num2str(delay);%something like 200E-6
OsciStruct.timebase_reference='center';
%trigger settings%
OsciStruct.trigger_mode='edge';
OsciStruct.trigger_source='channel2';
% OsciStruct.trigger_level='-2.0'; %original
OsciStruct.trigger_level='2.0';
OsciStruct.trigger_slope='positive';
%acquisition settings%
OsciStruct.acquire_type='average'; %average% %normal%
OsciStruct.acquire_count='1024';
% OsciStruct.acquire_srate='4E9'; %not working
%waveform settings%
OsciStruct.waveform_points_mode='raw';
OsciStruct.waveform_points='10000';
%channel1 settings%
OsciStruct.ch1_display='1';
OsciStruct.ch1_probe='1';
OsciStruct.ch1_range=num2str(vrange);%something like 1400E-3
OsciStruct.ch1_offset='0';
OsciStruct.ch1_coupling='DC';
OsciStruct.ch1_impedance='onemeg'; %ONEMeg%
%channel2 settings%
OsciStruct.ch2_display='0';
OsciStruct.ch2_probe='1';
OsciStruct.ch2_range='40';
OsciStruct.ch2_offset='-10';
OsciStruct.ch2_coupling='DC';
OsciStruct.ch2_impedance='onemeg'; %ONEMeg%
%channel3 settings%
OsciStruct.ch3_display='0';
OsciStruct.ch3_probe='1';
OsciStruct.ch3_range='20';
OsciStruct.ch3_offset='0';
OsciStruct.ch3_coupling='DC';
OsciStruct.ch3_impedance='onemeg'; %ONEMeg%
%channel4 settings%
OsciStruct.ch4_display='0';
OsciStruct.ch4_probe='1';
OsciStruct.ch4_range='20';
OsciStruct.ch4_offset='5';
OsciStruct.ch4_coupling='DC';
OsciStruct.ch4_impedance='onemeg'; %ONEMeg%
fopen(ScopeObj);
Config_Equipment('oscilloscope',ScopeObj,OsciStruct,1);
fclose(ScopeObj);
end
function Config_Equipment(type,obj,cfgstruct,cfgtype)
%type='oscilloscope' or 'fgenerator'%
%obj = equipment object file%
%cfgtype=1,2,3,4 (for oscilloscope channels), 5 (for general oscilloscope
%configuration,6 (function generator channel config), 7 (function generator general config)
if(strcmp(type,'oscilloscope')==1)
if(cfgtype==5||cfgtype==1)
% fprintf(obj,'*RST; :AUTOSCALE');
fprintf(obj,'DISPlay:INTensity:WAVeform 80');
% fprintf(obj,':STOP');
% pause(3);
%Configure timebase
fprintf(obj,strcat('TIMebase:RANGe ',32,cfgstruct.timebase_range));
fprintf(obj,strcat('TIMebase:DELay ',32,cfgstruct.timebase_delay));
fprintf(obj,strcat('TIMebase:REFerence ',32,cfgstruct.timebase_reference));
CheckError('time',obj);
%Configure Trigger
fprintf(obj,strcat('TRIGger:MODE ',32,cfgstruct.trigger_mode)); %Normal triggering
fprintf(obj,strcat('TRIGger:SOURCe ',32,cfgstruct.trigger_source)); %Normal triggering
fprintf(obj,strcat('TRIGger:LEVel ',32,cfgstruct.trigger_level)); %' Trigger level to whatever.
fprintf(obj,strcat('TRIGger:SLOPe ',32,cfgstruct.trigger_slope)); %' Trigger on pos. slope.
CheckError('trigger',obj);
%configure acquisition
fprintf(obj,strcat(':ACQUIRE:TYPE ',32,cfgstruct.acquire_type));
fprintf(obj,strcat(':ACQUIRE:COUNT ',32,cfgstruct.acquire_count));
% fprintf(obj,strcat(':ACQUIRE:SRATe ',32,cfgstruct.acquire_srate));
CheckError('acquisition',obj);
%configure waveform
fprintf(obj,strcat(':WAV:POINTS:MODE ',32,cfgstruct.waveform_points_mode));
fprintf(obj,strcat(':WAV:POINTS ',32,cfgstruct.waveform_points));
CheckError('waveform',obj);
end
if(cfgtype==5||cfgtype==1)
fprintf(obj,strcat('CHANnel1:DISPlay ',32,cfgstruct.ch1_display)); %Turn on channel display.
fprintf(obj,strcat('CHANnel1:PROBe ',32,cfgstruct.ch1_probe)); %Probe attenuation to 1:1.
fprintf(obj,strcat('CHANnel1:RANGe ',32,cfgstruct.ch1_range)); %' Vertical range 10 V full scale.
fprintf(obj,strcat('CHANnel1:OFFSet ',32,cfgstruct.ch1_offset)); %' Offset to -20.
fprintf(obj,strcat('CHANnel1:COUPling ',32,cfgstruct.ch1_coupling)); %' Coupling to DC.
fprintf(obj,strcat('CHANnel1:IMP ',32,cfgstruct.ch1_impedance)); %' impedance
CheckError('chan1',obj);
end
if(cfgtype==5||cfgtype==2)
fprintf(obj,strcat('CHANnel2:DISPlay ',32,cfgstruct.ch2_display)); %Turn on channel display.
fprintf(obj,strcat('CHANnel2:PROBe ',32,cfgstruct.ch2_probe)); %Probe attenuation to 1:1.
fprintf(obj,strcat('CHANnel2:RANGe ',32,cfgstruct.ch2_range)); %' Vertical range 10 V full scale.
fprintf(obj,strcat('CHANnel2:OFFSet ',32,cfgstruct.ch2_offset)); %' Offset to -20.
fprintf(obj,strcat('CHANnel2:COUPling ',32,cfgstruct.ch2_coupling)); %' Coupling to DC.
fprintf(obj,strcat('CHANnel2:IMP ',32,cfgstruct.ch2_impedance)); %' impedance
CheckError('chan2',obj);
end
if(cfgtype==5||cfgtype==3)
fprintf(obj,strcat('CHANnel3:DISPlay ',32,cfgstruct.ch3_display)); %Turn on channel display.
fprintf(obj,strcat('CHANnel3:PROBe ',32,cfgstruct.ch3_probe)); %Probe attenuation to 1:1.
fprintf(obj,strcat('CHANnel3:RANGe ',32,cfgstruct.ch3_range)); %' Vertical range 10 V full scale.
fprintf(obj,strcat('CHANnel3:OFFSet ',32,cfgstruct.ch3_offset)); %' Offset to -20.
fprintf(obj,strcat('CHANnel3:COUPling ',32,cfgstruct.ch3_coupling)); %' Coupling to DC.
fprintf(obj,strcat('CHANnel3:IMP ',32,cfgstruct.ch3_impedance)); %' impedance
CheckError('chan3',obj);
end
if(cfgtype==5||cfgtype==4)
fprintf(obj,strcat('CHANnel4:DISPlay ',32,cfgstruct.ch4_display)); %Turn on channel display.
fprintf(obj,strcat('CHANnel4:PROBe ',32,cfgstruct.ch4_probe)); %Probe attenuation to 1:1.
fprintf(obj,strcat('CHANnel4:RANGe ',32,cfgstruct.ch4_range)); %' Vertical range 10 V full scale.
fprintf(obj,strcat('CHANnel4:OFFSet ',32,cfgstruct.ch4_offset)); %' Offset to -20.
fprintf(obj,strcat('CHANnel4:COUPling ',32,cfgstruct.ch4_coupling)); %' Coupling to DC.
fprintf(obj,strcat('CHANnel4:IMP ',32,cfgstruct.ch4_impedance)); %' impedance
CheckError('chan4',obj);
end
end
end
function CheckError(tag,ScopeObj)
instrumentError = query(ScopeObj,':SYSTEM:ERR?');
% disp(strcat(tag,", found errors:"))
while ~isequal(instrumentError,['+0,"No error"' char(10)])
disp(['Instrument Error: ' instrumentError]);
instrumentError = query(ScopeObj,':SYSTEM:ERR?');
end
end