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

LPC1768 two pin ADC

Hi 

I want to read two pin of ADC in LPC1768, AD0.0 and AD0.1 


AD0.0 is on pin P0.23 
AD0.1 is on pin P0.24

I can read from AD0.0 but I can't read from AD0.1.

please help me abut it.

this is my code:

/*(C) Umang Gajera - www.ocfreaks.com
LPC1768/LPC1769 ADC Interfacing Example 1 Source Code using KEIL ARM
More Embedded tutorials @ www.ocfreaks.com/cat/embedded/
License : GPL.*/

#include <lpc17xx.h>
#include <stdio.h>


#define VREF 3.3 //Reference Voltage at VREFP pin, given VREFN = 0V(GND)
#define ADC_CLK_EN (1<<12)
#define SEL_AD0_0 (1<<0) //Select Channel AD0.0
#define SEL_AD0_1 (1<<1) //Select Channel AD0.1
#define CLKDIV 1 //ADC clock-divider (ADC_CLOCK=PCLK/CLKDIV+1) = 12.5Mhz @ 25Mhz PCLK
#define PWRUP (1<<21) //setting it to 0 will power it down
#define START_CNV (1<<24) //001 for starting the conversion immediately
#define ADC_DONE (1U<<31) //define it as unsigned value or compiler will throw #61-D warning
#define ADCR_SETUP_SCM ((CLKDIV<<8) | PWRUP)

int result1 = 0;
float volts1 = 0;
int result2 = 0;
float volts2 = 0;
int main(void)
{
    //SystemInit(); //Gets called by Startup code, sets CCLK=100Mhz, PCLK=25Mhz
    LPC_GPIO0->FIODIR |= (1<<10);
    
    LPC_SC->PCONP |= ADC_CLK_EN; //Enable ADC clock
    LPC_ADC->ADCR = ADCR_SETUP_SCM | SEL_AD0_0 | SEL_AD0_1;
    LPC_PINCON->PINSEL1 = (1<<14); //select AD0.0 for P0.23 and select AD0.1 for P0.24
    LPC_PINCON->PINSEL1|= 0x01<<16; /* Select the P0_24 AD0[1] for ADC function */
    LPC_PINCON->PINSEL1|= 0x01<<17; /* Select the P0_24 AD0[1] for ADC function */
    
    
    
    while(1)
    {
        LPC_ADC->ADCR |= START_CNV; //Start new Conversion
        
        while((LPC_ADC->ADDR0 & ADC_DONE) == 0); //Wait untill conversion is finished
        
        result1 = (LPC_ADC->ADDR0>>4) & 0xFFF; //12 bit Mask to extract result
        
        volts1 = (result1*VREF)/4096.0; //Convert result to Voltage
        if(volts1>2)
        {
            LPC_GPIO0->FIOSET |= (1<<10); // Output HIGH
        }
        if(volts1<1)
        {
            LPC_GPIO0->FIOCLR |= (1<<10); // Output HIGH
        }
        
        
        while((LPC_ADC->ADDR1 & ADC_DONE) == 0); //Wait untill conversion is finished
        
        result2 = (LPC_ADC->ADDR1>>4) & 0xFFF; //12 bit Mask to extract result
        
        volts2 = (result2*VREF)/4096.0; //Convert result to Voltage
        if(volts2>2)
        {
            LPC_GPIO0->FIOSET |= (1<<10); // Output HIGH
        }
        if(volts2<1)
        {
            LPC_GPIO0->FIOCLR |= (1<<10); // Output HIGH
        }
        
        
        
    }


}