Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: stt585 on December 29, 2007, 04:22:17 PM

Title: GP2Y0A2YK0F Sharp Distance Sensor
Post by: stt585 on December 29, 2007, 04:22:17 PM
Hi everyone, I am working with the GP2Y0A2YK0F Sharp distance sensor and am having significant noise problems with it.

Does anyone have experience using this sensor?  I see noise spikes occuring at 1kHz.  There are also lower frequency noise components as well because the output signal from the sensor is very "fuzzy."  I have thought about adding capacitors between the output pin and ground to filter out some of the noise, but the problem with this is that it decreases the response time of the sensor (ie. if you very suddenly remove the object in from of the sensor, the voltage should drop, but because of the capacitor, the output voltage drops very slowly until it finally reaches its steady state value approximately 2 s later. . .

If anyone has any expertise with this sensor, please let me know because I am starting to run out of ideas.  The output signal from the sensor is just way too fuzzy to be A/D'd with any decent accuracy.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Rebelgium on December 29, 2007, 04:28:10 PM
Just an idea: Place a smaller capacitor ( 22pF or something), this will cause the sensor to react much faster.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: robonoob on December 29, 2007, 05:29:45 PM
hi
sorry maybe im being impolite posting here but not helping you...but i was wondering if u could give me a link to that sensor cuz i-m doing a wallbot(wall avoiding robot) and maybe i could use one of those...
thank you
Title: Re: [b]GP2Y0A02YK0F[/b] Sharp Distance Sensor
Post by: stt585 on December 29, 2007, 05:39:08 PM
Hi, I made a mistake in the part number.
GP2Y0A02YK0F is the correct one.
http://search.digikey.com/scripts/DkSearch/dksus.dll?Detail?name=425-2062-ND
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: stt585 on December 29, 2007, 05:40:17 PM
Just an idea: Place a smaller capacitor ( 22pF or something), this will cause the sensor to react much faster.


Yes, that is true, but it doesn't eliminate the fuzziness of the output signal, which is the bigger problem.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: dunk on December 29, 2007, 06:21:50 PM
hey stt585,
you have probably tried this already but
have you tried testing your setup with a voltage divider in place of your sensor to test all the other components in your circuit?
there are a lot of places noise can creep in and it's worth ruling them out before you blame the sensor.

making sure i'm leaving enough time for my microcontrolers ADC to stabilise before taking a reading has caused me problems in the past.
shielding (or shortening) sensor wires is worth trying as well.

dunk.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Rebelgium on December 29, 2007, 06:34:34 PM
you can also use the sensor stand alone for a quick test setup, and then see if the spikes are still present. If they aren't, the problem isn't your sensor.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: stt585 on December 29, 2007, 07:11:45 PM
hey stt585,
you have probably tried this already but
have you tried testing your setup with a voltage divider in place of your sensor to test all the other components in your circuit?
there are a lot of places noise can creep in and it's worth ruling them out before you blame the sensor.

making sure i'm leaving enough time for my microcontrolers ADC to stabilise before taking a reading has caused me problems in the past.
shielding (or shortening) sensor wires is worth trying as well.

dunk.

Yep, I've got a 25k Pot that I was using before I replaced it with the sensor.  I was scoping the power rail just now and noticed that it became much much more noisier when i plugged in the sensor.  The noise on the power rail is the same frequency as the noise on the output of the sensor so I think that at least some of it is coming from the sensor itself.

I also noticed that the power rail was much noisier when a microcontroller was connected in the breadboard, but is pretty insignificant compared to the sensor noise.

No, I haven't tried fiddling around with the ADC setup and acquisition time yet.  That's a good idea, thanks!
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: stt585 on December 29, 2007, 07:14:08 PM
you can also use the sensor stand alone for a quick test setup, and then see if the spikes are still present. If they aren't, the problem isn't your sensor.

Ya, even when I just hook up +5V and GND to my sensor and read the output, it's noisy as hell.  I've even started eliminating ambient IR noise sources but haven't been able to isolate it yet.  Have you used this sensor before?
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: frank26080115 on December 31, 2007, 11:22:23 AM
http://www.robotroom.com/DistanceSensor3.html

David Cook made a lot of tests with different capacitors, also
Quote
a microcontroller could simply take multiple readings and discard the highest value to eliminate spikes.

Maybe you can take an average if it's too noisy to eliminate just one spike.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on December 31, 2007, 12:57:11 PM
I carefully looked at my readings with the analog GP2Y0A21YK just now.

No servos are running, nothing is blocking the sensor, and I have a 3300uF cap connected to the battery, with five .1uF caps right after my 5V regulator.

This is what I typically get in hyperterminal:
0 5 7 9 0 0 0 0 0 1 2 0 0 0 0

I never noticed this noise before . . . so I just investigated . . .

The above readings were done with this ADC setting:
a2dSetPrescaler(ADC_PRESCALE_DIV16); // configure ADC scaling

So I changed it to:
a2dSetPrescaler(ADC_PRESCALE_DIV128); // configure ADC scaling

Where higher DIV numbers increase accuracy but also increase read time (effectively finding an average over more time).

Now I got these typical values:
0 0 0 0 4 0 0 0 0 0 1 0 1 0 1

So this led me to believe that there are short lived spikes going on. So oscoping it, I got the attached image. I took this reading right from the sensor output bypassing the wires. Those spikes happened no matter what was in front of the sensor. My oscope autoset couldn't find a pattern in the spikes.

Odd . . .

edit: corrected a typo
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: stt585 on December 31, 2007, 02:36:20 PM
So this led me to believe that there are short lived spikes going on. So oscoping it, I got the attached image. I took this reading right from the sensor output bypassing the wires. Those spikes happened no matter what was in front of the sensor. My oscope autoset couldn't find a pattern in the spikes.

Odd . . .

http://document.sharpsma.com/files/GP2Y0A21YK-DATA-SHEET.PDF  (page 2)
I don't know how to explain those larger sporadic spikes . . . maybe ambient IR noise?  But those smaller ones closer to the signal--do they occur at intervals of approximately 40 ms?  I hypothesize that the "fuzzy" noise is the transition time between sample outputs.  Right now I think that I need to perform my A/D at a specific time, but even if I DO perform my A/D between those transition times, the signal is too "thick" to properly take a reading.

I will try to change my acquisition time settings on my microcontroller.  Is that what DIV does, or does it change the A/D conversion clockÉ
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on December 31, 2007, 03:03:34 PM
Quote
I don't know how to explain those larger sporadic spikes . . . maybe ambient IR noise?
well . . . i wasn't using a darkroom . . .

Quote
But those smaller ones closer to the signal--do they occur at intervals of approximately 40 ms?
looking closely at the signal, there are groupings of tiny spikes that occur for a duration of 30.44ms. and spaced by 8.86ms. I guess thats a total of 39.3ms, which is really close . . . you can see this in the image i attached.

The big spikes just seem to have no pattern . . .

Quote
Is that what DIV does, or does it change the A/D conversion clockÉ
this is what AVRlib says:
Quote
// A2D clock prescaler select
//      *selects how much the CPU clock frequency is divided
//      to create the A2D clock frequency
//      *lower division ratios make conversion go faster
//      *higher division ratios make conversions more accurate
#define ADC_PRESCALE_DIV2       0x00   ///< 0x01,0x00 -> CPU clk/2
#define ADC_PRESCALE_DIV4        0x02   ///< 0x02 -> CPU clk/4
#define ADC_PRESCALE_DIV8        0x03   ///< 0x03 -> CPU clk/8
#define ADC_PRESCALE_DIV16      0x04   ///< 0x04 -> CPU clk/16
#define ADC_PRESCALE_DIV32      0x05   ///< 0x05 -> CPU clk/32
#define ADC_PRESCALE_DIV64      0x06   ///< 0x06 -> CPU clk/64
#define ADC_PRESCALE_DIV128      0x07   ///< 0x07 -> CPU clk/128
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: stt585 on December 31, 2007, 03:37:30 PM
Awesome, thanks for all the thoughts, tips, advice and links everyone.  I will give this another try today!
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: benji on January 07, 2008, 04:20:02 PM
i have ordered this same ir for my mapping project,, is it a good one? what about noise?
how much resolution does it provide?
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: brijesh on January 07, 2008, 05:23:59 PM
There was similar thread sometime back. I am using sharp IR sensors too and felt it was too noisy. So dug around and came across this page.

http://www.gorobotics.net/Articles/Sensors/Effectively-Using-the-Sharp-GP2D12-Rangefinder/

I have written come code and tested it. Have not yet integrated it into the robots control loop so as to say anything about its performance. After filtering the max variation in the ADC output was limited to less then 10.

Other things to watch out for:
1) The reference voltage used by the ADC. On my board (Baby Orangutan AVR board) the reference voltage is 5V. But the max signal  range is from 0v to 2.45V, so top 2 bits are wasted.
2) Atmega data sheet says the accuracy of ADC is +/- 2LSB bits at 100KHz sampling rate.
3) Bandwidth of ADC is only around 35 KHz.
4) All the numbers above are from what I remember, don't have data sheets in front of me. Cross check them before using.

