Analog accuracy

Hello,

I am wondering if anyone ekse has a problem reading the analog pins and getting good accuracy. I am using a sensor that I have used brilliantly with other microcontrollers. The sensors outputs 0-5v to the Fez but the readings from the FEZ Panda II to the Debugger are all wrong. I expect a steady number between 0 and 1023…byt they are all over the place. It is a three axis accelerometer by the way. Normally the numbers are the same when not sitting still but here they are reading (for example):

721
716
743
742
719
736
683
668
724
721
668

This is completely wrong…

max voltage to ADC is 3.3 volts.

This is actually made for the lilypad and it is made to work at 5v.

In any event the same thing happens at 3 volts. It is all over th place. Just to check I plugged it into an Arduino and it was flatlined at 510 which is the correct value according to a lot of other user (508-512 for a level plane). It should not matter what microcontroller I use it as it just feeds a voltage…

I am new to this NETMF but maybe I am referencing the wrong machine? Fez Panda II…

using System;
using System.Threading;
using Microsoft.SPOT;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;

namespace MFConsoleApplication1
{
public class Program
{
public static void Main()
{
Debug.Print(
Resources.GetString(Resources.StringResources.String1));

        AnalogIn lightSensor = new AnalogIn((AnalogIn.Pin)FEZ_Pin.AnalogIn.An0);


        int lightSensorReading = 0;
        while (true)
        {
            lightSensorReading = lightSensor.Read();
            Debug.Print(lightSensorReading.ToString());


        }

    }

}

}

@ rgm - please use code tags. The Panda II is 3.3V only. Most pins are 5V tolerant, but that only means you (hopefully) won’t fry the board hooking it up to 5V.

Thx RansomHall…That is very good to know.

Sorry about the tags I am new to this so I apologize ;D

So I have used the 3V3 to the sesnor and it is still all over the place. For example:

496
500
502
502
497
499
501

Any ideas?

You can always edit your previous post and add code tags :wink:

I would not call that “all over the place”. Results will depend on the accuracy of your sensor, the overall circuit design, noise, etc…

post details about your accelerometer. maybe somebody here has experience with the same one?

496 to 501 is what you see and this looks very normal to me.

Thanks for the replies. I guess I was just comparing it to my Arduino which was flatlined and it was troubling. If the sensor is not moving I would assume it would have a flatline.

I am a mech engineer and this is new to me so thanks for the paitence!

Rob

Which sensor is it? do you have a link to the datasheet?

@ rgm You will find in the NXP datasheet corresponding to your device, the definition of all the noise (in term of SNR or lsb due to quantification steps…)

Check also that others Analog pins are connected.

Yes, @ leforban has a great point, we’ve seen other people improve the stability of readings by tying the unused AnalogIn pins to GND

Maybe arduino libs had a digital filter in code? It is easy to get average or median.

Here is a link to the data sheet.

http://www.electrokit.com/productFile/download/457

I am going to test it on a netduino plus and see if there is a difference.

Anways I will let you know.

Just to make distinction between error of sensor and error of analog to digital conversion. Why don’t you connect a 1.5V battery to the analog input. If the ADC is perfect you shouldn’t see variation, but you will probably see noise (due to quantification, EMI…)

To eliminate this you can filter EMI (better quality cable, no parallel long line, add capacitor…) and if it is not enough you can then compute average on some sample…

Another thing to keep in mind is the resolution/type of the A2D converter that is built into the microcontroller. The microcontroller the small FEZ boards use has an A2D converter 10bit resolution. If you compare the reading to a microcontroller with an 8bit A2D converter the 10bit resolution will allow yo to see smaller changes in the signal.

So an update that may help others. I drilled the board to a wooden plank and the numbers are very steady now. It is like night and day. Perhaps the desk was causing noise