EMX ADC Instability

Hi,
Forum just logged me out after typing this the first time - and trashed my message :-((. So here goes again…

I have EMX modules fitted to my own boards, and use V4.1 code.

I use AD0 and AD1 fed straight from an Op Amp with a VERY stable DC voltage (varies typically by 1/10 milliVolt during test period) measured with a bench DMM.

I still need to check for noise - and will decouple the AD pin with extra RC network tomorrow now - to be sure.

I read the A-D every second or so, and it varies by a considerable amount. The following is a capture of 20 readings (which I then average out) :

0x000000d5
0x000000d7
0x000000d7
0x000000d7
0x000000ce
0x000000ec
0x000000d6
0x000000d4
0x000000e8
0x000000dc
0x000000df
0x000000df
0x000000e1
0x000000d7
0x000000de
0x000000d8
0x000000d7
0x000000d9
0x000000d8
0x000000d8

This is unusable !!

Now - I am trying to understand how the AnalogIn pin code works - and I suspect that its running continually in BURST mode ???, and not just when I call ‘Read()’ ??

The reason I suspect this is that having added some direct Register access code - the readings vary between two consecutive Register reads !! :


        private static Register PINSEL1 = new Register(0xE002C004);
        private static Register AD0CR = new Register(0xE0034000);
        private static Register AD0GDR = new Register(0xE0034004);
        private static Register AD0STAT = new Register(0xE0034030);
        private static Register AD0INTEN = new Register(0xE003400C);
        private static Register AD0DR0 = new Register(0xE0034010);
        private static Register AD0DR1 = new Register(0xE0034014);


Then in my method :

        public static void Read()
        {
            uint r2 = 0;

            uint r5 = AD0DR0.Read();
            AVolts[cnt] = adA.Read();
            r2 = AD0GDR.Read();
            r5 = AD0DR0.Read();
            r5 = AD0DR0.Read();
            r2 = r2 & 0x40000000;
            //if (r2 != 0)
            //    return;
            //BVolts[cnt] = adB.Read();
            r2 = AD0GDR.Read();
            r2 = r2 & 0x40000000;
            //if (r2 != 0)
            //    return;

            if (++cnt > 19)
                cnt = 0;
        }

cnt is a simple counter so that I can average over 20 counts.

The readings are often accompanied by the ADC OVERRUN bit being set in DR0 and also GDR.

Setting breakpoints in this code - I can see that the two consecutive register reads (int r5) actually give different values.

Also the CPU User Manual states that the Overrun bit will be cleared on a register read - but its not being.

Hence my ‘guess’ that the A-D is being continually read at a high rate ???.

If this is so - then I guess I will just have to implement my own simple A-D read function using register accesses :-((.

Finally - is there a circuit diagram available for the EMX module please ??. I want to know how VDDA and VREF are being fed into the CPU

ie do they have adequate decoupling etc. ???

Been trying to get to the bottom of this instability for a while now - on and off :-((.

Was also waiting to see if it had been changed/fixed in 4.2…but it seems that is still not yet available :-((.

Many Thanks

Best regards

Graham

try grounding the unused analog inputs

I will forward this to the right people to investigate.

Gus,

Thanks - if your guys can answer the design questions, this would be a great help ;-)).

Mike,

Can’t simply ‘ground’ most of these as they are allocated to other functions like Txd3/Rxd3, a couple of digital inputs (pulled up to 3v3 with a 10k series resistor), and USB functions.

I have checked the PINSEL regs however and none of these are set as AD0[x] pins.

One pin IS connected to +5V - that is Pin 26 UD_VBUS !!. I read somewhere that an A-D pin connected to > 3v3 can cause bad readings :-O.
So…if this really is a problem - what should UD_VBUS be connected to :open_mouth: (PINSEL0 = 0x417d4000 which is Pin26 = USB_PPWR2 ??).

NB Gus: I defined all 12 PINSET regs but the app barfs with an exception when the code runs (builds fine) :

#### Exception System.ArgumentException - 0xfd000000 (2) ####
#### Message: 
#### GHIElectronics.NETMF.Hardware.LowLevel.Register::.ctor [IP: 0000] ####
#### SBII_Emx_RevC.AtoD::.cctor [IP: 008a] ####

A first chance exception of type ‘System.ArgumentException’ occurred in GHIElectronics.NETMF.Hardware.dll
An unhandled exception of type ‘System.ArgumentException’ occurred in GHIElectronics.NETMF.Hardware.dll

When the code hits the REG10 line in the following code :


        private static Register PINSEL0 = new Register(0xE002C000);
        private static Register PINSEL1 = new Register(0xE002C004);
        private static Register PINSEL2 = new Register(0xE002C008);
        private static Register PINSEL3 = new Register(0xE002C00c);
        private static Register PINSEL4 = new Register(0xE002C010);
        private static Register PINSEL5 = new Register(0xE002C014);
        private static Register PINSEL6 = new Register(0xE002C018);
        private static Register PINSEL7 = new Register(0xE002C01c);
        private static Register PINSEL8 = new Register(0xE002C020);
        private static Register PINSEL9 = new Register(0xE002C024);
        private static Register PINSEL10 = new Register(0xE002C028); BARFS HERE!!
        private static Register PINSEL11 = new Register(0xE002C02c);


Comment out that line and REG11 defines OK :open_mouth: - no barf…

Thanks

Graham
NB The forum logged me out again…:-((
Luckily I copied my test to the clipboard BEFORE pressing submit.