LPC1769 - Problem with Reading ADC

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

LPC1769 - Problem with Reading ADC

585 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by sukrubahadir on Fri Apr 01 07:34:50 MST 2016
Hello,
I want to interface with lpc1769's adc. I wrote following code and it does not working. I can't find problem.
I am using AD0.0 pin.

Please help me in this issue.
Thanks for your reply.
Here is my code :



#define CLKDIV 119

/**
 * @brief peripheral configuration
 */
typedef enum {PERIPH_DISABLE = 0, PERIPH_ENABLE = !PERIPH_DISABLE} PERIPH_MODE;
#define PARAM_PERIPHERAL_MODE(periph_mode) ((periph_mode == PERIPH_DISABLE) || (periph_mode == PERIPH_ENABLE))

/**
 * @brief clock config type definition
 */
typedef enum {CLK_4 = 0, CLK, CLK_2, CLK_8} PeripheralClock;
#define PARAM_PERIPHERALCLOCK(State) ((State == CLK_4) || (State == CLK) || (State == CLK_2) || (State == CLK_8))

/**
 * @brief adc mode type definition
 */
typedef enum {POWER_DOWN_MODE = 0, OPERATIONAL_MODE = !POWER_DOWN_MODE} Adc_Mode;
#define PARAM_ADCMODE(mode) ((mode == POWER_DOWN_MODE) || (mode == OPERATIONAL_MODE))

/**
 * @brief adc pin modes
 */
typedef enum {PULLUP = 0, REPEATER, NEITHER_PULLUP_NOR_PULLDOWN, PULLDOWN} Pin_Mode;
#define PARAM_PinMode(mode) ((mode == PULLUP) || (mode == REPEATER) || (mode == NEITHER_PULLUP_NOR_PULLDOWN) || (mode == PULLDOWN))

void ADC_IRQHandler(void){

uint32_t data = (LPC_ADC->DR[0] >> 4) & 0xFFF;
xprintf("data : %d \r\n", data);

}

void thermoController_adc_init(void){

// System Configuration for usign ADC.
LPC_SYSCTL->PCLKSEL[0] |= (CLK_8 << 24);// Clock for adc peripheral is (system clock / 8) ==> 12 MHz
LPC_SYSCTL->PCONP |= (PERIPH_ENABLE << 12); // Clock for adc peripheral enabled.

// ADC pin configuration
LPC_IOCON->PINSEL[1] |= (1 << 14); // AD0.0 is used as adc input.
LPC_IOCON->PINMODE[1] |= (NEITHER_PULLUP_NOR_PULLDOWN << 14); // AD0.0 pin has neither pull-up nor pull-down resistor.

// ADC Control Register Arrangement
uint32_t ControlRegister = 0x01;
ControlRegister |= (OPERATIONAL_MODE << 21); // PDN bit arrangement.
ControlRegister |= (CLKDIV << 8); // CLKDIV is 119 for producing clock at 100 kHz for ADC. By using this value one value is taken per 650 us.

LPC_ADC->CR = ControlRegister; // Update adc control register

// Interrupt Configuration
NVIC->IP[5] |= (32 << 19);
NVIC->ISER[0] |= (1 << 22);
LPC_ADC->INTEN |= (1 << 0);

ControlRegister |= (1 << 24); // Start Conversion now.

LPC_ADC->CR = ControlRegister; // Update adc control register for start conversion.

}

Labels (1)
0 Kudos
3 Replies

441 Views
rons
Contributor II

I would never use a xprintf from within a interrupt service routine. If this xprintf you are using

is from the standard library then you think about writing a mini-printf.

You are not resetting the NVIC pending bit in the interrupt routine.

0 Kudos

441 Views
lpcware
NXP Employee
NXP Employee
bump
0 Kudos

441 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by thedaz on Thu Apr 07 10:33:38 MST 2016
How does the system clock setup look like ? Did you try running this in a debugger ?
0 Kudos