Characterize an LED with ADALM1000

This example shows how to use MATLAB to connect to an Analog Devices ADALM1000 source-measurement unit, configure it, and make current and voltage measurements to characterize an LED.

Discover Supported Data Acquisition Devices Connected to Your System

daq.getDevices
ans = 
adi: Analog Devices Inc. ADALM1000 (Device ID: 'SMU1')
   Analog input subsystem supports:
      0 to +5.0 Volts,-0.20 to +0.20 A ranges
      Rates from 100000.0 to 100000.0 scans/sec
      2 channels ('A','B')
      'Voltage','Current' measurement types
   
   Analog output subsystem supports:
      0 to +5.0 Volts,-0.20 to +0.20 A ranges
      Rates from 100000.0 to 100000.0 scans/sec
      2 channels ('A','B')
      'Voltage','Current' measurement types
   

Properties, Methods, Events


Create a Session Using the ADALM1000 Device

ADISession = daq.createSession('adi')
ADISession = 
Data acquisition session using Analog Devices Inc. hardware:
   Will run for 1 second (100000 scans) at 100000 scans/second.
   No channels have been added.
   
Properties, Methods, Events

Add Channels for Sourcing Voltage and Measuring Current

The ADALM1000 device is capable of sourcing voltage and measuring current drawn on a specified channel. Set up the device in this mode.

Add an analog output channel with device ID SMU1 and channel ID A, and set its measurement type to voltage.

addAnalogOutputChannel(ADISession,'smu1','a','Voltage');

Add an analog input channel with device ID SMU1 and channel ID A, and set its measurement type to current.

addAnalogInputChannel(ADISession,'smu1','a','Current');

Confirm the configuration of the session.

ADISession
ADISession = 
Data acquisition session using Analog Devices Inc. hardware:
   No data queued.  Will run at 100000 scans/second.
   Number of channels: 2
      index Type Device Channel   MeasurementType        Range       Name
      ----- ---- ------ ------- ------------------- ---------------- ----
      1     ao   SMU1   A       Voltage (SingleEnd) 0 to +5.0 Volts
      2     ai   SMU1   A       Current             -0.20 to +0.20 A
   
Properties, Methods, Events

Blink Attached LED Five Times

Connect an LED in series with a 330 Ω resistor between the ADALM1000 channel A and ground.

for iLoop = 1:5
    % Turn on LED by generating an output of 5 volts.
    outputSingleScan(ADISession,5);
    pause(0.2);
    % Turn off LED by generating an output of 0 volts.
    outputSingleScan(ADISession,0);
    pause(0.2);
end

Characterize the LED

To understand the LED's I-V characteristics, sweep a range of voltage values from 0 V to 5 V, and measure the current for each value. The aggregate of all measurements provides data to graph the current across the LED over a range of voltages.

v = linspace(0,5,250);

for iLoop=1:length(v)
    outputSingleScan(ADISession,v(iLoop));
    i(iLoop) = inputSingleScan(ADISession);
end

Plot the Characteristic Curve of the LED and Estimate a Mathematical Model

When you have the measured data, you can visualize it. You can also calculate a mathematical model that approximates the behavior of the LED within the range of the measurements.

% Plot the measured data.
plot(v,i,'LineWidth', 2);
hold on;
grid on;
ylabel('I (amperes)');
xlabel('V (volts)');
title({'I-V Characteristic Curve of LED';'and fifth-order polynomial approximation.'});

Fit the data using a fifth-order polynomial and overlay the acquired data with the model of the LED approximated by a fifth-order polynomial.

approxPoly = polyfit(v,i,5);

Plot the approximated data.

plot(v,polyval(approxPoly,v),'-k','Linewidth',1);

Calculate the Voltage at Which the LED Turns On

Based on the fifth-order polynomial approximation, you can find a first- order approximation that represents the linearly increasing portion of the curve. The voltage at which the LED turns on is approximately where this line intersects the voltage axis.

Find the line that passes through the linear portion of the signal.

normErr = -1;
errThreshold = 0.001;
numPointsForLine = numel(v) - 10;
while (numPointsForLine > 0) && (normErr < errThreshold)
    approximation = polyval(approxPoly,v(numPointsForLine:end));
    [linearPoly, errorStruct] = polyfit(v(numPointsForLine:end),approximation, 1);
    numPointsForLine = numPointsForLine - 5;
    normErr = errorStruct.normr;
end

Evaluate the linear polynomial over the range of measurements. The value where this intersects the horizontal line representing any leakage current is the voltage at which the LED turns on.

LEDThreshold = 1.2;
leakageCurrent = mean(i(v<LEDThreshold));
linearIV = polyval(linearPoly,v);
minIndex = sum(linearIV<leakageCurrent);

Plot the linear portion of the curve.

plot(v(minIndex-1:end),polyval(linearPoly,v(minIndex-1:end)),'Magenta','Linewidth',2,'LineStyle','--')

Circle the approximate voltage at which the LED turns on.

plot(v(minIndex),leakageCurrent,'o','Linewidth',2,'MarkerSize',20,'MarkerEdgeColor','Red')
title(sprintf('Calculated Voltage at Which LED Turns On: %1.2fV',v(minIndex)));

Turn Off the LED and Clear the Session

outputSingleScan(ADISession,0);
close
clear ADISession