0

Best way to Integrate a signal from a photodiode?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Best way to Integrate a signal from a photodiode?

by iandol on Mon Nov 22, 2010 1:38 pm

Hello all,

I have a project where I'm using a TAOS TSL251R[1] pointing at a CRT, and I want a TTL out when the area under the photodiode is "white", and turn off when it is "black". Now the issue is that CRT phosphers decay in light intensity quickly, so the output looks like the following (imagine it smoothed with a gaussian, a 100Hz refresh means the time between the light pulse peaks is 10ms):

Code: Select all | TOGGLE FULL SIZE
                       -----      -----      -----     
 -----      -----      |    |     |    |     |    |     -----       -----
 |    |     |    |     |    |-----|    |-----|    |-----|    |      |    |
-|    |-----|    |-----|                                     |------|    |
>BLACK                 >WHITE                           >BLACK


I'm using an arduino to power my photodiode, and do the necessary logic (currently it is LOW when black, and pulses a TTL for every frame when the CRT is white, not quite what I want). However I wondered whether there was a smart way to use some capacitors to smooth the signal so the digital out stays HIGH for the duration that the CRT is "white". I imagine the problem with that is when the CRT turns black again, the capacitor signal will take time to dissipate and thus wrongly signal the white>black transition time.

Any other smarter ways to handle this? Thanks for any help in advance!

Ian

----
[1] http://www.taosinc.com/ProductDetails.aspx?id=61

iandol
 
Posts: 2
Joined: Mon Nov 22, 2010 1:13 pm

Re: Best way to Integrate a signal from a photodiode?

by tinsmith on Mon Nov 22, 2010 2:09 pm

Numerically, what are the voltage levels involved? It looks like you could just threshold it such that below X is off for both conditions, above X but below Y is black-on, above Y is white-on.
tinsmith
 
Posts: 62
Joined: Thu Nov 18, 2010 9:18 pm

Re: Best way to Integrate a signal from a photodiode?

by stinkbutt on Mon Nov 22, 2010 2:21 pm

If you want to integrate a varying signal, you can use an op-amp integrator:

Image

The only catch is I can't tell where 0V is. If the offset of your signal is consistently positive, or negative, then the integrator will just end up running it's output into the rail. (Going higher than the supply voltage and clipping the output.) Now, if the integral of your input is not = 0 (or at least constant) over the long term, then your op-amp will eventually run into the rail.

There are two solutions to this.

First, you can manually account for the voltage by biasing the positive input of the integrator.

Second, you could introduce a decay into the circuit instead:

Image

Now, you'll need to adjust the size of the decay resistor to ensure that it doesn't die out too fast or too slow, so that it reaches a steady state when the PWM you're reading is "mostly high" and a different steady state when it's "mostly low." You'll need to dicker around with all three of the component values, in fact, depending on how fast that PWM you were showing off changes. Basically just keep in mind that the increasing C and R1 slows down the rate at which the integral accumulates over time, and increasing R2 slows down the rate at which the integral "decays."

Or you could just do it in the code. But to do that you'll need to know what those 3 or 4 voltage values are and it gets complicated when the signal is "smoothed with a gaussian." I'm not sure what that even means.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: Best way to Integrate a signal from a photodiode?

by stinkbutt on Mon Nov 22, 2010 2:46 pm

If you're going to do it in the code you could just code some manual hysteresis into your decoding. Say, your signal's varying from 0V to 5V with the levels like this:

Code: Select all | TOGGLE FULL SIZE
5V                         -----      -----      -----     
4V   -----      -----      |    |     |    |     |    |     -----       -----
1V   |    |     |    |     |    |-----|    |-----|    |-----|    |      |    |
0V  -|    |-----|    |-----|                                     |------|    |
    >BLACK                 >WHITE                           >BLACK


Then you'd just code the Arduino to keep the "high" and "low" flags set until the signal goes above 4.5V or below 0.5V. That assumes, of course, you can find some voltage that the "BLACK" signal will never rise above, and some voltage the "WHITE" signal will never drop below.

Also keep in mind I just made up those voltages. I don't know what your levels really are.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: Best way to Integrate a signal from a photodiode?

by adafruit_support_bill on Mon Nov 22, 2010 3:01 pm

In software, look for the rising edges and measure the peaks. You can ignore the rest.

adafruit_support_bill
 
Posts: 76070
Joined: Sat Feb 07, 2009 10:11 am

Re: Best way to Integrate a signal from a photodiode?

by stinkbutt on Mon Nov 22, 2010 4:21 pm

arduwino wrote:In software, look for the rising edges and measure the peaks. You can ignore the rest.


I'm not sure if that'd work, primarily because he seemed to indicate that it wasn't a true square wave:

iandol wrote:so the output looks like the following (imagine it smoothed with a gaussian, a 100Hz refresh means the time between the light pulse peaks is 10ms):


Though, I've no earthly idea what a square wave "smoothed with a gaussian" looks like. A sine wave perhaps? That's why I figured if you're going to use software just implement a big hysteresis "dead zone" that doesn't do anything, and look for the big peaks and deep valleys.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Re: Best way to Integrate a signal from a photodiode?

by adafruit_support_bill on Mon Nov 22, 2010 5:06 pm

I'm not sure if that'd work, primarily because he seemed to indicate that it wasn't a true square wave:

You can still distinguish an upward slope from a downward slope. But given the regular 10 ms period, a simpler way might be to just take the highest reading in any 10 ms window as your peak.

adafruit_support_bill
 
Posts: 76070
Joined: Sat Feb 07, 2009 10:11 am

Re: Best way to Integrate a signal from a photodiode?

by iandol on Mon Nov 22, 2010 5:41 pm

Dear all, wow what a helpful bunch you are! :)

signal.png
signal.png (9.62 KiB) Viewed 2618 times


Here is the actual signal, and I realise I've made a few adjustments (using ND filters and such). Currently my OFF for both black and white is the same and somewhat offset from 0V. The upper trace is the current digital trigger from the arduino, the lower trace is the raw voltage signal from the TSL251R.

And a gaussian filter looks like a camel hump, so a square wave passed through a gaussian indeed looks like a rectified sinewave: http://en.wikipedia.org/wiki/Gaussian_filter

Now, I think indeed this is better done in software, and I suspect I should work out how to time 10ms in arduino-speak and only check my analog line after an internal delay for the next peak. I'm a bit worried that slop in the arduino timing code will potentially make me miss this narrow peak; any ideas on making this robust?

Thanks again all! :beer:

iandol
 
Posts: 2
Joined: Mon Nov 22, 2010 1:13 pm

Re: Best way to Integrate a signal from a photodiode?

by adafruit_support_bill on Mon Nov 22, 2010 5:55 pm

It looks like you will need to sample at least every ms to catch those peaks.

What else does the software need to do? If this is the only thing, you can just poll the crap out of it. Otherwise you will probably want to look at interrupts.

adafruit_support_bill
 
Posts: 76070
Joined: Sat Feb 07, 2009 10:11 am

Re: Best way to Integrate a signal from a photodiode?

by stinkbutt on Mon Nov 22, 2010 6:38 pm

Yeah, you don't need an integrator, you just need to look for a change in the output of that sensor. Polling makes more sense since you need to look at how high the output goes. You could put it on a timer and then change a global variable to designate whether the output was last high or low.
Red M&M, Blue M&M: They all wind up the same color

stinkbutt
 
Posts: 593
Joined: Wed Feb 17, 2010 2:40 am

Please be positive and constructive with your questions and comments.