Reply by Robert Adsett May 14, 20082008-05-14
At 09:44 AM 5/14/2008 +0000, r.jensenm wrote:
>Hi guys,
>
>I have tried to setup a software controlled AD conversion for ch 0-5
>but I only read 0x3FF from the result registers??
>
>Below is part of my code. First adc_init is called once then adc_run
>is called forever. While stepping through the code with debugger I
>can see that each channels result register is updated but no mather
>what I apply to the adc input I get a 100% reading??
>
>Can anyone point out to me howcome?

For a start you don't actually appear to read the A/D anywhere.

Robert

http://www.aeolusdevelopment.com/

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live.... we
currently have stock."

An Engineer's Guide to the LPC2100 Series

Reply by "r.jensenm" May 14, 20082008-05-14
Hi guys,

I have tried to setup a software controlled AD conversion for ch 0-5
but I only read 0x3FF from the result registers??

Below is part of my code. First adc_init is called once then adc_run
is called forever. While stepping through the code with debugger I
can see that each channels result register is updated but no mather
what I apply to the adc input I get a 100% reading??

Can anyone point out to me howcome?

Regards Michael

#define ADC_start AD0CR |= 0x1000000;

uchar adc_conversion_done(void)
{
if ((AD0GDR & 0x80000000) == 0x80000000) // if conversion ready
return true;
else
return false;
}

void adc_init(void)
{
uchar i;
// power Control register for various peripherals
// at reset its default zero - nedd to be set to enable power to
A/D
PCONP |= 0x1000;
// ADC Clock frequency: 200 kHz
// ADC No burst mode
// ADC AD power enable
AD0CR = 0x20C700;
adc_index = 1;
adc_channel = 1;
AD0CR |= adc_index; // vg A/D kanal
ADC_start; // start A/D konvertering
//adc_run();
}

void adc_run(void)
{
if (adc_conversion_done() == true) { // hvis A/D konvertering er
//adc_data[adc_channel] = AD0GDR;//(AD0GDR & 0xFF00) >> 8;
if (++adc_channel > 6) {
adc_channel = 1;
adc_index = 1;
}
else
adc_index *= 2;
AD0CR &= 0xFFFFFF00; // slet tidligere valgt kanal
AD0CR |= adc_index; // vg ny A/D kanal
ADC_start; // start A/D konvertering
}
else
adc_index = adc_index;
}