Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: [lpc2000] A/D converter: a conversion is never completed

2005-11-10 by Tom Walsh

Gromann, Klaus wrote:

>Hi Joerg,
>
>you have set the BURST-bit (0x00010000)in the ADCR. I never tried this
>but the manual says that if this bit is set the ADC does repeated
>conversions at a rate defined by the CLKS bits (000 = 11 clock cycles).
>I think that the DONE bit will be never set in this mode.
>
>Second suggestion : Try to set the START bits to "start conversion now"
>(001) by your code to see if the interrupt handler works as you want. I
>use this mode and do a polling of the DONE bit and everything works
>  
>
This is my ADC routines on the LPC2138:

============ begin setup ===============
void initADC(void)
{ // setup converter to run continuously.
      // connect VIC to A/D Convertor.
   VICVectAddr1 = (uint32_t)adc0ISR;    // address of the ISR
   VICVectCntl1 = VIC_ENABLE | VIC_ADC0;
   VICIntSelect &= ~VIC_BIT(VIC_ADC0);  // ADC0 selected as IRQ
   VICIntEnable = VIC_BIT(VIC_ADC0);    // ADC0 interrupt enabled
      // set pins for AD0.0 .. AD0.3 to A/D function.
   PINSEL1 = (PINSEL1 & 0xc03fffff) | (0x15400000);
      // accuracy to 10bits.
   adcSetValue = (
      (ADC_CHN_0 | ADC_CHN_1 | ADC_CHN_2 | ADC_CHN_3) |
      (ADC_CLK_DIVISOR(14)) |    /* approx 4.2MHz conversion rate. */
      (ADC_BURST_ON) |        /* run continuously. */
      (ADC_RESOLVE_10) |      /* 10 bit resolution. */
      (ADC_POWER_ON) |        /* enabled. */
      (ADC_START_0)) &        /* no, we are bursting. */
      (~ADC_RESERVED_CONTROL_BITS); /* write 0's to reserverd bits. */
   ADCR0 = adcSetValue;
}
============ snip ================


=========== begin ISR ==============
unsigned int adcData [4];

void adc0ISR(void)
{// keep continuous update of A/D pin values.
unsigned int temp;
   temp = ADDR0;     // read conversion info.
   switch (ADC_CHANNEL(temp)) {
      case 0:
         adcData[0] = ADC_VALUE(temp);
         break;
      case 1:
         adcData[1] = ADC_VALUE(temp);
         break;
      case 2:
         adcData[2] = ADC_VALUE(temp);
         break;
      case 3:
         adcData[3] = ADC_VALUE(temp);
         break;
      default:    // do nothing on overranges.
         break;
   }
   VICVectAddr = 0x00000000;             // clear this interrupt from 
the VIC
}
=========== snip =================

=========== begin Macros ===========
#define  ADC_VALUE_MASK    (0x0000ffc0)
#define  ADC_VALUE(A)      ((A >> 6) & 0x3ff)
#define  ADC_CHANNEL_MASK  (0x07000000)
#define  ADC_CHANNEL(A)    ((A >> 24) & 0x7)
#define  ADC_OVERRUN_MASK  (0x40000000)
#define  ADC_DONE_MASK     (0x80000000)

============ snip ================

Hope this helps.

TomW

-- 
Tom Walsh - WN3L - Embedded Systems Consultant
http://openhardware.net, http://cyberiansoftware.com
"Windows? No thanks, I have work to do..."
----------------------------------------------------

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.