This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

LPC 2148 ADC

Hii all.This time I'm struck with the ADC problem.My code is running successfully.I'm using a ready-made board of LPC2148 which has a potentiometer connected with its pin 13 of the MCU i.e., AD0.1.The potentiometer is used to supply various analog voltage to the pin 13.
Now the problems are --
1:->the result of the ADC conversion of a predefined voltage is not coming in the AD0DR1 register..but its coming in the global result register i.e., in the AD0GDR.
I dont know why this is happening
2:->I'm sending the result of ADC conversion to P1.16 to P1.23 which has LED connection to it..and the pattern of LED blinking is rightfully going with the ADC result.If i power up the development board with a predefined analog volatage(say 2V) the result is coming accordingly..but now if i change the value of the potentiometer(say to 3V) then the new result isn't coming..and the result of 2V continues to blink at the LEDs.If I reset the board or switch on the board after switching it off then the right value of 3V is showing up..what should i do

  • I'm posting the part of my code which handles the above functions.the GPIOInit() function below makes the LEDs to blink as well as checks for any new data in the Global Data Register.As well as the ADC_initialization code is also given below
    Pclk -> 60MHz
    VPBCLK -> 60MHz
    ADCCLK -> 4MHz.
    ADC initializaion code--

    void init_ADC_mod()
    {
                            // Initial ADC8 (ADCR=0x01210601)
    
            PINSEL0 |= 0x01000000;               // Select AD0.1 Pin Connect to pin13
            AD0CR   &= 0x00000000;           // Clear All Bit Control
            AD0CR   |= 0x00000002;           // Select ADC = AD0.1 rest all are treated as simple GPIO
            AD0CR   |= 0x00000E00;           // ADC Clock = VBP(PCLK) / 15(=14+1) = 4MHz
            AD0CR   |= 0x00000000;           // No Busrt..i.e., Burst=0...soft-ware controlled
            AD0CR   &= 0xFFF1FFFF;           // CLKS = 000 = 10Bit : 11 Cycle Clock Conversion
            AD0CR   |= 0x00200000;           // PDN = 1 = Active ADC Module
            AD0CR   &= 0xFF3FFFFF;           // TEST[1:0] = 00 = Normal Mode
            AD0CR   &= 0xF7FFFFFF;           // EDGE = 0 = Conversion on Falling Edge
            AD0CR   |= 0x01000000;           // START = 001 = Start Conversion Now
    
    }
    


    GPIOInit() function --

    void GPIOInit( DWORD PortType,DWORD ADC_DATA)
    {
            DWORD DATA;
            PortType=0;
    
                    SCS = 0;                        /* set GPIOx to use regular I/O */
                    IODIR1 = 0x00FF0000;    /* P1.16..23 defined as Outputs..while the rest are input */
                    //      IOSET1 = ADC_DATA;              // the first byte of the data is sent to the o/p
                    while(1)
                    {
                            IOPIN1 = 0x00000000;
                            IOCLR1 = 0x00FF0000;            /* turn off LEDs */
                            delay();
                            DATA = ADC_DATA;                //      ADC_DATA_LAST = (ADC_DATA>>8) & 0x00030000;
                            DATA = (DATA<<16) & 0x03FF0000; // only the 10 result bit remains
                            IOSET1 = DATA;
                            delay();
                            IOCLR1 = 0x00FF0000;
                            delay();
                            DATA = (DATA>>8) & 0x00FF0000;
                            IOSET1 = DATA;
                            delay();
                            value1=AD0GDR;  // the next value of ADC(if the i/p has changed already) is stored in value1
                            if(value1!=ADC_DATA) // this is checked with the previous value stored in ADC_DATA
                            {
                                    //      if(value1 & 0x0000FFC0)
                                            ADC_DATA=value1;        // if they are unequal ADC_DATA gets the new value.
                            }
        }
        return;
    }
    

  • Another thing guys i just checked that the converted bit pattern for a given value is also not coming rite.
    My voltage reference is 3.45V
    so the step size for 10 bit ADC should be
    0.003369140V = 3.4mV(approx)
    On supply of 3V the value should come
    3/step size = 3/3.4mV = 882.35 = 882(approx)=0x1101110010(in binary).
    but my output is coming something different....and frustating of all ia that for constant analog input 3V supply the corresponding value coming is aometimes 960 or 576 or 704.......
    Now what to do..

  • I have checked the reading in the simulator.The AD0GDR reading is 0x0100E880 i.e., the result is 0x03A2..but according to my calculation it should come 0x0372..

  • Have you verified that all your voltages are perfectly stable?

    Is the voltage reference in range, with regard to the supply power to the processor?

  • Have you verified that all your voltages are perfectly stable?

    Is the voltage reference in range, with regard to the supply power to the processor?

  • Yes my reference voltage is internal and it is equal to Vcc=3.45V..and I have checked it.

    But the major problem I'm facing now is that even the output value for a constant analog supply say 3v is not coming steadily.What I'm saying is that I have read the ADC output value from ADODR1 register and projecting it via the LEDs connected to P1.16-P1.23...but each time I'm powering up the board or resetting the board I'm getting different values and that too everyone is wrong...I dont know wat is happening

  • This really sounds like a noisy power supply. Not just the reference supply but the board supply.
    Also, try to ensure that you do very limited bit switching (LEDS, etc.) while doing an ADC convert.
    Good luck.
    Bradford

  • We are still waiting for any answer to this:
    "Have you verified that all your voltages are perfectly stable?"

    Whenever an ADC produce weird measurements, the first thing to do is to grab the oscilloscope and look at all relevant signals. If the measured signal isn't stable, in relation to the speed of the ADC, your ADC will have problems. If the reference voltage isn't stable, your ADC will have problems. If the VCC isn't stable, your ADC will have problems. If the GND isn't stable, your ADC will have problems. If other signals to an external ADC or the processor does funny things (such as an output switching high currents or an input receiving an overvoltage into the body diodes), your ADC will have problems. If the input signal can't handle the load of the ADC input, your ADC will have problems. If the processor runs at max load, the switching of all internal transistors may give the ADC problems. You get the idea? Almost anything can result in bad ADC readings, so you really have to check that everything is ok. The external signals are easy to look at. If that isn't enough, then it will be time to try to do something about noise from inside the processor.

    The first six or maybe eight bits of the ADC output are relatively easy to get to produce reasonable values. But every extra bit will be harder.

  • Yes i have checked my board..my reference voltage is not being constant.It increases when I increase the supply voltage to the board.For example when the supply voltage is 4.8V the reference voltage becomes 3.3V which changes to 3.5V when the supply voltage to the board becomes 5.1V or 5.06V.
    As (the voltage input to the microcontroller)Vcc=Vref so that also change in accordance to the supply voltage.
    Now what should I do..
    P.S. I'm sorry for the delay in providing the data.

  • Sounds like you have measured the signal with a multimeter.

    Have you also checked it with an oscilloscope and seen if it - besides changing value with the input voltage - also has noise?

    For the DC problem, you normally buy a dedicated voltage reference. You could see it as a "super-zener". You may get a 2.0V, 2.048V or maybe a 2.5V voltage reference.

    The next thing is that you may look at using capacitors and inductors to filter away noise.

    Having a voltage reference with a lower voltage than what you want to mesure would mean that you need to add a voltage divider to make sure that the input voltage is within range. Big enough resistance values that they don't load down the voltage source. But low enough resistance that the input impedance of the ADC doesn't affect the divider significantly.

  • Yeah sir u r rite...i have used a multimeter to chck teh values...

    LPC2148 has internal voltage reference..so whats the use of a dedicated external sorce..and moreover how to use it.I'l check it using the oscilloscope and let u knw about the noise part

  • "LPC2148 has internal voltage reference..so whats the use of a dedicated external sorce..and moreover how to use it."

    What do you mean by that?

    The 2148 has Vref, Vssa, Vdda signals.

    Vssa: Analog Ground: 0 V reference. This should nominally be the same voltage as VSS, but should be isolated to minimize noise and error.

    Vdda: Analog 3.3 V Power Supply: This should be nominally the same voltage as VDD but should be isolated to minimize noise and error. This voltage is used to power the ADC(s).

    Vref: A/D Converter Reference: This should be nominally the same voltage as VDD but should be isolated to minimize noise and error. Level on this pin is used as a reference for A/D convertor.

    The only bad thing is that NXP seems to have a hard time to decide what voltages that are allowed on Vref.

    6.8.1 of product datasheet (Rev 04 17 nov 2008) says:
    Measurement range of 0 V to VREF (2.0 V <= VREF <= VDDA).

    8 of product datasheet says:
    Min 2.5V, Typical 3.3V, Max Vdda

  • yeah u r rite what i mean to say is that in my development board the Vref pin is internally connected with Vcc

  • One thing you have not told us before, is that you are using a development board. Or more explicitly which board. But now we know that it isn't a Keil MCB2140.

  • I have said that I'm using a board in my very first posting..i guess u missed it.Its from robokits a cmpany from rajasthan(india) and its written in their website about the board that...Designed as per keil MCB2130 dropping some features.

    I have checked the connection with the oscilloscope there are some noise signal creeping into the ADC pin.