Yahoo Groups archive

Lpc2000

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

Thread

LPC2138 ADC interrupt problem

LPC2138 ADC interrupt problem

2006-04-23 by osaelhaggar

hi all,

i'm new in the group , but i hope i will be helpful with you & share 
my little knowledge with you.

well, i'm working on the OLIMEX LPC2138 evaluation board & ARM cross 
works compiler & debugger.
i'm working on implementing a Voice Over Wifi phone.

i want to run the ADC & get samples for the voice @8khz ,& i will put 
the samples in a frames to pass it for the compression code.

i have written a code for the ADC_0_ISR interrupt handler, but when i 
debug the code it never enters the ADC_0_ISR , to be known i 
configured the ADC0 to work at 88khz & in burst mode.

i choosed 88khz ,because it is said in the LPC2138 manual that each 
conversion takes 11 clks to get 10 bits.  am i doing write ?

at last here is the code that i tested :)
//////////////////////////////
#include "LPC213x.h"
#include <__armlib.h>

void init_ADC(void)
{
    PINSEL0 |= 0x00000300;  //  select pin0.4 as AD pin AD0.6
    PCONP   |= 0x00001000;  // enable the power to ADC.0
    AD0CR = 0x00214040;  //  configure the AD & run at 88Khz clk at 
                         //CLK_DIV = 40, @cclk = 14.475Mhz
}

int ADC_Data(void)   // i'm only scaning on channel 6 where the 
                    //     microphone is connected
{
    int data_sample ;
    int channel ;  // we work on channel 6  ,  AD0.6
    int value;
         value = AD0DR;
         channel = ((value >> 24 ) & 0x00000007);
         if (channel == 6)
            {
               data_sample = ((value >> 6 ) & 0x000003ff);
               return data_sample ;
            }
}

static void ADC_0_ISR(void) __attribute__ ((interrupt ("IRQ")));

int B1samples[160]={0}; // buffer1  for the sampled voice
int B2samples[160]={0}; // buffer2  for the sampled voice
int samplesCount;       // samples count for the sampled voice


static void ADC_0_ISR(void)  
{
     
  if (samplesCount <160 )
     {
       B1samples[samplesCount] = ADC_Data();
       samplesCount++;
     } 
  else if (160<=samplesCount <320 ) 
       { 
          B2samples[samplesCount] = ADC_Data();
          samplesCount++;
        }
  else
         { samplesCount = 0 ;
           B1samples[samplesCount] = ADC_data();
         }
  __ARMLIB_isrDisableIRQ();
 
  VICVectAddr = 0;   // Update VIC priorities
}

int main (void)
{
    PINSEL0 |= 0x00000300;  //  select pin0.4 as AD pin AD0.6
    int i,j;
    int sampleddata[160]={0};

  VICIntSelect &= ~0x4000;  // AD0 interrupt is an IRQ interrupt 
  VICIntEnable = 0x4000;   // Enable AD0 interrupt 
  VICVectCntl0 = 0x32;  // Use slot 0 for AD0 interrupt 
  VICVectAddr0 = (unsigned int)ADC_0_ISR;  // Set the address of ISR 
                                           //   for slot 0 

  __ARMLIB_enableIRQ();  // Enable Interrupts 
  __ARMLIB_isrEnableIRQ();  // enable the interrupts

  init_ADC();

      while(1)
      {   
         if (samplesCount ==159)
                for (i=0;i<160;i++) 
                  sampleddata[i] = B1samples[i]; // we will pass the 
                                                 //B1samples to encoder
         if (samplesCount ==159)
                for (j=0;j<160;j++)
                sampleddata[j] = B2samples[j]; // we will pass the 
                                               //B2samples to encoder
      }
}
///////////////////////

i really appreciate your help to spot the error & tell me what i have 
done wrong.

thanks all,

osama el haggar

Re: LPC2138 ADC interrupt problem

2006-04-24 by ghetto_shinobi

--- In lpc2000@yahoogroups.com, "osaelhaggar" <osamaelhaggar@...> wrote:
Hi
 VICIntSelect &= ~0x4000;  // AD0 interrupt is an IRQ interrupt 
 VICIntEnable = 0x4000;   // Enable AD0 interrupt 

Should be 0x00040000

Regards

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.