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

LPC11U68 ADC read value oscillates

Hi,

does anybody have an example code of using ADC of NXP LPC11U68? I have a very oscillating output even if I use battery supply or add additional capacitor. The filter capacitors on VREFP and VREPN are used as defined in Product datasheet. Besides how do I enable sequence B? If I try the same procedure as by sequence A nothing is converted. My code is below.

#define SETBIT(X, Y) (X |= 1 << Y)
#define CLEARBIT(X, Y) (X &= ~(1 << Y))

int main(void)
{ // Variables char cText[20]; unsigned long ulVal;

// System init targetInit();

// LCD init LCD_Init();

// SETTING OF ADC, channel 1 // Function 1 - ADC, channel 1 PIO0_23 = 1;

// Analog mode for pi CLEARBIT(PIO0_23,7);

// Enable CLK for ADC SYSAHBCLKCTRL |= 1 << 13;

// Enabling power for ADC, bit 4 to 0 CLEARBIT(PDRUNCFG,4);

// Autocalibration AD_Self_calibration();

// The conversion clock is equal to system clock AD_CTRL &= ~(0x000000ff);

// In sequence A set to sample channel 1 SETBIT(AD_SEQA_CTRL,1);

// Enable sequence A SETBIT(AD_SEQA_CTRL,31);

// First line of LCD LCD_Write_string(" AD value ");

// Cursor to second line LCD_Set_position(2,1);

// Second line of LCD LCD_Write_string(" U = 0000 mV ");

while(1) { // Start of conversion AD_SEQA_CTRL |= (1<<26);

// Waiting to finish conversion while(CHECKBIT(AD_DAT1,31)==0);

// Reading DAT register ulVal = AD_DAT1;

// Extrude the proper value ulVal = (ulVal >> 4);

// Extrude the proper value ulVal = ulVal & 0x0FFF;

// Calculation ADC value in mV ulVal = 1000*VREF*ulVal/4095;

// Cursor to second line LCD_Set_position(2,8);

// Formet the display sprintf(cText, "%4d", ulVal);

// Write ADC value to LCD LCD_Write_string(&cText[0]);

// Pavza pause(); }

Thank you for helping!

Jure

Parents Reply Children