### Author Topic: How to sense square wave light  (Read 2182 times)

0 Members and 1 Guest are viewing this topic.

#### benjammin105

• Jr. Member
• Posts: 37
##### How to sense square wave light
« on: January 26, 2010, 10:50:45 PM »
I'm not experienced in robot designs and this is my first project. We are entered in a robotics competition for school. We are a making an autonomous robot and using the Axon as the brain for it. The question I have is the robot has to be able to detect frequency light off a sine wave at 4 corner of 20, 40, 60, and 80 Khz. I'm looking for a sensor that would do something like this . I've looked at the sensors from Taos and don't actually know enough about all of this to be able to tell if they are what I'm looking for. The course is 8 ft. across so I need a sensor that could cover this range. If anyone might have an idea about this or could point me in the right direction I would be very appreciative. Thank you.

• Supreme Robot
• Posts: 11,669
##### Re: How to sense square wave light
« Reply #1 on: January 27, 2010, 10:12:14 AM »
First question, what is the frequency of the light (ie spectrum - IR, ultraviolet, visible, etc)? If its visible light, what color?

Basically, knowing what the light is, you then look up datasheets of light sensors and determine if that sensor is good for it.

Read this, then come back if you get stuck again:
http://www.societyofrobots.com/sensors_color.shtml

#### benjammin105

• Jr. Member
• Posts: 37
##### Re: How to sense square wave light
« Reply #2 on: January 30, 2010, 02:18:39 PM »
It is white visible light, but what I'm having the count is the pulses because it is being driven by a square wave. I'm thinking there is a way to do this with the ADC on my axon and with a photodiode but I'm not sure. Does anyone know anything about that kinda thing?

• Supreme Robot
• Posts: 11,669
##### Re: How to sense square wave light
« Reply #3 on: January 30, 2010, 09:36:56 PM »
There is.

To test it out, write a short program that reads the ADC, and outputs the value to hyperterminal. You'll then know how to write a 'is the value high or low' program.

Be aware that the value will change with ambient light (such as a cloud blocking the light coming into your window). So you're code will have to be smart[er].

• Robot Overlord
• Posts: 202
##### Re: How to sense square wave light
« Reply #4 on: January 31, 2010, 03:21:29 AM »
Be aware also that to accurately count pulses with your ADC you will have to sample at twice your maximum signal frequency (google 'sample theorem' and 'Nyquist rate'). 160kHz is a good way beyond typical sampling frequencies for an ATMega processor.

You may be better off looking at building a filter circuit for the output from your photodiode. With some simple highpass filtering (google 'RC highpass filter') and some amplification you could reject ambient/mains light (but watch out because some flourescents now operate in the 20kHz region) and should be able to feed your signal to the comparators on the Axon or an external comparator. This should give you a binary (logic level) signal with the same frequency which is comparatively easy for the microcontroller to measure.

#### benjammin105

• Jr. Member
• Posts: 37
##### Re: How to sense square wave light
« Reply #5 on: February 01, 2010, 10:55:39 PM »
hopslink, I'm interested in trying your idea. I just got a few questions about it. First of all, with an active high pass filter using an op-amp I was wondering if the gain is going to extend the range of my photodiode? On the photodiode datasheet it say it operates best at 950 nm? If I select a R2 of 47kohm and a R1 of 4.7kohm I would have a gain of 10. How would this gain related to my distance or am I only jacking up the voltage coming out of the filter? I was planning on my cutoff frequency being around 19 khz so I believe a .001microfarad capacitor would be optimal...Am I on the right track or way off? thank you either way

• Robot Overlord
• Posts: 202
##### Re: How to sense square wave light
« Reply #6 on: February 02, 2010, 04:56:13 AM »
Two main factors will set the effective range of your detector. Sensitivity of your photodiode and filter performance. The sensitivity of the photodiode is fixed at manufacture. To improve sensitivity you could select a different photodiode or use a lens to gather more incoming light. The filter acts to separate the signal you want from any noise. Provided you can achieve good separation even a tiny signal can be used, so good filtering can greatly increase the effective range of your sensor.

Filter gain has no direct effect on effective range but amplification is important for the function of your circuit. You need to match the output from your filter to your detection circuit so it may be worth using a low fixed gain for the filter itself and having another variable gain amplifier to allow easier matching.

Many photodiodes are most sensitive at longer wavelengths and 950nm is well into the IR portion of the spectrum.  Unless your signals have an IR component you need to compare photodiode response at the wavelengths corresponding to your signals.

