I have a project which utilizes a distance measurement sensor, namely the Sharp GP2Y0A710K0F. I need several meters of range and I found ultrasonic sensors to be unreliable. In the first version of my project, I used an Arduino Mega2560 to process the data. After I calibrated the sensor, it worked pretty well (the sensor has a poor documentation, so I measured the raw ADC data between 1-5m with 20cm gaps and made a 10th degree polynom to calculate the range). But then I ported the project to a standalone Atmega328P-PU and used a MAX11644 12bit ADC for better resolution. Or so I thought. Now it has a very large scattering and generally bad precision (usually 50-70 cm off, sometimes even 1-2 m). Longer distance has worse precision.
What I do with the data:
I read 10 values from the ADC, sort them with bubble sort and drop the items which differ much from the median value, then average the rest. This is the test code. The final code had another sort-drop-average round with 25 of these values.
This used to work fairly well on the Mega. When I started using the MAX11644, I simply mapped down the raw value from the 0-4095 range to 0-1023 and used the method as before.
I'm not sure if it's a lack of signal conditioning or it's the sensor, but I measured the sensor's output with a multimeter and sometimes it's in the 0.3-1.5V range, other times it's in the 1-3V range which looks better to me. I have 4 sensors, I tried putting a 100uF cap on one of the sensors' supply line but I don't see much difference with the stock sensors.
I also tried feeding the signal to the MAX11644 and the Atmega328's ADC at the same time to see if there a difference. The Atmega's measurement seems more stable, but still can't measure longer distances than 2,5m precisely.
Has anyone used these sensors or the MAX11644 before? Or have you experienced anything similar?
I can post some code or something if you want, but it's pretty long, so maybe we can find an explanation first without time consuming code digging (and I don't think it's code related).