Main Site Documentation

Analogin ADC0 and ADC1


#1

Hi all

I am still having troubles with my custom PCB for EMX. When reading the ADCO and ADC1 , I see unpredictable values.

Instanciation of analogin are made with:
AnalogIn an1=new AnalogIn(AnalogIn.Pin.Ain0);
AnalogIn an2=new AnalogIn(AnalogIn.Pin.Ain1);

I have a doubt about how to use them. I have tried (without any success) to deactivate touch screen support using:
GHIElectronics.NETMF.Hardware.Configuration.Touch.UseDefaultInterface(false);

Am I missing something?

Best regards to all


#2

That should be it. I ma not sure why it is not working for you.

Connect AN0 to ground and check the returned values, it should be zero or very close to zero


#3

Hello GUS

Here’s my test code:

using System;
using System.Threading;

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

namespace TESTANALOG
{
    public class Program
    {
        public static void Main()
        {
            // Blink board LED

           GHIElectronics.NETMF.Hardware.Configuration.Touch.UseDefaultInterface(false);
            OutputPort buzzer = new OutputPort(EMX.Pin.IO13, false);
            AnalogIn an1=new AnalogIn(AnalogIn.Pin.Ain0);
            AnalogIn an2=new AnalogIn(AnalogIn.Pin.Ain1);
            AnalogIn an5=new AnalogIn(AnalogIn.Pin.Ain5);
            AnalogIn an6=new AnalogIn(AnalogIn.Pin.Ain6);
            AnalogIn an7=new AnalogIn(AnalogIn.Pin.Ain7);

            while(true)
            {   int van1=an1.Read(); int van2=an2.Read();int van5=an5.Read();int van6=an6.Read();int van7=an7.Read();
                Debug.Print("Value AN1="+ (van1*10/1000).ToString()+"."+((van1*10)%1000).ToString());
                Debug.Print("Value AN2="+ (van2*10/1000).ToString()+"."+((van2*10)%1000).ToString());
                Debug.Print("Value AN5="+ (van5*10/1000).ToString()+"."+((van5*10)%1000).ToString());
                Debug.Print("Value AN6="+ (van6*10/1000).ToString()+"."+((van6*10)%1000).ToString());
                Debug.Print("Value AN7="+ (van7*10/1000).ToString()+"."+((van7*10)%1000).ToString());
                
                Thread.Sleep(1000);
                // Sleep for 1000 milliseconds
          
            }
        }

    }
}

And here is a bunch of results with the five pins connected to GND.

Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.40
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.20
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.30
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.120
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.10
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.320
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.30
Value AN2=0.320
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.20
Value AN2=0.130
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.30
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.40
Value AN2=0.10
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.80
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.80
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.780
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.20
Value AN1=0.40
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.30
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.0
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.20
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0
Value AN1=0.280
Value AN2=0.0
Value AN5=0.0
Value AN6=0.0
Value AN7=0.0


#4

Results look normal. Noise on built in ADC is expected.

For super accuracy on analog inputs, there has to be a complete isolation between digital and analog circuitry. (external ADC with separate power source).


#5

Hi Gus

You say that these values are normal. This is not exactly what I am used to see and the fact that only ADC0 and ADC1 are affected seems to be an error on my board (EMC ???)

Without formatting values into Voltage (i.e. printing raw data) I observed that ADC0 goes from 0 to 58. This is really far from what we can expect with 10 bit resolution and an abosolute error of +/- 4LSB conbined with an offset error of +/-3LSB as described in the NXP datasheet. Therefore I think I have something wrong on my custom board, probably EMC.

If someone can perform the same test it would be great…


#6

There are many factors that jump in play with analog designs. Starting from separating power sources and having more spread out layout on PCB. EMX is a very compact 8 layer board so there isn’t much room for separating noise. Maybe use a digital filter to enhance the results.


#7

I am not sure that the problem comes from EMX, It may be due to bad routing of my custom PCB. I go on my investigations about that and will let you know. My main doubt was about disabling or not the touch controller. if the parameter has to be set to false or true.

Regards

Jeremie


#8

Hi GUS on an other post quitly related to this one:
http://www.tinyclr.com/forum/10/1975/#/1/

You said that:

I have try this without knowing what it means exactly but didn’t observe better results.

However I have modifying the code in order to average results of 64 samples. This seems better but it will consume processor ressources…

Here is the average data with all the 7 ADC connected together to a lab power supply.
Van1=123.84375
Van2=122.65625
Van5=119.765625
Van6=121.34375
Van7=122.484375
Van1=123.484375
Van2=121.953125
Van5=121.015625
Van6=121.09375
Van7=122.515625
Van1=123.5625
Van2=124.734375
Van5=120.765625
Van6=120.984375
Van7=122.390625
Van1=126.359375
Van2=126.0625
Van5=120.828125
Van6=121.125
Van7=122.34375
Van1=120.25
Van2=125.734375
Van5=120.71875
Van6=121.265625
Van7=122.34375
Van1=121.84375
Van2=121.390625
Van5=120.796875
Van6=121.5
Van7=122.234375
Van1=123.71875
Van2=117.90625
Van5=120.65625
Van6=120.984375
Van7=122.28125
Van1=121.703125
Van2=122.296875
Van5=120.953125
Van6=121.15625
Van7=122
Van1=124.140625
Van2=116.984375
Van5=120.875
Van6=121.265625
Van7=122.375
Van1=122.84375
Van2=130.109375
Van5=121.15625
Van6=121.265625
Van7=122.21875
Van1=130.125
Van2=124.921875
Van5=120.765625
Van6=121.171875
Van7=122.28125
Van1=122.015625
Van2=121.28125
Van5=120.921875
Van6=121.234375
Van7=122.5625


#9

One thing you can do to improve (not sure how much it will thought) is by filtering the power source going to EMX, using capacitor/coils/ferrite-beads…you know, the usual.


#10

I have nearly the same problem, I use ADC 2 and 3 and the values are very floaty, I have testes with connecting to ground or to vcc and it floats periodicly.

I think its a problem with the power supply of my board, if I use the usb port to power the cobra, its not so bad, but with a external psu its very floaty.

But I have no oscilloscope to prove it.


#11

Would grounding any unused adc ports help?


#12

I started to ground all ADC’s but I cant find ADC4 on the Cobra, which pin is it?


#13

You do not need to ground all pins but you need to have all ADC configured pins connected or grounded.

There is no ADC 4 IIRC