Brijesh

Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: benji on January 08, 2008, 07:12:53 AM
Quote
1) The reference voltage used by the ADC. On my board (Baby Orangutan AVR board) the reference voltage is 5V. But the max signal  range is from 0v to 2.45V, so top 2 bits are wasted.
how about having the output of the sharp IR into an op amp with gain of 2 and then to the AVR?? anyone tried this?
i guess that would increase the resolution 2 times
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: paulstreats on January 08, 2008, 09:00:37 AM
I use the GP2D12 sharp distance sensor. This has a lot of similar type noise but doesnt seem quite as bad as yours (it works well enough for me - it generally gives a correct range).

I generally take 5 readings and then divide the result by 5 in software to get an average value. I know its not perfect but it seems to work. but make things slow.

I looked at the difference between the GP2D12 and the GP2Y0A2YK0F and it seems the main difference that the beam width on the GP2Y0A2YK0F is almost twice as big as the GP2D12, Maybe this is causing some additional problems by having a wider detection range, greater scattering etc... Maybe there is a problem with reflections
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: brijesh on January 08, 2008, 01:57:18 PM

how about having the output of the sharp IR into an op amp with gain of 2 and then to the AVR?? anyone tried this?
i guess that would increase the resolution 2 times
[/quote]

Yes it will increase the resolution by 2 times.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: benji on January 09, 2008, 07:26:25 AM
well i think ill do this 2 times gain before goin to the avr , but about average values.. should somone get average values during the first 50 useconds or after the sensor is setteled?
how much timesteps between these five readings?
how much noise(mv) does this sensor give?anyone has a powerfull algo to get rid of this noise?
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on January 09, 2008, 10:19:55 AM
I think taking an average is bad for this type of noise. You don't want noise changing your average value.

