DPRG List  

DPRG: biasing & reading a phototransistor

Subject: DPRG: biasing & reading a phototransistor
Date: Tue Aug 17 15:38:29 CDT 1999

To those who do not like math or get hives thinking about electronics
and computations:

	My apologies for this long boring post. If you *really* don't
	like it, then I'll refrain from any such further posts, and put
	such replies only in private e-mail to those individuals who
	specifically request them, if any should.

To all:

	I just ran this stuff off from the top of my head, and I do not
	guarantee that everything is done absolutely correctly. I have
	checked it reasonably well, but I might have made a mistake
	along the way somewhere.

	I am not an electronics expert. My degree and graduate work are
	in mathematics, not electronics (math, and mathematical
	probability and statistics, respectively) I work as a system
	architect with strength in software, not hardware. I have done
	some hardware design, but it is not my forte.

	Check my work by constructing some circuits and checking that
	they actually behave as predicted. If not, then I'll go back and
	check the math again.

)Thanks to all for your replies.  I'm learning a lot.  Mike, thanks for
)the detailed explanation, and for taking the time to recover it after
)your network error.  

What I did was cut from the screen, and do a 

	cat > recover.dat

and then paste :)

No big deal.

Glad to help.

)MIKE MCCARTY -- 93789 wrote:
)> With 10K you should have
)>         Dark: 5V - (100nA x 10K) = 4.999V
)>         Light: 5V - (50uA x 10K) = 4.5V
)What I get with a 10K across the output:
)  Supply voltage = 4.98V
)  Dark voltage across phototransistor = 4.92V (dark room or black card
)                                               over sensor)
)  Light voltage = ~3.5V (Al foil 0.15" from sensor)

1.5 V is *plenty* unless you have a very noisy environment.

)> Just from the graph, I'd say 10K is an *upper* limit on the load
)> resistor. Even then you are going to notice slow transitions. The
)> load resistance and collector capacitance form a low pass filter, which
)> slows down the transitions. At 10K you are going to have 150us rise and
)> fall times. That's pretty slow, and will need a comparator with
)> hysteresis. As noted above, with 10K you are going to get 1/2 V of
)> signal swing. A comparator set to 4.75 V with hysteresis of +/-0.1V might
)> do well (limits of 4.65V and 4.85V). It's a start, anyway.
)Now I just have to learn how to use a comparator... :^)  Excuse my
)naivete, but can I do this with the 339 quad comparator I've got in 
)front of me?  It says its differential input range is equal to the 
)supply voltage, but I don't see how to set up hysteresis with it.
Well, the second easiest way is to get an application note and read it

The easiest way is to ask someone who knows :)

The hardest way is to learn how comparators work by doing the math! :)

(I happen to like the Socratic method, so I prefer to ask questions
rather than answer them, hopefully questions which the student can
answer :)

Ok, let's think about how to make this work. We want a comparator which
has *two* threshholds, a lower and an upper. We have one which can
reliably switch at any given set threshhold, but it only has one. How
do we split it? Well, we can simply have two threshhold values, and
switch between them, based on what the current output is. How do we do
that? Well, we can use a "soft" threshhold, and feed a little of the
output back with the proper polarity and "adjust" the threshhold with

So here is a sample circuit. I don't recall the design equations, though
I could derive them without much trouble, just don't have the time right

Anyway, here goes (pardon the terrible art). The pullup is because IIRC
the 339 has open collector (OC) outputs.

                        |\     \ Rpullup
                        | \    /
        Vin o-----------|- \   \
                        |   \  |
                        |   /--+-+--------+-----o Vout
       Vref o-/\/\--+---|+ /     |        |
                    |   | /      |        \
              R1    |   |/       |        / Rload
                    |            |        \
                    +--/\/\/-----+        |
                    |                     |
                    |   R3              -----
                    /                    ---
                    \                     -
                    / R2

As you can see, the comparator has an input which is fed both from the
reference voltage, and from the output, so the output can affect the
actual threshhold the compartor sees. The output makes an adjustment to
the reference. Usually R3 >> R1, so that the actual reference point is
much more influenced by Vref than by the output. Also, we need Rpullup
<< R3, and Rpullup << Rload or the current draw will affect Voh.

Ok, I'm a fool. I'll figure out the design equations.

