Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

IO Test with National Instruments® PCI-6289 Board

This example shows how to do an analog and digital IO loopback test using the National Instruments® PCI-6289 (M-series) board.

Open, Build, and Download the Model to TargetPC1

Click here to open the model: xpcNIPCI6289.

% Open the model.
mdl = 'xpcNIPCI6289';
mdlOpen = 0;
systems = find_system('type', 'block_diagram');
if isempty(strmatch(mdl, systems, 'exact'))
  mdlOpen = 1;
  open_system(mdl);
end

% Build the model and download to the target computer, TargetPC1.
set_param(mdl,'RTWVerbose','off'); % Configure for a non-Verbose build.
rtwbuild(mdl);                     % Build and download application.
### Starting Simulink Real-Time build procedure for model: xpcNIPCI6289
Warning: This model contains blocks that do not handle sample time
changes at runtime. To avoid incorrect results, only change
the sample time in the original model, then rebuild the model. 
### Successful completion of build procedure for model: xpcNIPCI6289
### Looking for target: TargetPC2
### Download model onto target: TargetPC2

Run the Model

Using the Simulink® Real-Time™ object variable tg, start the model. Wait until the model has stopped running before proceeding.

tg.stoptime=1; % Set model stoptime to 1 sec.
+tg;           % Start the model.

% Wait until the run is complete.
while strcmp(tg.Status, 'running')
  pause(0.5);
end

Display the Analog Subsystem Test Results

For this model, 4 Analog Output and 4 Analog Input channels are exercised. Signals are written to the output channels, looped back to the input channels, and compared to verify IO integrity.

% Open the analog IO subsystem.
open_system([mdl,'/PCI-6289 (M Series)/Analog IO Subsystem']);

% Plot results.
figure(101); clf;
subplot(2,2,1)
h=plot(tg.TimeLog,tg.OutputLog(:,1),'g',tg.TimeLog,tg.OutputLog(:,5),'b',tg.TimeLog,tg.OutputLog(:,9),'r');
axis([0 0.2 -1.2 1.2]); set(h,'LineWidth',1);
grid on;
title('National Instruments PCI-6289','FontSize',11)
ylabel('Sine')
legend('D/A','A/D','Error')
subplot(2,2,2)
h=plot(tg.TimeLog,tg.OutputLog(:,2),'g',tg.TimeLog,tg.OutputLog(:,6),'b',tg.TimeLog,tg.OutputLog(:,10),'r');
axis([0 0.2 -1.2 1.2]); set(h,'LineWidth',1);
grid on;
title(['Analog I/O Test (Fs = ' num2str(1/tg.SampleTime/1000) 'KHz)'],'FontSize',11)
ylabel('Square')
subplot(2,2,3)
h=plot(tg.TimeLog,tg.OutputLog(:,3),'g',tg.TimeLog,tg.OutputLog(:,7),'b',tg.TimeLog,tg.OutputLog(:,11),'r');
axis([0 0.2 -1.2 1.2]); set(h,'LineWidth',1);
grid on;
ylabel('Sawtooth')
xlabel('Time (sec)')
subplot(2,2,4)
h=plot(tg.TimeLog,tg.OutputLog(:,4),'g',tg.TimeLog,tg.OutputLog(:,8),'b',tg.TimeLog,tg.OutputLog(:,12),'r');
axis([0 0.2 -1.2 1.2]); set(h,'LineWidth',1);
grid on;
ylabel('Chirp')
xlabel('Time (sec)')

Display the Digital Subsystem Test Results

For this model, 2 Digital Output and 2 Digital Input channels are exercised. Random pulses are written to the output channels, looped back to the input channels, and compared to verify IO integrity.

% Open the digital IO subsystem.
open_system([mdl,'/PCI-6289 (M Series)/Digital IO Subsystem']);

% Plot results.
figure(102); clf;
subplot(3,1,1)
h=plot(tg.TimeLog,tg.OutputLog(:,13),'g',tg.TimeLog,tg.OutputLog(:,15),'b',tg.TimeLog,tg.OutputLog(:,17),'r');
axis([0 0.2 -0.2 1.2]); set(h,'LineWidth',1);
title(['National Instruments PCI-6289 Digital I/O Test (Fs = ' num2str(1/tg.SampleTime/1000) 'KHz)'],'FontSize',11)
ylabel([' Random '; 'Pulse #1'])
legend('DOut','DIn','Error')
subplot(3,1,2)
h=plot(tg.TimeLog,tg.OutputLog(:,14),'g',tg.TimeLog,tg.OutputLog(:,16),'b',tg.TimeLog,tg.OutputLog(:,18),'r');
axis([0 0.2 -0.2 1.2]); set(h,'LineWidth',1);
ylabel([' Random '; 'Pulse #2'])
subplot(3,1,3)
h=plot(tg.TimeLog,tg.OutputLog(:,19),'r');
axis([0 0.2 -0.2 1.2]); set(h,'LineWidth',1); grid on
ylabel(['Comparator'; '0=Err,1=OK'])
xlabel('Time (sec)')

% Close the model if we opened it.
if (mdlOpen)
  bdclose(mdl);
end

% EOF xpcNIPCI6289Demo.m
Was this topic helpful?