Analog reading

Hi all

In my project I’m using different analog inputs for reading voltage, temperature etc.

I couldn’t get my voltage to be correct, so I started tracking down the problem, and it seems that when I enable ADC0, my reading from ADC2 gets screwed up. If I don’t enable it, the readings are correct). Below are some raw reading from ADC2 (just with the pin floating with nothing attached, so i jumps arround a bit):

21
2
34
0
29
46
33
0
36
0
48
14
Enable analog 0
100
190
190
188
144
191
201
102
102
137
224

As you can see the values are suddenly larger. Why is that? Am i missing something? I don’t use the touch controller, I use my own I2C capacitive touch, so I should be able to use ADC0.

/Kenneth

Capacitive touch? I woul love to see some pictures :slight_smile:

About ADC, make sure all voltages coming in are under 3.3V and better under 3V

I also have seen this and my voltages are well below 3V.

More troubling for me was the ripple that is present on the analog inputs. My scope can’t pick up much variance in the analog signal, but connected to Cobra I get a bunch.

My solution was to write some filtering routines (stdev, moving average etc.), but I wish I did not have to. Putting caps on the signal did not help. Made me think the issue was internal to the EMX board or I was doing someting wrong. Since accuracy is not critical for me yet I have left this to later debug sessions.

Two examples sensors I use are:

http://www.robotshop.com/content/PDF/datasheet-and-schematic-sen-09028.pdf
http://www.national.com/mpf/LM/LM35.html#Overview

-AP

I don’t know how the GHI controls the ADC’s but maybe the problem is they don’t wait long enough to sample the input after they switch the analog channel multiplexer to another channel.

An easy way to detect this is by using “register access” to read the analog inputs directly from the processor.

@ Gus
Yes the cap touch works very vell…very responsive :slight_smile:

Regarding the ADC. Currently there’s no voltage comming in on the pin… the test is on a completely clean EMX dev. board with nothing attached to the pins. So it’s not voltage problem. Furthermore this behavior only occurs when i enable ADC0 or ADC1, the others are fine.
So my thoughts is that this is caused by something related to the default touch controller?

Below is the code i used for testing:


public static void Main()
        {
            Program myApplication = new Program();
            Window mainWindow = myApplication.CreateWindow();
            GPIOButtonInputProvider inputProvider = new GPIOButtonInputProvider(null);
            myApplication.Run(mainWindow);
        }

        private Window mainWindow;
        private AnalogIn ad2;
        private AnalogIn ad0;

        public Window CreateWindow()
        {
            mainWindow = new Window();
            mainWindow.Height = SystemMetrics.ScreenHeight;
            mainWindow.Width = SystemMetrics.ScreenWidth;
            mainWindow.AddHandler(Buttons.ButtonUpEvent, new RoutedEventHandler(OnButtonUp), false);
            mainWindow.Visibility = Visibility.Visible;
            Buttons.Focus(mainWindow);
          
            ad2 = new AnalogIn(AnalogIn.Pin.Ain2);
            Thread t = new Thread(ReadAnalog);
            t.Start();

            return mainWindow;
        }

        private void ReadAnalog()
        {
            while(true)
            {
                double rawVoltage = (double) ad2.Read();
                Debug.Print(rawVoltage.ToString());
                Thread.Sleep(100);
            }
        }

        private void OnButtonUp(object sender, RoutedEventArgs evt)
        {
            ButtonEventArgs e = (ButtonEventArgs)evt;
            
            Debug.Print("Enable analog 0");
            if(ad0 == null)
                ad0 = new AnalogIn(AnalogIn.Pin.Ain0);
            Debug.Print(ad0.Read().ToString());
        }

try to attach somthing to ADC. It’s probably hardware not a software.
When there is nothing on ADC it catches inputs from other (near ones) pins.

On AVR mega I saw situation when sensor connected to adc0 made proportional input to adc7 and all pins in between. Tho when there was connected sensors on all adc’s they messured correct readings. I think it might be the same on your controller.

Are you suggesting enabling and grounding unused analog pins?

Yes floating pins can cause problems. Also analog inputs with high impedance would not work as nice.

In fact all unused inputs should be pulled down (analog and digital). Floating inputs oscillate and draw unnecessary power from the CPU.

You could also set the unused pins as output.

I just tried grounding ADC0 and the readings on ADC2 are now normal.

Thanks guys

I’m curious, does setting the AD0 (IO8) to an outputport have the same positive effect? I assume you had to ground directly to the EMX board because IO8 is not exposed on the IO header, but rather the Display header?

-AP

On this note

There are loads of NC pins on the Domino are all of them set to output as a default?

Try changing the clock as follows:
Register AD0CR = new AD0CR(0xE0034000);

AD0CR.ClearBits(0xFF << 8); // must clear first
AD0CR.SetBits(3 << 8); // DIV is 3

Try values 3 and up and let us know what the results are.

LOL, I love smileys! 8) = 8 )

Lol yes it is 8 )

Should’ve used the “code” button :wink:


AD0CR.ClearBits(0xFF << 8); // must clear first
AD0CR.SetBits(3 << 8); // DIV is 3