lpcware

ADC problem on lpc1769

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by karanmehta93 on Tue Jan 01 11:27:01 MST 2013

#include<LPC17xx.h> //Always Put this header file on the top of the code else u will get errors
#include"LPC17xx_1.h"

#include"PLL.h"
#include"NVIC.h"

#include"ADC.h"

int GetADC(int channel)
{
PCONP |= 0x00001000;
int adc_clkdiv;

switch (channel){

case Adc0:
PINSEL1 &= ~0x0000C000;
PINSEL1 |=  0x00004000;
break;
case Adc1:
PINSEL1 &= ~0x00030000;
PINSEL1 |=  0x00010000;
break;
case Adc2:
      PINSEL1 &= ~0x000C0000;
PINSEL1 |=  0x00040000;
     break;
case Adc3:
    PINSEL1 &= ~0x00300000;
PINSEL1 |=  0x00100000;
     break;
case Adc4:
PINSEL3 &= ~0x30000000;
PINSEL3 |=  0x30000000;
break;
case Adc5:
PINSEL3 &= ~0xC0000000;
PINSEL3 |=  0xC000000;
break;
case Adc6:
PINSEL0 &= ~0x00000030;
PINSEL0 |=  0x00000020;
break;
case Adc7:
PINSEL0 &= ~0x000000C0;
PINSEL0 |=  0x00000080;
break;
}

adc_clkdiv = 4;
AD0CR = 1<<channel;
AD0CR |= adc_clkdiv<<8 | 1<<16 | 1<<21;
waitus(100);
int addr,ADCval=0;
switch (channel){

case Adc0:
addr  = AD0DR0;
if(addr & 0x80000000)
ADCval=((addr & 0x0000FFF0)>>4);
break;
case Adc1:
addr = AD0DR1;
if(addr & 0x80000000)
ADCval=((addr & 0x0000FFF0)>>4);
  break; 
case Adc2:
addr  = AD0DR2;
if(addr & 0x80000000)
ADCval=((addr & 0x0000FFF0)>>4);
  break;
case Adc3:
addr  = AD0DR3;
if(addr & 0x80000000)
    ADCval=((addr & 0x0000FFF0)>>4);
break;
case Adc4:
addr  = AD0DR4;
if(addr & 0x80000000)
   ADCval=((addr & 0x0000FFF0)>>4);
break;
case Adc5:
addr  = AD0DR5;
if(addr & 0x80000000)
    ADCval=((addr & 0x0000FFF0)>>4);
break;
case Adc6:
addr  = AD0DR6;
if(addr & 0x80000000)
ADCval=((addr & 0x0000FFF0)>>4);
break;
case Adc7:
addr  = AD0DR7;
if(addr & 0x80000000)
ADCval=((addr & 0x0000FFF0)>>4);
break;
}
AD0CR = 0x01;
return ADCval;
}

Following is my code for ADC conversion. It works for all channels except 5 and 6.
I have checked for all types of hardware problems and haven't found any.
Please help urgently.

Outcomes