characterize an led with adalm1000 -凯发k8网页登录
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
daqlist
ans=1×5 table
vendorid deviceid description model deviceinfo
________ ________ _______________________________ ___________ ________________________
"adi" "smu1" "analog devices inc. adalm1000" "adalm1000" [1×1 daq.adi.deviceinfo]
create a dataacquisition interface for the adalm1000 device
adidaq = daq("adi");
add channels for sourcing voltage and measuring current
the adalm1000 device is capable of sourcing voltage and measuring current simultaneously on the same 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.
addoutput(adidaq,'smu1','a','voltage');
add an analog input channel with device id smu1 and channel id a, and set its measurement type to current.
addinput(adidaq,'smu1','a','current');
confirm the configuration of the channels.
adidaq.channels
ans=1×2 object
index type device channel measurement type range name
_____ ____ ______ _______ _____________________ __________________ __________
1 "ao" "smu1" "a" "voltage (singleend)" "0 to 5.0 volts" "smu1_a"
2 "ai" "smu1" "a" "current" "-0.20 to 0.20 a" "smu1_a_1"
blink attached led five times
connect an led in series with a 330- resistor between the adalm1000 channel a and ground. alternately apply 5 v and 0 v.
for iloop = 1:5 % turn on led by generating an output of 5 volts. write(adidaq,5); pause(0.2); % turn off led by generating an output of 0 volts. write(adidaq,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)'; i = readwrite(adidaq,v,"outputformat","matrix");
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
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 dataacquisition
write(adidaq,0);
close
clear adidaq