To get rid of that noise in your algorithm, take 6 or so readings in ~5ms, and store each value. Compare each value, and if you see a value thats significantly different from the others, throw it out.

For example:

10, 12, 11, 12, 35, 11

Delete the 35, as its obviously noise. You will need a 'this is noise' threshold value. Using hyperterminal you can quickly figure out a good threshold.

10, 12, 11, 12, 11

Then you can average the remaining numbers: 11 (deleting noise) vs. 15 (average with noise)
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: benji on January 09, 2008, 01:32:52 PM
yea admin, that rocks, but what about this 5usecs? is it after the 50usecs of setteling or before the things settels? is this noise u guys are talking about before or after the sensor is settled,,,,,,?

thanks admin,,nice shot
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on January 09, 2008, 01:38:13 PM
Quote
what about this 5usecs? is it after the 50usecs of setteling or before the things settels?

Do something like this:

Code: [Select]
loop ~6 times:
take_reading
delay(1 ms)
store value

compare values
delete spike value(s)
average remaining values

Now to know how many readings you should take, and the delay time, print out your data in hyperterminal to see what you get.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: benji on January 09, 2008, 04:33:53 PM
you are taking a reading each 1 micro secs,,,, i suppose the sensor is moved, how much time would you wait before goin into the loop you have introduced? thats my q

by the way ,,if i connect my micro to the serial port, would hyper terminal show data directly when its recieved to the pc?
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on January 09, 2008, 06:08:15 PM
Again, you must use hyperterminal (yeap, using serial port to your PC) to determine the best sampling rate for your design. This is how I'd do it.

Quote
i suppose the sensor is moved
Sensor movement doesn't matter at 1ms. ;)
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: benji on January 21, 2008, 08:59:24 AM
sorry to get backon this a little late but i would like to say that this sensor (according to the datasheet) refreshes its output each 40 m seconds,so how do you folks aquiure its output at 1 khz???? anyone can explain?
i think we should wait 40 m each time we are goin to read a new out, or were you considering a steady state? if so im cool,but if there is a change in range that should be taken care of..
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: DomoArigato on January 21, 2008, 11:30:40 AM
Benji, I'm pretty sure your right, the fastest you can accurately sample that sendor is around 30ms - 40ms.  Did the guy who posted this have his microcontroller plugged into the wall?  I couldn't get accuarte readings when I did.
Title: Re: Fixing the problem
Post by: Commanderbob on May 24, 2008, 04:12:14 PM
I know this is an old topic but I had a problem with it a while back and now have a solution.

