Society of Robots - Robot Forum
Electronics => Electronics => Topic started by: Geir on January 22, 2009, 09:11:51 AM
-
I connected my GP2D12 distance sensor to an ATmega168. The software just waits for a measurement scales it down to 8 bit. And then sends it to the computer in a loop. I placed the sensor 15cm from a black coffi cup. Then i took 10000 samples and did a plot in matlab. The plot came out like this http://gp2d12.russemotto.com (http://gp2d12.russemotto.com).
Is the GP2D12 this bad?
-
Make sure the surface your looking at isnt shiny at all and also make sure there are no unexpected sources of infrared light in the area such as a tv remote or a window with the sun pouring in.
-
there should not be and thing disturbing it. And the variation is really big
-
try going into a room that doesnt have any natural light and slowly move an object forwards and backwards in front of it and see if the readings go all over the place or if the distance curve follows your motion
-
Hi,
What's your sample speed?
-
Ha, that question here is very critical... If you are using lamps for lighting... what type???
These long tube lamps generate a generous amount of IR light, frenzying your equipment...
-
The GP2D12 should be fairly immune to light. The sensors themselves however are fairly noisy, and at 8 bit a +/- 8 fluctuation would be normal. The noise we see in your graph is 2-3x bigger than normal . . .
I make this mistake sometimes, but are you positive you are reading the same ADC port that it's plugged into? ADC ports can leave voltage onto nearby ports, making it sorta work but not quite.
-
There is very little light where I'm doing my experiments, so this should not be it. I checkt my connection it's on the right pin :) And i did the experiment one more time today. For some reasone it got better, there is still some noise but not as bad. I uploaded the image, so you can see what you think. I did the experiment like 10 times yesterday and every plot was really bad, strange.
I don't know the sample rate. The prosessor is running at 8MHz. And the code is like this:
a2dInit();
a2dSetPrescaler(ADC_PRESCALE_DIV32);
a2dSetReference(ADC_REFERENCE_AVCC);
while(1)
{
val=a2dConvert8bit(5);
uart_putint(val);
}
Im not really used to avr so if you see a problem yell it out:) Thanks for the help so far ;D
-
With ADC_PRESCALE_DIV32 the clock to ADC is abouot 8Mhz/32 = 250K which is higher than max specified in datasheet for 10bit precision.
"By default, the successive approximation circuitry requires an input clock frequency between 50 kHz and 200 kHz to get maximum resolution. If a lower resolution than 10 bits is needed, the input clock frequency to the ADC can be higher than 200 kHz to get a higher sample rate."
Your second picture is more are less what is expected. The sharp sensors are noisy. It will help if you put 10uF capacitor as close to Sharp sensor power pins as possible. I solder a SMD 0602 capacitor right between the connector power pins. I am talking about pins on the PCB of the sensor.
-
I changed the prescale to 64 not mutch change. But if the second on is what you expect i guess the sensor is OK
-
Try to hook a multimeter up to the output, you should the voltage moving when you move objects closer to it. (it will verify that the sensor is working properly). Once it is then its just a noise problem....
-
The AD reads the voltage so i know the sensor is working. The question is, if the noise is normal?
-
Take the suggestion of Brijesh and be sure to have a cap on the power line for the sensor. When I did this on my sensor it made a BIG difference. Also try various targets. It seems that some targets are read better and some not so well.
Kirk
-
I did not save any oscilloscope screen shots of sensor output or power supply lines. But here is someone who did do it.
http://www.robotroom.com/DistanceSensor3.html#SIGNAL
To get good range and power output from the transmitter, they probably send a large current through the transmitter LED for short period of time. This large spike in current causes spikes on the power supply lines. These spikes manifest themselves on the signal line and affect ADC in the AVR.
In the above link the author talks about 10uF cap and 0.1uF ceramic cap. If you are using electrolytic caps for 10uf then ceramic cap is needed. If you are using a surface mount cap then single ceramic cap in 10uF range is sufficient. The closer to sensor PCB power pins the better it is.
-
ok thank I'll try the cap and check it whit the scope.