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
Please recheck your post. Your source code is very confusing, all commented out?
And please read this:
http://www.keil.com/forum/tips.asp
before you post something new.
SystemCoreClockUpdate()
void ADCInit( uint32_t ADC_Clk ) { /* Disable Power down bit to the ADC block. */ LPC_SYSCON->PDRUNCFG &= ~(0x1<<4); /* Enable AHB clock to the ADC. */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<13); LPC_IOCON->PIO0_23 &= ~0x9F; /* Clear bit7, change to analog mode. */ LPC_IOCON->PIO0_23 |= 0x01; /* 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) */ return; }
I believe that, most LPC11Uxx example codes on the Internet are for LPC11U1x/2x.
--
The LPC11U3x has a 10-bit ADC with a maximum 10-bit conversion rate of 400 kSamples/s. For LPC11U3x ADC, the analog voltage supply and ADC reference voltage shared with VDD.
The LPC11U6x has a 12-bit ADC with a maximum 12-bit conversion rate of 2 MSamples/s (VDD = 2.7 V to 3.6 V) or 1 MSamples/s (VDD = 2.4 V to 2.7 V). The LPC11U6x ADC uses dedicated pins for Analog voltage supply (VDDA) and ADC reference voltage (VREFP, VREFN). The A/D converter includes a built-in, hardware self-calibration mode. In order to achieve the specified ADC accuracy, the A/D converter must be recalibrated, at a minimum, following every chip reset before initiating normal ADC operation.
Hello,
thank you for response. I am also very sorry to miss out the source code format. Am publishing the code again. In an example that you have published I can see that the code is not for LPC11U68, because all ADC settings are made in CR and SEQA and SEQB are missing. Thank you for and further suggestions.
#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 pin PIO0_23 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); // Format the display string sprintf(cText, "%4d", ulVal); // Write ADC value to the LCD LCD_Write_string(&cText[0]); // Pause pause(); }
16.3.1 Perform a single ADC conversion using a software trigger
To perform a single ADC conversion for ADC0 channel 1 using the analog signal on pin ADC_1, follow these steps:
1. Enable the analog function ADC_1. 2. Configure the system clock to be 50 MHz and select a CLKDIV value of 0 for a sampling rate of 2 Msamples/s using the ADC CTRL register. 3. Select ADC channel 1 to perform the conversion by setting the CHANNELS bits to 0x2 in the SEQA_CTL register. 4. Set the TRIGPOL bit to 1 and the SEQA_ENA bit to 1 in the SEQA_CTRL register. 5. Set the START bit to 1 in the SEQA_CTRL register. 6. Read the RESULT bits in the DAT1 register for the conversion result.
TRIGPOL = bit 18 SEQA_ENA = bit 31 START = bit 26
TRIGPOL Select the polarity of the selected input trigger for this conversion sequence.
Remark: In order to avoid generating a spurious trigger, it is recommended writing to this field only when the SEQA_ENA bit (bit 31) is low. It is safe to change this field and set bit 31 in the same write.
thank you for an advice. Setting TRIGPOL bit to 1 really helped. I was reading the manual, but it was not clear to me why this bit should be used if we have software trigger. Ok, I will use this bit in a future. But I need to mention that also the result of the AD conversion is better in mean of oscillating if I have disconeted the debugger. Of course this happened by mistake :)
Thank you again for all advices!
Regards,