Lesse... The actual voltage at the reference point is V', say. Then we

	Ir1 = (Vref - V')/R1
	Ir3 = (Vout - V')/R3

	V' = (Ir1 + IR3)x R2

>from this we get

	V' = [(Vref - V')/R1 + (Vout - V')/R3]xR2


	V'(1 + R2/R1 + R2/R3) = VrefxR2/R1 + VoutxR2/R3

             VrefxR2/R1 + VoutxR2/R3
	V' = -----------------------
               1 + R2/R1 + R2/R3


             Vref/R1 + Vout/R3    R3xVref + R1xVout
	V' = ------------------ = ------------------
             1/R2 + 1/R1 + 1/R3   R1xR3/R2 + R1 + R3

Vout is either Voh or Vol (typically +5 and 0, but I'll do the general
case). That makes the threshhold voltages

                Vref/R1 + Vol/R3
	Vthl = ------------------
               1/R1 + 1/R2 + 1/R3

                Vref/R1 + Voh/R3
	Vthh = ------------------
               1/R1 + 1/R2 + 1/R3

The center point is
                        Vref/2R1 + (Voh+Vol)/2R3
	(Vthh+Vthl)/2 = ------------------------
                           1/R1 + 1/R2 + 1/R3

The total hysteresis is 
                         (Voh-Vol)/R3        (Voh-Vol)R1xR2
	(Vthh-Vthl) = ------------------ = ------------------
                      1/R1 + 1/R2 + 1/R3   R1R2 + R1R3 + R2R3

An easy way to derive Vref is simply to connect it to Vcc. I'll plug in
Vref = Voh = Vcc, and Vol = 0. Note that assuming Voh = Vcc means that
Rpullup must be much smaller than Rload and R3, so that they do not
appreciably affect Voh.

                     Vcc/R1              VccR2R3
	Vthl = ------------------ = ------------------
               1/R1 + 1/R2 + 1/R3   R1R2 + R1R3 + R2R3

                Vcc(1/R1 + 1/R3)      VccR2(R1 + R3)
	Vthh = ------------------ = ------------------
               1/R1 + 1/R2 + 1/R3   R1R2 + R1R3 + R2R3

The total hysteresis is then
	Vthh-Vthl = Hyst = ------------------
                           R1R2 + R1R3 + R2R3

One way to solve this is to divide Hyst by Vthl

	Hyst   R1
	---- = --
	Vthl   R3

Now that we have these values, we substitute into the equation for Vthl,
and solve for R2

	VccR2R3 = Vthl(R1R2 + R1R3 + R2R3)

	R2(VccR3 - VthlR1 - VthlR3) = VthlR1R3

                   VthlR1R3                VthlR1
	R2 = -------------------- = ---------------------
             VccR3 - Vthl(R1 + R3)  Vcc - Vthl(R1/R3 + 1)

                     VthlR1                   VthlR1           VthlR1
	R2 = ------------------------- = ----------------- = ----------
             Vcc - Vthl(Hyst/Vthl + 1)   Vcc - Hyst - Vthl   Vcc - Vthh

To compute the values of the resistors, then, pick Rpullup << Rload.
Then pick R3 = some convenient value with R3 >> Rpullup. Then

	R1 = ---- R3

	R2 = ----------
             Vcc - Vthh

I'd go for a total hysteresis about 1/2 of the total voltage difference
available, just for a starter.

[Now that I have these equations, I think I'll put them in a folder
somewhere so I can look for them for about 2x as long as it took to
derive them before giving up and doing it all over again :)]

Let's pick some figures out of the air for an example. Let's assume

	Vcc = 5V
	Rload = 100K
	Vthh = 4.6V
	Vthl = 3.9V

We'll chose Rpu << 100K, say Rpu = 1K. (Rpu could be up to about 5K or
so, even possibly 10K. I'd watch how small it is if you have power
limitations. But since you're burning 40mA in the diode, I'm not going
to worry about 5ma in Rpu. If it's an issue, just try a few different
Rpu and see what it does to your threshhold voltages. Larger Rpu will
cause the lower upper threshhold voltage to move *down*.) We'll chose
R3 >> Rpu, R3 = 1M.


	Hyst = Vthh-Vthl = 4.6-3.9 = 0.7V

	R1 = (0.7V/3.9V)x1M = 179.5K

	R2 = (3.9Vx179.5K)/(5V-4.6V) = 1.75M

Let's make R1 = 180K, and R2 = 1.8M as nearest standard
values. Let's recompute the actual threshhold voltages

	Vthl = 5V(1.8M)(1M)/[(180K)(1.8M)+(180K)(1M)+(1.8M)(1M)] = 3.91V

	Vthh = 5V(1.8M)(180K+1M)/[(180K)(1.8M)+(180K)(1M)+(1.8M)(1M)] = 4.61V