Here is the data with just the sensor:
Rise time ~65ns
Fall time ~1.65us
Peak to peak voltage ~2v

Sensor with 10nf ceramic capacitor on data line:
Rise time ~4us
Fall time ~340us
Peak to peak voltage ~0.1V

Sensor with 10uf ceramic capacitor and 530 ohm resistor parallel to the capacitor:
Rise time ~7us
Fall time ~6us
Peak to peak voltage ~0.11V

Conclusion, I would recommend adding a 10uf capacitor and a 530 ohm resistor to the data line on the IR sensor. The increased rise and fall times are nothing compared to the 1.9V difference in peak to peak value. There is a lot less noise with this configuration. Admin, I recommend putting this on the IR sensor page.

This was all tested/measured with a 2Y0A02 Sharp IR sensor and my 100MHz Tektronix Digital Oscilloscope.

Hopes this helps someone. ;D
Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on May 25, 2008, 03:31:56 PM
Quote
Admin, I recommend putting this on the IR sensor page.
done. ill try it out myself when i get time.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: SixRingz on May 25, 2008, 05:33:26 PM
Well, it's been a while since I took my electronics classes but I recall a lab excercise we did which was picking up alot of noise from the tube lights in the lab. (Do you call it tube lights? The long glass cylinders which are common in schools, hospitals etc) One of the excercises was to build an IR sensor, but I can't recall if this was the one suffering from that noise or if it was some other lab... Worth taking a look at anyhow. I ordered some Sharp sensors myself on friday, so I'm as eager as you guys to get to the bottom of this. I don't want to suffer from noisy readings!! >:(
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on May 25, 2008, 11:58:11 PM
Glad this helped someone  :D. I have not tried it with my microcontroller yet. I have also messed with some other values for the capacitor and any less and you get some noise and any more it does not really help with noise but makes the rising/falling edges longer. The resistor value is not so crucial some where around 500 ohms works good. That allows the capacitor to discharge faster. A smaller value may be a bit better, I have not tested it.

Admin you said your scope could not find a pattern in the spikes. When I set mine to peak detect it found that the spikes happen at around 1KHz. Each spike has the same shape a little spike flowed by a -320mv drop, then the larger spike that has a tail that lasts for about 1.5us. The whole glitch has a length of 1.75us.

You can sample the sensor faster then 40ms. You will get the same voltage, it won't cause any errors.

OK, I took some pictures with my camera, they will have to do until I get a USB drive for my scope.

Here is a closeup of one of the spikes.
(http://coilgunpower.com/forum/irwave.JPG)
This is what the signal looks like with peak detect setting.
(http://coilgunpower.com/forum/irnoise.JPG)
And here is the signal with the capacitor/resistor attached.
(http://coilgunpower.com/forum/irfixed.JPG)

Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on May 26, 2008, 03:56:13 AM
Just out of curiosity (and I apologize if you have already answered this earlier in the thread), do you have a bypass capacitor of 10uF or more between Vcc and ground somewhere near your sensor?

It seems to me like the easiest way to deal with noise from the sharp sensors would be to simply average readings over perhaps a 10 ms period.  Given that the refresh rate is greater than this, you're not losing any response time by doing this, and you're pretty much negating the impact of the glitches and other noise that might be overlaying the signal.

- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on May 26, 2008, 09:47:30 AM
Actually I did not put a cap on the power line. I powered it with +5V from USB on my computer. I think I posted this somewhere else but the Sharp IR sensors seem to take large bursts of power that causes the microcontroller to reset.

I just checked to see if that helped and it did absolutely nothing on the read out.

You could do as Admin said earlier and take multiple readings then use an algorithm to cancel the noise. That works OK but it has a two major problems.
1) Processing time, your microcontroller has to take multiple readings and then figure out which readings to average.
2) Sensor changes, if you take readings while the sensor is changing its output then you will get the wrong data.

Here is a picture of what I mean. This is the output as I move my hand up and down over the sensor. You can see each step is about 40ms.
(http://coilgunpower.com/forum/irchange.JPG)
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on May 26, 2008, 03:35:18 PM
Actually I did not put a cap on the power line. I powered it with +5V from USB on my computer. I think I posted this somewhere else but the Sharp IR sensors seem to take large bursts of power that causes the microcontroller to reset.
The datasheet recommends you use such a capacitor to protect your power line from these bursts.  I was wondering if it could also help smooth out the output just by smoothing out the supply.

I just checked to see if that helped and it did absolutely nothing on the read out.

Quote
1) Processing time, your microcontroller has to take multiple readings and then figure out which readings to average.
In general you should always be taking multiple analog readings to protect yourself from noise.  Since the ADC runs in hardware, you can have it set up to be constantly measuring and averageing in the background, which will take up almost none of your CPU's processing time.  I don't think it would be necessary to devote any resources to figuring out which readings to average: just average all the ones you get in some block of time of predetermined length, such as 5 or 10ms).


Quote
2) Sensor changes, if you take readings while the sensor is changing its output then you will get the wrong data.
Basically you'll get the same kind of result as with a capacitor during the time period that spans a step: you'll see a weighted average voltage somewhere between the high portion of the step and the low portion of the step.  If you're averaging results over a period of time that's several times smaller than the sharp sensor's refresh rate, your average values will usually be as correct as they can be given the sensor's refresh rate, or they will at least be smoothly inbetween steps.  Given that your algorithm already has to deal with the notion that your sharp sensor output might be 40ms behind reality, I don't think this step-averaging effect will be too significant.


- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Webbot on May 26, 2008, 04:24:04 PM
Request to Admin

There seems to be an endless number of threads covering Sharp IR detectors, noise etc. Some give potential solutions in hardware (with caps and resistors) and others give noise filtering solutions in software. It would be good to try and consolidate all this into "best practice" in the tutorials to try and consolidate all these threads and "head off" new ones with some kinda generic approach.

Appreciate your busy - but a holistic solution, that can be referenced in posts, will help us all trying to keep disparate threads up to date and cross referenced. As I understand it - this problem is common to all Sharp I/R devices - so it's not like we need different info for each device.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on May 26, 2008, 05:14:18 PM
Webbot I think the best solution is to use a combination of both. Ben is right ADC should be sampled more then once, but you should also have the cap/resistor combo to prevent the spikes as they will throw your average off. The larger spikes got up to 2V more then the correct reading.

Thanks,
Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Webbot on May 26, 2008, 06:18:12 PM
Commanderbob :- I'm not suggesting what the best answer may or may not be - I'm just suggesting that a 'unified' answer to the zillions of posts in the forum, in this thread and MANY others, is linked to the Sharp IR Tutorial. Otherwise newbies, let alone anyone else, will search the forum and be reading for days on end.

Its hard to see the wood for the trees.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on May 26, 2008, 10:21:07 PM
Webbot I think the best solution is to use a combination of both. Ben is right ADC should be sampled more then once, but you should also have the cap/resistor combo to prevent the spikes as they will throw your average off. The larger spikes got up to 2V more then the correct reading.
But the duration of the spikes is miniscule compared to the noise-free portion of the signal, so their effect on the average will pretty much be negligible (assuming your ADC sample rate is around 10 kHz, so you get plenty of samples in your average).  Averaging in software is for the most part functionally identical to using an RC filter to average/integrate in hardware.  Just as the voltage spikes will raise the software average slightly, so will they raise the average sensor output voltage if a capacitor is used to filter the noise.  My personal opinion is that it's sufficient for one to just use either the hardware filtering (capacitor) or software filtering (averaging).  Which one works best for you will depend on whether you'd rather sacrifice a few CPU cycles or modify your hardware/sacrifice prototyping space.

- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on June 01, 2008, 02:01:58 PM
Quote
Admin you said your scope could not find a pattern in the spikes. When I set mine to peak detect it found that the spikes happen at around 1KHz. Each spike has the same shape a little spike flowed by a -320mv drop, then the larger spike that has a tail that lasts for about 1.5us. The whole glitch has a length of 1.75us.
The little spikes had a pattern, but the larger ones were completely random (see my earlier pic).

Quote
It seems to me like the easiest way to deal with noise from the sharp sensors would be to simply average readings over perhaps a 10 ms period.
taking an average still isn't perfect:
http://www.societyofrobots.com/robotforum/index.php?topic=2712.msg19663#msg19663
I'd rather do it in hardware with the cap + resistor, anyway.

