% Code to capture temperature data from the thermoprobe using NI PCI-6221 (37 pin) DAQ board
% For JHU Matlab 2006a (w/ DAQ toolbox)
% Programmed by Rob
% Last revision: 3/29/2007
clear all;
clc;
% Initialize the data file
[DataFileName,DataPathName] = uiputfile('.txt','Where would you like to save your data?','temperature_time_DAQ.txt');
cd(DataPathName);
Header = '%# t [s] T [oC]';
dlmwrite(DataFileName,Header,'delimiter','','-append');
% Initialize the DAQ board
AI = analoginput('nidaq','Dev1');
addchannel(AI,0);
% Start the data aquisition and plot and save it in real time
% The default 'SampleRate' is 10 kS/s and the default 'SamplesPerTrigger'is 1000
set(AI,'InputType','SingleEnded'); % DAQ board input type (bascially same as RSE input)
set(AI,'Timeout',2);
set(AI,'SampleRate',250000);
set(AI,'SamplesPerTrigger',2500);
tic; % Start the timer
for i = 1:1e6;
start(AI);
raw_data = getdata(AI);
t = round(10*toc)/10; % Register the time when data point i was captured
T = round(10*mean(raw_data)*985)/10; % Convert voltage to oC using a linear scaling
current_data_line = [i t T];
dlmwrite(DataFileName,current_data_line,'delimiter','\t','-append');
plot(t,T,'og');
xlabel('Time [s]');
ylabel('Temperature [\circC]');
hold on;
title(['Current Temperature: ',num2str(T),' [\circC]'],'FontSize',18);
drawnow;
end;