IR phototansistors, sensitivity and RC time constant
September 12, 2010
Some time ago I had a great idea: I'm going to make two robots. One will be an obstacle avoider and its job will be just wander around with its big head. The other bot will then try to catch it and hit the head with a hammer. Tracking would be done with infrared leds and phototransistors. For the time being I've pretty much completed the first part and posted Head. Head already has infrared leds on its head so next thing would be building an infrared tracker.
I have made one "Evil Eye" prototype and it has 5 pairs of SFH 313 FA phototransistors (10 total) and I'm using a 47K resistor for each pair. Schematic is just like in OddBot's compound eye except I don't have IR leds on the same board. Here's my schematic for clarification (just 1 of 5 phototransistor pairs):
Evil eye schema
In case you are interested there are a couple more photos (and videos) in my blog post here.
Now to the business. When I was making this prototype I was aware that the value of R1 (see the schematic above) affects the sensitivity. Lower values mean lower sensitivity and higher values mean higher sensitivity. Being a beginner in this kind of stuff I first chose the safe road and went with same value Oddbot had used, 4K7. After playing with it for a while I felt like I needed more sensitivity. So I went a decade up to 47K. Oh yeah! I was getting some sensitivity. I was also aware that more sensitivity means more sensitivity to everything those phototransistors pick up, daylight being maybe the most feared bogey. I did some testing with daylight too and decided that it was not a problem. Yes, it was getting through but my IR leds were strong enough to make a difference (indoors, just blinds off windows, no direct sunlight). By the way, if you really want to mess up your IR phototransistors try a halogen lamp. I have a light with 2 halogen lamps, one 50W and one 300W. The 50W lamp messes up my phototransistors for good even when I have dimmer set so that it is barely lit.
So, I had made a compromise between sensitivity and how much noise/background IR will get though. I had also thought that some kind of modulation could be nice to improve detection accuracy. Simplest thing would be PWMing an IR led at 50% duty cycle. If the eye is getting a straight line then is background IR. If there's pulsing at some predetermined frequency then it's my IR led.
I made two little programs I'm calling Serial-O-Scope (yeah I know, how original) and USART-scope (who'd have guessed that) for testing some modulation things. Serial-O-Scope is a Processing program listening for data coming in from serial port and USART-scope is a program running in an ATMega8 sending ADC data out from USART. Serial-O-Scope then draws a nice graph of the data. ATMega8's ADC is running at about 19230SPS (samples per second) which is a bit too much for maximum resolution (10bits). I'm using only 8 bits and results seemed to be really stable to I'm guessing that's ok. I did try 9615SPS just in case and got similar results. I ran some test using different values for R1 and 555 timer PWMing an IR led at about 198Hz/53% duty cycle. I had the eye prototype already soldered but it was easy enough to add another resistor in parallel to the first one to lower R1 value. This is where I noticed that my compromise included something more than just sensitivity and noise/background IR.
It's the *** **** RC time constant! Yes, it's screwing up my Evil Eye! RC time constant doesn't really have much to do if you are going with plain IR light with no modulation. But it's a different thing when you want to do modulation. Without any more jabbering I'll just post some screenshots from Serial-O-Scope. Screenshots have R1 value and the distance between the eye and IR led just beneath them.
R1 = 47K, distance ~30cm
R1 = 47K, distance ~60cm
R1 = 47K & 47K in parallel (23K5), distance ~30cm
R1 = 47K & 47K in parallel (23K5), distance ~60cm
R1 = 47K & 4K7 in parallel (~4K3), distance ~10cm
R1 = 47K & 4K7 in parallel (~4K3), distance ~30cm
R1 = 47K & 4K7 in parallel (~4K3), distance ~60cm
How about that? Huh? You can see how sensitivity gets lower as R1 value gets lower. You can also see the weird thing I noticed then I first looked at these pictures. Why do those pictures with higher R1 value look like there's a shark gang or something swimming by? I checked the datasheet (once again) and it said rise/fall times are 8-15 microseconds depending on model. Those shark fins aren't even close to that! It was time to do some googling and our dear friend Google showed me the way to enlightenment thought this link. Here's a quote from that page: "The speed of response of a phototransistor is dominated almost totally by the capacitance of the collector-base junction and the value of the load resistance. These dominate due to the Miller Effect which multiplies the value of the RC time constant by the current gain of the phototransistor. This leads to the general rule that for devices with the same active area, the higher the gain of the photodetector, the slower will be its speed of response." (Notice parts I've bolded) I faintly remembered that RC time constant is something made of resistance and capacitance (RC, easy to remember). Quick look at Wikipedia confirmed that. What a disappointment! A lousy resistors can so totally slow down your phototransistors response time. At this point I noticed that the datasheet does have Rl = 1kΩ mentioned there but I honestly wouldn't have guessed it affects the rise/fall times.
So, if I'll go with the prototype and modulation I'll have to deal with really slow rise/fall times and that's not good. On the other hand I could probably do just fine without modulation. Mixing high and low sensitivity parts could also be a solution. For now I feel like leaving it as it is and dealing with problems later if there's any. One thing is for sure: I learned that there's a thing called RC time constant and it affects phototransistors' response time. That's a good thing isn't it? Now I know it next time I'm doing something with phototransistors. Unless I forget it first :-)
To lighten up the post I'll add those Evil Eye test video I've posted in my earlier blog post here too. Embedded ones are from Youtube and there are also Vimeo versions available here, here and here. Those videos are done with 47K R1 on every phototransistor pair and without any modulation on IR led. Only thing changing between videos is software (a tiny little bit better each time).