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
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,