HEY! Just by coincidence, these values match with your observed

	Vlight = 3.5V
	Vdark  = 4.92V

These might be just a little tight, just a little too much hysteresis.
Lets see what it looks like using 1/3 of the total (1/3 headroom above,
1/3 for the hysteresis, and 1/3 for floorspace)

	Vcc = 5V
	Rload = 100K
	Vthl = 3.97V
	Vthh = 4.45V

This gives us

	Hyst = 0.48

	R1 = (0.48/3.97)x1M = 121K

	R2 = (3.97)(121K)/(5-4.45) = 873K

Nearest standard values are

	R1 = 120K

	R2 = 820K

Plugging back in

	Vthl = 3.95V

	Vthh = 4.42V

This probably would work a bit better, more cleanly. The earlier design
might miss some transitions. Try both, see how they work, and let me
know. I'd like to know whether I made a mistake :)

Anyway, I'd connect up an LM339 with the resistors mentioned above, a
pot across Vcc (say 1K pot in series with 5K resistor or so, pot
connected to Vcc, 5K to ground) to provide test voltages, and see what
the actual threshhold voltages come out to be, and fiddle just a bit.
You can omit the load resistor, if you want :)

If the threshhold values are reasonably close (and unless I made a
mistake in the algebra, they should be), then I'd connect up the
detector, and see what kind of results I get.

The output should be suitable for driving Rload up to approximately 50K
or maybe a little less, but I wouldn't load it too much. OTOH, a CMOS
input, like to a PIC, ought to be no problem. The switching time should
be 200ns or so, and you ought to get quite solid 0V and 5V outputs.

)> How many stripes do you have? How many RPS do you anticipate? Suppose
)> your max. speed is equivalent to 5 RPS, and you have 20 stripes. That's
)> 100 stripes per second, or 10mS per stripe. 150us rise and fall times
)> adds up to 1/3 of a ms. Not too bad, but not too good, either. Ok for
)> speed sensing, not good enough for position sensing. You'd have to move
)> quickly, then slow way down for positioning as you neared your goal.
)I have two discs I'm playing with, one with 36 stripes and one with 90.
)I anticipate about 1RPS max.  I'm just looking for speed sensing right
)now.  I'll have to move to something better than a BS-II for position
)sensing (probably a Scenix with SX-Key & C2C).

So that's 36 or 90 pulses per second. My guesstimate wasn't off *too*
far at 100 per second, was it?


)> Here's what I recommend:
)> Put in a 10K load resistor on the collector, and remove the emitter
)> resistor.
)Done.  Never had an emitter resistor.

I thought you said you had a 250 ohm emitter resitor. Oh, well, must be
getting old or something.

)> Put a 91 ohm resistor on the diode.
)Didn't have one, so faked it with 150 ohms in parallel with 220.

Sounds ok, that's 89 ohms. You *did* check the current to be <= 40mA
didn't you? Don't want to damage the diode.

)> Stop all current to the diode. See what your leakage current is.
)Looks like about 1.9 microA.

That's not terrible, but not great. I'd say it's certainly acceptable.

)> Then turn off all lights in the room and see what it is.
)0.2 microA.

Yep, you got light leakage, but not too badly.

)> Now reapply current to the diode and see what happens. (Make sure
)> you've got close to 40mA in the diode. Do this still in the dark. I'd
)> start with a 200 ohm resistor on the diode, and gradually reduce it
)> towards 91 ohms.)
)5.0 microA.

Well, here's your problem. Insufficient illumination or albedo.

)With Al foil in front of sensor, it's very variable with distance; 
)best number is about 150 microA at about 0.15".

And this really nails it. Insufficient albedo. Your reflectance is too

Paper is notoriously transparent to IR.

)With my disk (printed on an ink jet printer, backed with white card
)stock) in front of sensor, the best I get is something like 25 microA.
)You're right, I guess my discs are pretty bad.  I'll try a more 
)reflective paper, & printing on a laser printer instead of an ink jet 
)for a better black.

Maybe better, maybe not. Germanium (yes, the semiconductor) is
*transparent* to IR. Wouldn't guess it from looking at it. It looks
just like lead. So is iodine, and it's so black it's hard to tell it's
actually purple :)

)Other than that, do the numbers above sound reasonable based on the
)device specs?

Yes, they do.

I hope I included enough example math for you to figure out any further
experiments you might want to try.


More information about the DPRG mailing list