Sounds like you are on the right track. There are many resources available for designing Sallen and Key type filters (I pull values from tables in Horowitz and Hill's excellent 'The Art of Electronics' as it is sat on my bookshelf). Also be aware that several IC manufacturers produce these types of filter and provide online tools for design.

Be aware that this is a bit of a 'catch all' filtering style. While it will greatly improve your chances of detecting the signals you want you will need to be careful. Shroud your photodiode so that it can not see light from multiple emitters at the same time or you may get crosstalk type problems. If this becomes an issue you may need to look at specific bandpass filtering, but the best thing to do is get it built and start testing it

#### benjammin105

• Jr. Member
• Posts: 37
##### Re: How to sense square wave light
« Reply #7 on: February 02, 2010, 11:09:23 PM »
I'm really appreciating all of the information and I think I'm getting closer to the solution that I'm looking for. I've taken your advice and designed a Sallen-key high pass filter for my photodiode. I used the formulas and I'm getting a 12 ohm for R1 and R2. I'm getting .68microfarad for C1 and C2. This makes my cutoff frequency right at 19.5KHz which is right below the range that I want to detect the pulse of (20kHz-80kHz). The photodiode I selected has a spectral sensitivity of 400 all the way to like 1100 or so in the infrared range. I'm also about to start looking into a lens that will make the detection of the lights possible at far distances.

Just a few more questions though. Even though I have my filter with the op-amp and everything, do I still need to run this circuit thru another op-amp amplifier stage or should this be good as is? and you mentioned a detector circuit...what would something like that include? Would that be the ADC on the Axon or what? Thanks for everything! This makes me wish I would have gotten more application in electronics class!

• Robot Overlord
• Posts: 202
##### Re: How to sense square wave light
« Reply #8 on: February 03, 2010, 02:39:24 AM »
Quote
I used the formulas and I'm getting a 12 ohm for R1 and R2.
12 Ohm seems very low. Look to get it up to 10-100kOhm range and adjust C to suit.
Quote
I'm also about to start looking into a lens that will make the detection of the lights possible at far distances.
If your arena is 8'x8' then the maximum distance you can be reading an emitter from is >12' (approx. head trig). I would get the system built and test it before you worry too much about range.
Quote
...do I still need to run this circuit thru another op-amp amplifier stage or should this be good as is?
The op-amp amplifier should make things easier. They generally come 2-4 on an IC anyway.
Quote
...and you mentioned a detector circuit...what would something like that include? Would that be the ADC on the Axon or what?
Not the ADC for the reasons mentioned above. I would be looking at using a comparator on the Axon or an external comparator feeding a digital input (ideally one of the input capture unit pins). The comparator is essentially a 1 bit ADC. It compares two inputs, one your signal and the other a threshold value, and switches it's output high or low depending which is greater. This is why you want some method for adjusting gain in your circuit as it becomes far easier to adjust the output voltage from your filter to a sensible input voltage for the comparator.

#### benjammin105

• Jr. Member
• Posts: 37
##### Re: How to sense square wave light
« Reply #9 on: February 03, 2010, 09:37:48 PM »
I'm trying to use a bigger resistor but the only problem is with larger resistors I get smaller capacitors. The really small capacitors are either not available or ridiculously expensive. The best I've been able to spec out is something with a .1microfarad for 9 cents and the resistors would be around 80 ohms. I was wondering why the resistors had to be large like in kohm range?

• Robot Overlord
• Posts: 202
##### Re: How to sense square wave light
« Reply #10 on: February 04, 2010, 02:33:20 AM »
The open-loop output impedance of the op-amp rises at high frequencies adding to your resistor values. If these resistors are very small then this effect will be significant and alter the frequency response of your filter.

You should be able to source capacitors down into the pF (pico, 10-12) range.

#### benjammin105

• Jr. Member
• Posts: 37
##### Re: How to sense square wave light
« Reply #11 on: February 04, 2010, 06:46:50 PM »
I got it man. I got some 8.2kohm resistors and 1nF caps. they were both common and easy to find. Gonna build it when my op amps come in. thanks for everything! I'll let you know what happens!

#### Soeren

• Supreme Robot
• Posts: 4,672
##### Re: How to sense square wave light
« Reply #12 on: February 04, 2010, 07:31:46 PM »
Hi,

You are cruisin' down the wrong street, going with conventional analog filters, unless you plan on making 8 nodes filters or there abouts (reserve lots of PCB real estate if you do).
A small DSP (like a DSPic) would be the very easy way of making a steep enough filter, but that takes the ability to design and implement eg. a FIR-filter.

I'll suggest a reasonably easy method. Use 4 PLL tone decoders LM567 (or XR567), each tuned to the frequency of one beacon and use a photo transistor as a "microphone" with an amplifier that has the needed gain at 80 kHz which the PLL's is then listening to.

Besides reading each output (which is open collector, so needs a pull up set or an external pull up) in polled mode, a diode OR "gate" could go to an interrupt input to tell the program to read the 4 lines.
Regards,
Søren

A rather fast and fairly heavy robot with quite large wheels needs what? A lot of power?