Main Content

Measure Resistance with an NI Switch Module and DMM

This example shows how to use an NI switch module with an NI digital multimeter to measure resistance.

A switch module consists of an array of controllable relays/switches that can be arranged and addressed to provide various connection configurations. When used with an appropriate terminal block, an NI switch module can be configured to use a certain switch topology, such as multiplexer or matrix topology with one- or multi-wire switching modes. One common application is to combine one or more measuring instruments with a switch module to perform automated measurements on a number of devices or circuit test-points. This example uses an NI switch module and digital multimeter (DMM) to measure the resistance of 5 resistive devices in two-wire resistance measurement mode.

Hardware Setup

Note: The Switch module and DMM mentioned below are configured as simulated devices in NI-MAX for the purpose of publishing this example.

  • NI 2530 switch module, used with a matrix terminal block accessory, and configured in NI MAX to use a 2-wire 4x16 matrix topology.

  • NI 4065 digital multimeter (DMM) connected to switch matrix row 'r0'.

  • Five resistors connected to switch matrix columns 'c0' to 'c4'.

Requirements

To run this example the following hardware support packages need to be installed:

Initialize Connection to NI Switch Module

To connect to the switch module, use the pre-built MATLAB® instrument driver 'niswitch.mdd' as installed with the NI-SWITCH support package, and as the resource name use the device name from NI MAX (such as 'PXI1Slot3'). MATLAB will use the NI-SWITCH driver to communicate with the instrument. By defaut, NI switch modules use the topology configuration specified in NI MAX (vendor-provided utility).

mySwitch = icdevice('niswitch.mdd', 'PXI1Slot3');
connect(mySwitch);

Initialize Connection to NI Digital Multimeter

To connect to the DMM instrument, use the pre-built MATLAB instrument driver 'nidmm.mdd' as installed with the NI-DMM support package. For the resource name, use the device name from NI MAX (such as 'Dev1'). MATLAB will use the NI-DMM driver to communicate with the instrument.

myDMM = icdevice('nidmm.mdd', 'Dev1');
connect(myDMM);

Define Constants used by the Driver Functions

NI-Switch and NI-DMM drivers use predefined constants as function arguments for configuring specific settings and operations. Their values are listed in the corresponding driver help files. These constants are defined in C header files included with the NI-SWITCH and NI-DMM drivers:

  • 'niswitch.h' and 'IviSwtch.h' in 'C:\Program Files\IVI Foundation\IVI\Include'

  • 'nidmm.h' and 'IviDmm.h' in 'C:\Program Files\IVI Foundation\IVI\Include'

const.NISWITCH_VAL_BREAK_BEFORE_MAKE = 1;
const.NISWITCH_VAL_SOFTWARE_TRIG = 3;
const.NISWITCH_VAL_NONE = 0;
const.NIDMM_VAL_2_WIRE_RES = 5;
const.NIDMM_VAL_SOFTWARE_TRIG = 3;
const.NIDMM_VAL_AUTO_RANGE_ON = -1;
const.NIDMM_VAL_TIME_LIMIT_AUTO = -1;

Reset Switch

Reset switch to default connection state.

invoke(mySwitch.Utility, 'Reset');

Configure Digital Multimeter

Configure DMM measurement type to be a two-wire resistance measurement. Configure DMM to perform an auto-range operation before each measurement, and specify the measurement resolution.

invoke(myDMM.ConfigurationMeasurementOptions, 'ConfigurePowerLineFrequency', 60);
MeasurementFunction = const.NIDMM_VAL_2_WIRE_RES;
Range = const.NIDMM_VAL_AUTO_RANGE_ON;
ResolutionDigits = 5.5;
invoke(myDMM.Configuration, 'ConfigureMeasurementDigits', MeasurementFunction, Range, ResolutionDigits);

Make a Switch Connection and Perform a Single Resistance Measurement

Connect a path between a device under test (DUT) at switch matrix column 'c0' and measuring instrument, in this case a DMM at row 'r0'.

invoke(mySwitch.Route, 'Connect', 'r0', 'c0');
MaximumTimeMs = 5000;
invoke(mySwitch.Route, 'WaitForDebounce', MaximumTimeMs);

After switch has settled, proceed with measurement.

MaximumTime = const.NIDMM_VAL_TIME_LIMIT_AUTO;
reading = invoke(myDMM.Acquisition, 'Read', MaximumTime);

% Check if DMM reading was over-range
IsOverRange = invoke(myDMM.Acquisition, 'IsOverRange', reading);
disp(reading);
disp(IsOverRange);
   5.0002e+07

     0

Disconnect the path between terminals 'r0' and 'c0'.

invoke(mySwitch.Route, 'disconnect', 'r0', 'c0');

Software-Controlled Switch Scanning Operation

A switch module can be configured to switch between different connection paths by scanning, i.e. sequentially switching and advancing through a list of connections as defined in a scan list. The connection switching during scanning can be synchronized with a measuring instrument by hardware-triggering (hardware-timed handshaking), or can be software-timed by a software trigger command.

To configure a scanning operation, specify a list of connections as a scan list string. Here, the switch will cycle through connections between the measuring instrument (DMM) at matrix row 'r0' and devices under test at matrix columns 'c0' to 'c4'. For details on the scan list syntax refer to the NI-SWITCH driver documentation.

NrConnections = 5;
scanList = 'c0:4->r0;';
scanMode = const.NISWITCH_VAL_BREAK_BEFORE_MAKE;
invoke(mySwitch.Scan, 'configureScanList', scanList, scanMode);

% Set scan trigger input to software -- switching to the next connection in
% the scan list will be done as a result of a SendSoftwareTrigger command.
scanDelay = 0;
triggerInput = const.NISWITCH_VAL_SOFTWARE_TRIG;
scanAdvancedOutput = const.NISWITCH_VAL_NONE;
invoke(mySwitch.Scan, 'ConfigureScanTrigger', scanDelay, triggerInput, scanAdvancedOutput);

% Configure switch to cycle only once through the scan list by disabling
% the continuous scan mode.
invoke(mySwitch.Scan, 'SetContinuousScan', 0);

Initiate switch scan operation using software triggering.

invoke(mySwitch.Scan, 'InitiateScan');

for ii=1:NrConnections
    % Perform DMM measurement
    readings(ii) = invoke(myDMM.Acquisition, 'Read', const.NIDMM_VAL_TIME_LIMIT_AUTO);
    % Check if DMM reading is over-range
    IsOverRange = invoke(myDMM.Acquisition, 'IsOverRange', readings(ii));
    if IsOverRange
        fprintf('Measurement %d is over range.\n', ii);
    end
    % Send trigger command to switch to advance to next connection
    invoke(mySwitch.Scan, 'SendSoftwareTrigger');
end

Display measurement results.

figure;
bar(readings);
ylabel('Resistance (ohm)');
xlabel('Device #');
set(gca, 'XTick', [1:NrConnections]);

Disconnect from Switch Module and DMM Instrument

disconnect(mySwitch);
delete(mySwitch);

disconnect(myDMM);
delete(myDMM);