www.cs.unca.edu/~bruce/Spring06/180/Exercise6.doc

=0 cellpadding=10 cellspacing=0 width=100%>Yahoo! is not affiliated with the authors of this page or responsible for its content.






Exercise 6: LEDs and MatLab

(a modification of a lab developed by Peter Mathys
at the University of Colorado at Boulder---full credit for this exercise
goes to Peter Mathys)


Goals of this Exercise

Measure
the i-v
characteristic of a resistor and a LED.
Plot i-v characteristics
in Matlab and estimate model parameters.
Learn
how to use Ohm's law.
Learn
how to use the Shockley equation to model diodes and LEDs.

1. Introduction

Circuits are analyzed or "solved"
by deriving equations from two types of constraints:



The element constraints.
The connection constraints.

For 2-terminal devices such as independent
sources, resistors, lamps, diodes, LEDs, etc, the element constraints
are expressed in the form of an i-v characteristic. The following figure shows the i-v characteristic of a resistor with resistance R.


The black
line is the i-v characteristic of a real resistor. It typically has a linear
region, but the power rating of the device limits the range over which
the i-v characteristic is (approximately) a straight line through
the origin. The red line is the i-v characteristic of an ideal linear resistor. According to Ohm's
law


v
= R i   or   i = (1/R) v


More generally, the i-v characteristic of a linear 2-terminal element has the following properties:



It is a straight line through the origin.
It is bilateral, i.e., it has odd symmetry about the origin.

An ideal voltage source, for instance,
has an i-v characteristic that is a straight line, but it does not
pass through the origin and it is not bilateral. Thus, an ideal voltage
source is a nonlinear element. As another example, the i-v characteristic of a diode goes through the origin, but
it is neither a straight line, nor bilateral, and thus the diode is
a nonlinear element.


The two schematics below show how
to measure the i-v characteristic of a 2-terminal element E.     


The schematic
on the left uses a variable voltage source to change the voltage v across the element E, which in turn induces a change in the current i through E. The one on the right uses a variable current source to change the current i through E, which causes the voltage v across E to change. For a linear resistor either arrangement works
well to measure the i-v characteristic. For (forward biased) diodes and LEDs, where
a small change in v leads to an exponential change in i, it is much better to use the setup with the variable current
source. However, variable voltage sources are much more common in a
lab than variable current sources. To convert a variable voltage source
into a (approximate) variable current source, use a current limiting
resistor R<sub>lim in series with the voltage source as shown
in the following schematic.


The i-v
characteristic
s of an ideal and a real diode are shown in the following
graph.


Clearly
both are nonlinear 2-terminal elements. The main difference between
the ideal diode and the (idealized) real diode is that the latter has
a nonzero forward voltage drop V<sub>F. For silicon p-n junction diodes V<sub>F is approximately 0.6 to 0.7 V.


The Shockley equation for p-n junction diodes which is shown below
closely approximates the i-v characteristic of real diodes.


To
determine the parameters n and i<sub>0 from the measurement of a i-v characteristic, the following derivation is useful.


Plotting
Graphs in Matlab. Matlab (the name stands for mat</span>rix lab</span>oratory) is a program that is widely used in academia and
industry for numerical computations and simulations, especially in signal
processing, communications, and control theory. An attractive feature
of Matlab that will be used here are the many built-in graphing capabilities.


Suppose you have measured a whole
set of (v,i) pairs, e.g., the ones shown in the following table.





Volts


Milliamperes


1.26


1.261


2.48


2.482


5.61


5.616


7.23


7.237


9.55


9.560


12.04


12.05




The easiest way to visualize and
interpret this data is to make a plot of i versus v, e.g., in Matlab.


After
starting Matlab, the Matlab workspace environment (with a >>
prompt) can be used directly to type such commands as


5+3  
or   sin(pi/6)   or   exp(-1)  
etc.


 

 

Matlab is matrix and vector oriented, and most commands work directly
on matrices and vectors. To plot i versus v for several (v,i) pairs, you enter the voltage data in one vector, say v,
and the current data in a second vector, say i,
as shown in the Matlab code example below. Note the semicolon (;) at
the end of each vector. If you leave it out (try it!), Matlab prints
the vectors in the workspace immediately after you press the "Enter"
key.





Simple Plot of i-v Characteristic in Matlab



>> v = [1.26  2.48  5.61  7.23  9.55 
12.04];


>> i = [1.261 2.482 5.616 7.237
9.560 12.05];


>> plot(v,i)




To plot the data in vector i
versus the data in vector v,
simply use the command plot(v,i)
as shown in the last line of the above Matlab code. The resulting graph
is shown in the following figure.


While
this is a great initial result, several improvements can (and should)
be made. First of all, rather than working directly in the Matlab workspace
and retyping a lot of things while developing and debugging a program,
it is easier to use a Matlab script file or m-file. This is a file that contains Matlab statements and
comments (separated by %)
and is saved with a .m
filename extension. To invoke the m-file editor type edit
at the Matlab command prompt. Then enter the improved version of the i-v
characteristic
plot program as shown in the next figure and save it
as ivplot01.m (or any
other name of your choice, but with a .m
extension) in the default directory.


Note
that a header and other comments (preceded by %)
were added for clarity. But the main improvement, besides using an m-file,
is that the graph has a grid (invoked by the grid
command) and is labeled, using the xlabel
and ylabel command