LPC11E14 ADC problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC11E14 ADC problems

227 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by bac87 on Sun Sep 27 06:54:56 MST 2015
Hello,

In my project I want to read voltage level on battery and on NTC thermistor. The ACDs are showing me some value which is not right, both ADC inputs have different voltage but they measure the same value. The ADC is measuring something but I don't know what, it could be linked to temperature because is shifting up and down.

I build my code from LPC11A14 ADC example the registers are not identical but I have make some adjustments. I really don't know where I have missed.

This is my code:
/*
* Function: ADCInit()
* Discription:Init ADC
* Parameters:
*/

void ADCInit(void){
/* Disable Power down bit to the ADC block. */
  LPC_SYSCON->PDRUNCFG &= ~(0x1<<4);

// LPC_SYSCON->PRESETCTRL |= (0x1<<11);
  /* Enable AHB clock to the ADC. */
  LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13);



  LPC_IOCON->TRST_PIO0_14 &= ~0x9F;  /* Clear bit7, change to analog mode. */
  LPC_IOCON->TRST_PIO0_14 |= 0x02;  /* ADC IN3 */


  LPC_IOCON->PIO0_23   &= ~0x9F; /* Clear bit7, change to analog mode. */
  LPC_IOCON->PIO0_23   |= 0x02;  /* ADC IN7 */





  LPC_ADC->CR = ( 0x01 << 0 ) |  /* SEL=1,select channel 0~7 on ADC0 */
( ( SystemCoreClock / ADC_Clk - 1 ) << 8 ) |  /* CLKDIV = Fpclk / 1000000 - 1 */
( 0 << 16 ) | /* BURST = 0, no BURST, software controlled */
( 0 << 17 ) |  /* CLKS = 0, 11 clocks/10 bits */
( 0 << 24 ) |  /* START = 0 A/D conversion stops */
( 0 << 27 );/* EDGE = 0 (CAP/MAT singal falling,trigger A/D conversion) */

}
//***************end function ADCInit *******************************************

/*
* Function: GetADCValue()
* Discription:Get ADC Value
* Parameters:channelNum
*/
uint32_t GetADCValue(uint8_t channelNum)
{
volatile uint32_t ADCValue;

  LPC_ADC->CR &= 0xFFFFFF00;   //Mask CR
  LPC_ADC->CR |= (1 << 24) | (1 << channelNum); // //Start conversion now,  SEL ADC
  ADCValue= ( LPC_ADC->DR[channelNum] >> 3 ) & 0x3FF;
  /*[channelNum]*/

  return ADCValue;


}
//***************end function GetADCValue *******************************************





Thank you for help,


Regards,


Blaz



Labels (1)
0 Kudos
0 Replies