Best way to Integrate a signal from a photodiode?

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
iandol
 
Posts: 2
Joined: Mon Nov 22, 2010 1:13 pm

Best way to Integrate a signal from a photodiode?

Post by iandol »

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

                       -----      -----      -----      
 -----      -----      |    |     |    |     |    |     -----       ----- 
 |    |     |    |     |    |-----|    |-----|    |-----|    |      |    | 
-|    |-----|    |-----|                                     |------|    |
>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

tinsmith
 
Posts: 62
Joined: Thu Nov 18, 2010 9:18 pm

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

Post by tinsmith »

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.

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

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

Post by stinkbutt »

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.

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

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

Post by stinkbutt »

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

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.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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

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

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

Post by stinkbutt »

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.

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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.

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

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

Post by iandol »

Dear all, wow what a helpful bunch you are! :)
signal.png
signal.png (9.62 KiB) Viewed 2676 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:

User avatar
adafruit_support_bill
 
Posts: 88093
Joined: Sat Feb 07, 2009 10:11 am

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

Post by adafruit_support_bill »

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 BANNED out of it. Otherwise you will probably want to look at interrupts.

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

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

Post by stinkbutt »

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.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”