Quote
Request to Admin

There seems to be an endless number of threads covering Sharp IR detectors, noise etc. Some give potential solutions in hardware (with caps and resistors) and others give noise filtering solutions in software. It would be good to try and consolidate all this into "best practice" in the tutorials to try and consolidate all these threads and "head off" new ones with some kinda generic approach.

Appreciate your busy - but a holistic solution, that can be referenced in posts, will help us all trying to keep disparate threads up to date and cross referenced. As I understand it - this problem is common to all Sharp I/R devices - so it's not like we need different info for each device.
Entirely noted. As soon as I get time I'll do this.

Quote
But the duration of the spikes is miniscule compared to the noise-free portion of the signal, so their effect on the average will pretty much be negligible (assuming your ADC sample rate is around 10 kHz, so you get plenty of samples in your average).
Too processor intensive . . . and if you have a low sample rate, and a large spike gets into your average, it will throw it off.

Quote
Which one works best for you will depend on whether you'd rather sacrifice a few CPU cycles or modify your hardware/sacrifice prototyping space.
My plan was to solder the resistor + cap directly onto the back of the sensor. Probably 10 min of work tops ;D
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on June 01, 2008, 05:21:20 PM
Too processor intensive . . . and if you have a low sample rate, and a large spike gets into your average, it will throw it off.
It's not processor intensive at all given that the ADC functions in hardware.  If you clock the ADC at the I/O clock / 128 and note that the ADC takes 13 clock cycles to perform a conversion, you get 1664 instruction cycles (so maybe 1000 instructions) for every ADC sample you receive, and adding that sample to a running sum and starting the new conversion is what, maybe 20 instructions at most?  The burden this adds to the processor is maybe 2%.  Running the ADC constantly is one of the least processor-intensive things you can do on an AVR (assuming you aren't deliberately delaying the processor while the conversion is taking place).

As far as a large spike throwing the average off, as I said in an earlier post, the degree by which it throws the average off will basically be the same as the degree by which the voltage is thrown off by the presence of a capacitor.  The capacitor is doing in hardware the exact same thing as a software average (assuming you have enough data points in your average to approximate the continuity of an integral).  The only time a software average will perform worse than a capacitor is if you do something like in the thread you linked, which is to take only five readings and get unlucky enough to have a spike in the middle.  In the case of the sharp IR sensor, where the update rate is limited to maybe 25 Hz by the sensor itself, there's no reason not to take on the order of 100 samples per average, which would pretty much mitigate the presence of any large noise spikes to the same degree as a capacitor.

- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on June 01, 2008, 09:10:59 PM
The capacitor is doing in hardware the exact same thing as a software average (assuming you have enough data points in your average to approximate the continuity of an integral). 

That is not true at all. It would only be true if you did not have the resistor in parallel with the capacitor. When there is a spike the capacitor absorbs it and there is only a little increase in voltage. Then the capacitor is allowed to discharge the spike though the resistor effectively reducing noise and keeping the original signal.

Quote from: Admin
My plan was to solder the resistor + cap directly onto the back of the sensor. Probably 10 min of work tops Grin
That was my plan too. :D
Bens would that be so hard? ;) You could get a surface mount capacitor and resistor that would fit right between the pins.
Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on June 01, 2008, 10:12:26 PM
That is not true at all. It would only be true if you did not have the resistor in parallel with the capacitor. When there is a spike the capacitor absorbs it and there is only a little increase in voltage. Then the capacitor is allowed to discharge the spike though the resistor effectively reducing noise and keeping the original signal.
Your statement is incorrect.  An RC filter in this case acts as an integrator of the noise.  The output is identical to a software integration of the signal, which can be approximated via an average.  Every noise spike bumps the voltage slightly (this is because the RC filter smooths it out greatly, but the down side is that the voltage stays slightly above the real signal for significantly longer).  If the frequency of the noise spikes is high enough, your voltage output will always be slightly higher than the actual signal.  This is exactly the same result as you get when you add up all of the values over time and divide (i.e. the noise spike is smoothly distributed over a much longer time scale, leading to a voltage reading that is slightly higher than the signal).

Don't think that an RC filter gives you free and perfect noise suppression, because it doesn't.  It is doing in hardware what can easily be duplicated in software in this particular case.

