The Lab Volt Process Control trainer model (3521) was purchased by the School of Engineering & Physics, University of the South Pacific for use in control engineering courses. The model came with a customised data acquisition device and proprietary software for control. One of its disadvantages was the lack of an interface with Matlab for labs and projects that required design using root locus and the implementation of difference equations. To overcome this problem, a National Instruments USB DAQ card was interfaced with the model and connected to a PC running Matlab. Fig. 1 below shows the complete system setup. Fig. 2 illustrates the DAQ card and connections. Fig. 3 shows step response data collected and displayed on a computer screen using Matlab.
Fig. 1 System set up for Matlab control
Fig. 2 National Instruments USB DAQ card
Fig. 3 Step response data plotted "on the fly" in Matlab
Matlab Code
% This m-file is designed for use with the lab-volt process control trainer
% model. A National Instruments NI DAQPad-6015 is used for data acquistion.
% Feedback temperature is input via analog input 0 (AI 0) while the
% controller output is sent via analog output 0 (AO 0).
% The difference equation of a digital controller can be programmed by the user.
% Sample Time T, execution time TEX, and reference input refInputP
% can be set by the user.
% Feedback temperature and controller output are output to the matlab workspace
% and also plotted in graphs.
% © Praneel Chand 05/04/2010
clear all
clc
% specify sample time in sec
T = 2; %two seconds
% specify execution time in minutes
TEX = 20; %twenty minutes
% specify reference input per unit value
refInputP = 0.8;
% DO NOT EDIT BELOW THIS LINE----------------------------------------
% convert reference input PU value to voltage
inputRange = 5;
minInput = 0;
refInput = minInput + refInputP*inputRange;
% create data acquisition device objects.
tempInputObj = analoginput('nidaq','Dev1');
addchannel(tempInputObj,0); % add channel 0 to analog input object
set(tempInputObj,'InputType','Differential');
set(tempInputObj,'SamplesPerTrigger',101); % read in 101 samples each time
set(tempInputObj,'TriggerType','Manual'); % manual trigger
set(tempInputObj,'TriggerRepeat',inf); % manual trigger
contOutputObj = analogoutput('nidaq','Dev1');
addchannel(contOutputObj,0); % add channel 0 to analog output object
% INITIALISE VARIABLES
% initialise loop counter
count = 1;
% loop counter limit
countMax = ceil(TEX*60/T) + 1;
% intialise temperature input data
tempData = 0;
% initialise controller output data
contData = 0;
% initialise arrays for temperature input and controller output storage
tempDataArray(1:countMax) = 0;
contDataArray(1:countMax) = 0;
% initialise error
error = 0;
error1 = 0;
% intialise timer variables
t1 = 0;
t2 = 0;
% start daq objects
start(tempInputObj)
%start(contOutputObj)
figure(1)
title('Sensed Heater Output');
xlabel('Sample Number');
ylabel('Sensed Temp. (V)');
hold on
tic
while count <= countMax
t1 = clock;
trigger(tempInputObj)
tempData = median(sort((getdata(tempInputObj))); % read 101 samples of temperature input data and compute median (acts as a filter)
% check if input data is within 0-5 V
if tempData < 0
tempData = 0;
elseif contData > 5
tempData = 5;
end;
tempDataArray(count) = tempData; % store temperature input data
plot(count,tempData,'*');
drawnow;
%DO NOT EDIT ABOVE THIS LINE-----------------------------------------
% insert your digital controller difference equation here...
error = refInput - tempData; % calculate currrent error
% continue with your difference equation programming...
contData = refInput; % e.g. open loop system, step input applied to plant directly OR
contData = (2.802*error-2.758*error1+contData); % e.g. feedback system difference equation
% DO NOT EDIT BELOW THIS LINE----------------------------------------
%contData = 2.2
% check if output data is within 0-5 V
if contData < 0
contData = 0;
elseif contData > 5
contData = 5;
end;
contDataArray(count) = contData; % store controller output data
putsample(contOutputObj,contData)% set controller output data
count = count + 1;
%t2 = clock
timep = T-(etime(clock,t1));
pause(timep); % insert pause to meet sample time requirement
end;
% set output to zero to disable heater
putsample(contOutputObj,0)% set controller output data
% stop objects
stop(tempInputObj)
stop(contOutputObj)
% delete objects
delete(tempInputObj)
clear tempInputObj
delete(contOutputObj)
clear contOutputObj
% plot output data
for i = 1:length(tempDataArray)
timeArray(i) = (i-1)*T/60;
end;
figure(2)
plot(timeArray,tempDataArray,'o:')
title('Sensed Heater Output')
xlabel('Time (min)')
ylabel('Volts (V)')
figure(3)
plot(timeArray,contDataArray,'o:')
title('Controller Output')
xlabel('Time (min)')
ylabel('Controller Output (V)')