adc

hello

I’m using the LPC2148 CodeBase v0.1 from microbuilder.eu (- j.c.wrens version adapted to crossworks from rowley).

For the project I extended the library for all 4 ADCs I need: AD0.1, AD0.2, AD1.6, AD1.7.

Everyone works fine, except the AD1.7 (posted below). First time through there is no problem, the second time it hangs in the ```
while (!(AD1_DR7 & AD_DR_DONE))


library

int adcInit1_7 (void)
{
// Force pin 0.22 to function as AD1.7
PCB_PINSEL1 = (PCB_PINSEL1 & ~PCB_PINSEL1_P022_MASK) | PCB_PINSEL1_P022_AD17;

// Enable power for ADC1
SCB_PCONP |= SCB_PCONP_PCAD1;

// Initialise ADC converter
AD1_CR = AD_CR_CLKS10 // 10-bit precision
| AD_CR_PDN // Exit power-down mode
| ((11 - 1) << AD_CR_CLKDIVSHIFT) // 4.36MHz Clock (48.0MHz / 11)
| AD_CR_SEL7; // Use channel 3
return 0;
}

int adcRead1_7 (void)
{
// Deselects all channels and stops all conversions
AD1_CR &= ~(AD_CR_START_MASK | AD_CR_SELMASK);

// Select channel 7
AD1_CR |= (AD_CR_START_NONE | AD_CR_SEL7);

// Manually start converting now (rather than waiting on an external input)
AD1_CR |= AD_CR_START_NOW;

// Wait for the conversion to complete
while (!(AD1_DR7 & AD_DR_DONE))
;

// Return the processed results
return ((AD1_DR7 & AD_DR_RESULTMASK) // Read bits 6…15 on AD1 data register 6 (which contains our conversion results)
>> AD_DR_RESULTSHIFT); // shift them to the end of a 32-bit value (giving us a 10-bit number)
}


any idea?

when I watch the registers I see in AD1GDR that CHN=7 and DONE=true. But in AD1DR7 the DONE Flag is removed, so I’ll never leave this … loop. That’s all I can say so far. No idea?

Although I haven’t seen issues with the DONE bit in ADGDR (as opposed to the DONE bit in the ADDRx registers) you may find the following two threads of interest. You may have stumbled across another ADC gotcha we haven’t seen yet.

http://mbed.org/forum/mbed/topic/1798/? … ment-10042

http://mbed.org/forum/mbed/topic/2003/? … ment-10104

hello,

thanks for these two. perhabs it’s something new.

your first link does refer to burst mode and frequencies greater than 8MHz but my configuration fits neither. Before I got your post I was expecting that the ADC-Channel could be smashed, so I took an other one. I’ve did four conversions in a row: first AD16, then two AD0-Channel conversions and at least the AD1.7 conversion. after the change from AD1.7 to AD1.1 it hangs at AD1.6. I do not have a clue what that could be. You cannot say it’s after three conversions…

Thank you for your hints

I will post as soon as I get new infos

The Logomatic from sparkfun does this quite a bit, you should have a look at the code as it also uses the LPC2148.