Quote
Bens would that be so hard?  You could get a surface mount capacitor and resistor that would fit right between the pins.
It wouldn't be hard, but neither would the 10 lines of code it would take to accomplish this on on an AVR.  In my mind, the two solutions are functionally equivalent and it's just a matter of personal preference deciding on which one to use (for example, maybe you don't have surface mount caps and resistors in the right value range on hand).


- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Admin on June 01, 2008, 10:28:47 PM
Yea but software has a limited sample rate, and takes at least "2%" of processing :P

Anyway there is another point missed: that noise is going to interfere with other nearby sensors
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on June 01, 2008, 11:57:37 PM
Yea but software has a limited sample rate, and takes at least "2%" of processing :P
I sense a note of mockery in this.  Are you not as fond of theoretical software calculations as you are of theoretical mechanical calculations?  :P  As far as the limited sample rate, on an AVR it's still more than sufficient for getting accurate readings from the Sharp sensors.

Quote
Anyway there is another point missed: that noise is going to interfere with other nearby sensors
I could be wrong, but I don't think it will interfere with nearby sensors in any significant way (any more than high-speed serial communication interferes with nearby sensors).  I think the much bigger source of interference would come from not having a capacitor across the sensor's power and ground somewhere near the sensor as the sensor's large power-drain spikes will create system-wide power disturbances.

- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on June 02, 2008, 06:35:46 PM
I got some unexpected data for you guys. Before I show it I want to say that the measurements were taken with the IR sensor in a box, dark and the same distance away from the sensor. The vertical divide and the horizontal divide was left the same for all 3 shots.
Here it is...
Standard spike signal measured at 1.40V
(http://coilgunpower.com/forum/TEK0001.BMP)
Sensor with a capacitor on the output, signal still 1.40V, the spike is a different shape.
(http://coilgunpower.com/forum/TEK0002.BMP)
Sensor with RC filter, signal drops to 1.29V ???
(http://coilgunpower.com/forum/TEK0003.BMP)
I had to move this one up a bit so it was still on the screen.

Also note that this was with a 0.1 uf cap. (I could not find the small one I recommended) I will update this once I get one.

Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on June 02, 2008, 06:47:20 PM
What value resistor did you use and can you explain how you connected everything?  Putting a resistor on the sensor output is going to raise your output impedance and, depending on the magnitude of the input impedance of your measuring device, will throw off your readings somewhat.  When measuring voltages, you want to have as small an output impedance and as high an input impedance as possible, so you might want to use a larger capacitor and a smaller resistor.  Or maybe something else strange is going on.

- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on June 02, 2008, 07:59:48 PM
The resistor and the capacitor are both connected to ground and the signal line. The sensor can put out quite a bit of power, it can light a LED.

I found the capacitor I recommended before and a 450 ohm resistor. Here is the output. The first row is zoomed to see each spike and the second row is zoomed out to see many spikes. The first column is just the sensor, second is just capacitor, and third is capacitor and resistor.
(http://coilgunpower.com/forum/TEK0010.BMP)(http://coilgunpower.com/forum/TEK0011.BMP)(http://coilgunpower.com/forum/TEK0012.BMP)
(http://coilgunpower.com/forum/TEK0015.BMP)(http://coilgunpower.com/forum/TEK0014.BMP)(http://coilgunpower.com/forum/TEK0013.BMP)

The mean is the average so that is what you would get with the microcontroller if you manage to get 1GS/s. (thats what the scope is ;))

Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on June 02, 2008, 08:31:43 PM
If your resistor and capacitor are both connected to ground and the signal line, then you aren't using an RC filter.  In an RC filter the resistor and capacitor are in series, which lets the resistor limit the flow of current through the capacitor.  What you are describing is a resistor and capacitor in parallel, and the effect is that you are putting a very strong pull-down resistor on the signal output, and then filtering that with a capacitor.  This would explain why your third column is 20% lower than what it should be.  You definitely don't want a pull-down resistor on an analog voltage signal.

The mean is the average so that is what you would get with the microcontroller if you manage to get 1GS/s. (thats what the scope is ;))
Given that signal, I'd put money on being within 1% of that mean measuring at 10 kHz.

- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on June 02, 2008, 09:15:10 PM
You definitely don't want a pull-down resistor on an analog voltage signal.

I know that it is dropping the signal but it makes the fall time a lot shorter. See my earlier post. I will try adding some other stuff and see what I can get. Any suggestions for removing noise?

Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: bens on June 02, 2008, 11:55:06 PM
I know that it is dropping the signal but it makes the fall time a lot shorter.
Losing 20% of your signal to get a shorter fall time might not be worth it, though.  Is the pull-down effect a constant or is it dependent on the output voltage (in which case it would interfere with the ability to linearize the sensor output)?  I'd be interested to see what an RC filter does to the signal (i.e. sensor output -> resistor -> x -> capacitor -> ground, where X is your filtered signal)


- Ben
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on June 03, 2008, 04:46:01 PM
Ask and you shall receive.  ;)
Sensor->450 ohm->test point->10nf->ground
First picture is the control second is with the filter.
(http://coilgunpower.com/forum/TEK0019.BMP)(http://coilgunpower.com/forum/TEK0020.BMP)

EDIT: I forgot to say that I think the reason that it is lower is there are some low spikes that will pull it down.
Justin
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Murmandamus on March 11, 2009, 10:10:33 PM
Hi people,

Sorry for bumping this old topic. I'm new to this site (and loving it by the way!) and just found this topic via this article about Sharp IR range sensors (http://www.societyofrobots.com/sensors_sharpirrange.shtml). The article talks about these sensors being noisy and links to one of the posts in this thread as being the best known solution to date.

I haven't read the entire topic (nor any other topics on this forum yet) but I just decided to register and drop a quick reply here, because I didn't see the following mentioned. I've played around with a couple of Sharp GP2D02's (one of the digital range sensor variants) a couple of years ago, and I remember reading somewhere that it actually helps reduce noise (a lot) if you ground the sensor casing. Yes, that black plastic box that houses the sensor, electrically connect it to ground. I remember doing that and noticing dramatic improvement. I imagine the same might be true for the particular analog variant mentioned in this thread.

I thought this was common knowledge, but again, I didn't see it mentioned here. If everybody already knows about this, or if I'm wrong afterall, then my apologies... If not, try it!

Cheers
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on March 11, 2009, 11:22:49 PM
Is the black case even conductive? I though it was some sort of plastic. How would you go about grounding it?

Thanks for the suggestion!
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Murmandamus on March 12, 2009, 03:47:44 PM
Is the black case even conductive? I though it was some sort of plastic. How would you go about grounding it?

Thanks for the suggestion!

Yes, that's the surprise, apparently it is conductive. At least to some extent that makes a difference. The way I grounded it at the time was by sticking a wire into the mounting hole and securing that with the screw (plus a ring) used for mounting the sensor. The other end of the wire, of course, goes to ground (i.e. negative pole of whatever powers your project). That was just a test setup, don't know how well it would hold on a mobile platform. Haven't done a lot of playing with this stuff since then, unfortunately. But anything that connects the casing to ground should do.

I've been scratching my head where the heck I found this particular tip, and finally dug up the following link: http://www.barello.net/Papers/GP2D02/ (http://www.barello.net/Papers/GP2D02/) - I have no idea how I came to that site at the time. Just scroll almost halfway down and look for a paragraph under the header "Physical mounting issues". I have a couple more links about the GP2D02 but none of them mention the grounding thing. By the way this is an older variant of the Sharp IR sensors, I don't think it's even available anymore. And I don't know if the current variants still have the same issues. But it's worth a try.

Hope it helps!
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on March 12, 2009, 10:44:23 PM
Wow, I would of never guessed. My multi-meter just showed that from each hole (2Y0A02) it has a resistance of about 3K ohms and sometimes as low as 500 ohms, depending on how I hold the probes. Once I get some time I will try grounding it and see how that affects the output.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Commanderbob on March 18, 2009, 06:36:19 PM
Alright I did some tests. For my tests I simply took my Sharp 2Y0A02 sensor and put it in a paper cup. Then I gave it power, took a sample of its original signal spikes, grounded the case and took another sample. here are the two images.

Control
(http://coilgunpower.com/forum/control.BMP)

Grounded Case
(http://coilgunpower.com/forum/grounded.BMP)

As you can see grounding the case (I just used an alligator clip) significantly reduces the spikes intensity. If I grounded it better (maybe in multiple places?) the spikes would go down even more.

Great tip, I'll be grounding the cases from now on.
Title: Re: GP2Y0A2YK0F Sharp Distance Sensor
Post by: Murmandamus on March 19, 2009, 12:53:54 AM
Great to know it helps, thanks for the update!