% MDA: Agilent Infiniium Oscilloscope model number 54845A, s/n US40020193 % MDA: Oscilloscope IP address: 148.88.156.198 Subnet mask: 255.255.0.0 % MDA: Host PC IP address: 10.48.240.61 Subnet mask: 255.255.255.255 % MDA: Preferred DNS server: 148.88.65.52 Alternative DNS server: 148.88.65.53 % Clear all variables, functions & MEX-files, and close all figures if exist('t') fclose(t); end clear all close all % File and acquisition setup title = 'Oscilloscope: File & acquisition set up'; prompt = {'File directory', 'File name', ... 'Number of events', 'Sample rate (Sa/s)', 'Acquisition points'}; defAns = {'C:\Diamond Experiment\', 'Diamond_Saed', '10', '8E9', '400'}; % MDA: At 8 GSa/s and 400 samples we have an acquisition window of 50 ns FileData = inputdlg(prompt, title, 1, defAns); DestDir = char(FileData(1)); DestFile = char(FileData(2)); EventCount = str2double(FileData(3)); SampFreq = char(FileData(4)); AcqPoints = char(FileData(5)); Frequency = str2double(FileData(4)); Points = str2double(FileData(5)); TimeBase = num2str((1/str2double(SampFreq))*str2double(AcqPoints)); % MDA: This calculates the hortizontal fullscale range based on sample rate and number of acquisiton points %strBuffer = ['%', num2str(length(num2str(Points*2))+2), 's']; % Trigger setup title = 'Channel 3: Trigger set up'; % MDA: Channel 1 on the Agilent Infiniium oscilliscope s/n US40040193 is faulty, we're therefore using channel 3 prompt = {'Trigger level (V)', 'Time trigger offset (s)'}; defAns = {'22.0E-3', '10E-09'}; TrigData = inputdlg(prompt, title, 1, defAns); TrigLevel = char(TrigData(1)); TrigOffset = char(TrigData(2)); % Channel 3 voltage axis setup title = 'Channel 3: Voltage axis set up'; prompt = {'Voltage full scale range (V)', 'Voltage offset (V)'}; % MDA: for the voltage offset, +ve moves signal down, -ve moves signal up defAns = {'80.0E-03', '20.0E-3'}; VoltData = inputdlg(prompt, title, 1, defAns); % Connect to the oscilloscope t = visa('agilent', 'TCPIP0::148.88.156.198::INSTR'); set(t, 'InputBufferSize', 2602144,'Timeout', 350); fopen(t); fwrite(t, '*CLS'); % Configure the oscilloscope fwrite(t, [':CHANNEL3:RANGE ', char(VoltData(1))]); fwrite(t, [':CHANNEL3:OFFSET ', char(VoltData(2))]); fwrite(t, ':CHANnel3:INPut DC50'); fwrite(t, ':ACQUIRE:CONFIG SINGLE'); fwrite(t, [':ACQUIRE:SRATE ', SampFreq]); fwrite(t, [':ACQUIRE:POINTS ', AcqPoints]); fwrite(t, ':ACQUIRE:MODE RTIME;AVERAGE OFF'); fwrite(t, ':TIMebase:REFerence CENTer'); fwrite(t, [':TIMEBASE:POS ', TrigOffset]); fwrite(t, [':TIMEBASE:RANGE ', TimeBase]); fwrite(t, ':TRIGGER:EDGE:COUPLING DC'); fwrite(t, ':TRIGGER:EDGE:SOURCE CHAN3'); fwrite(t, [':TRIGGER:LEVEL CHAN3,', TrigLevel]); fwrite(t, ':TRIGGER:MODE EDGE'); fwrite(t, ':TRIGGER:EDGE:SLOPE POSITIVE'); fwrite(t, ':TRIGGER:SWEEP TRIGGERED'); fwrite(t, '*CLS'); counts = 0; start_time = clock; start_time = (start_time(1, 4) * 60 * 60) + (start_time(1, 5) * 60) + (start_time(1, 6)); % % MDA: Query scope settings % fwrite(t, ':CHANNEL3:SCALE?'); % vertical_scale = fscanf(t, '%f'); % MDA: This returns volts/div % fwrite(t, ':CHANNEL3:OFFS?'); % vertical_offset = fscanf(t, '%f'); % MDA: This returns vertical offset % % % MDA: Define ADC constants % adc_resolution = 256; % MDA: 8-bit ADC % adc_offset = 128; % MDA: Midpoint for an 8-bit ADC % num_vertical_divisions = 8; % MDA: Number of vertical divisions on the screen while (counts < EventCount) fwrite(t, ':VIEW CHANNEL3'); fwrite(t, ':DIGITIZE'); fwrite(t, ':WAVEFORM:SOURCE CHANNEL3'); fwrite(t, ':WAVEFORM:FORMAT ASCII'); % MDA: ASCII - slower than WORD but already in volts, please read Proggrammer's Guide https://www.testworld.com/wp-content/uploads/keysight-agilent-infiniium-oscilloscopes-programmers-guide.pdf fwrite(t, ':WAVEFORM:BYTEORDER LSBFIRST'); fwrite(t, ':WAVEFORM:DATA?'); ch1 = fscanf(t, '%s', Points); % MDA: Read string of samples in V. E.g., V_1, V_2, V_3, ... , V_Points counts = counts + 1; Channel_1(:, counts) = str2double(strsplit(ch1, ',')'); % MDA: Split string decribed above into array and convert string to double. Units already in volts % a = fscanf(t, '%c', (length(num2str(Points * 2)) + 2)); % if isempty(a) % a = ['#', num2str(length(num2str(Points * 2))), num2str(Points * 2)]; % end % % RecordBytes = str2double(a(2)); % bufLen = str2double(a(3:RecordBytes+2)) / 2; % ch1 = fread(t, bufLen, 'int16'); % UNDERSTAND WHAT IS GOING ON HERE FOR RECORD AMPLITUDE CONVERSION TO VOLTS % % counts = counts + 1; % Channel_1(:, counts) = ch1; fwrite(t, '*CLS'); end finish_time = clock; finish_time = (finish_time(1, 4) * 60 * 60) + (finish_time(1, 5) * 60) + (finish_time(1, 6)); laps = finish_time - start_time; count_rate = counts / laps; fclose(t); clear AcqPoints ch1 defAns counts Points % MDA: Clear up workspace before saving save([DestDir,DestFile,datestr(now,' dd-mmm-yyyy, HH_MM'),'.mat']); % % MDA consider putting the below in a separate script % % mca_bins = 2^16; % MDA: Number of bins in MCA % % peak_amp = max(Channel_1); % MDA: Find the peak of each pulse % %largest_peak_amp = max(peak_amp); % MDA: This method will prevent you % %from plotting spectra from different source as they will give you a % %different maximum maximum. Better to fix this. % largest_peak_amp = 0.07; % MDA: This is in V. % % x = 0:largest_peak_amp/(mca_bins-1):largest_peak_amp; % % [occur,xout] = hist(peak_amp, x); % %plot(occur); % plot against channel number % %figure; % plot(xout,occur); % plot against volts % % %ADD THESE FEATURES % %axis labels % %save(workspace)