EmbDev.net

Forum: ARM programming with GCC/GNU tools ADC interrupt problem in LPC2138


Author: kamil bahadir (Guest)
Posted on:

Rate this post
0 useful
not useful
Hi!

I am using yagarto last ver. in my project. normaly if i use timer0 
interrupt in project, everything ok! timer0 is working.(the LED is 
blinking!!)
if i use two interrupt in system (timer0 and A/D0 ) the system is 
halting.
the code as below,

cpu: LPC2138
//---------------------------------------------------------
#define IRQ_MASK (~0x000000C0)

void tc0_IRQ(void) __attribute__((interrupt("IRQ")));
void adc0_IRQ(void) __attribute__((interrupt("IRQ")));
//-------------------------------------------------------------
/* ****************************************************** */

void EnableIRQ(void)
{
  _SET_CPSR(_GET_CPSR() & IRQ_MASK);

}
/******************************************************** */
static inline unsigned _GET_CPSR(void)
{
  unsigned long retCode;
  asm volatile (" mrs  %0, cpsr" : "=r" (retCode) : );
  return retCode;
}
/* ****************************************************** */
static inline void _SET_CPSR(unsigned value)
{
  asm volatile (" msr  cpsr, %0" : : "r" (value)  );
}
/* ****************************************************** */


void vectorinit (void)
{
#define VICVectCntl0_ENABLE (1<<5)
#define VIC_Channel_Timer0  4
#define VIC_Channel_adc0  18

    // setup timer0 for IRQ
  // set interrupt as IRQ
  VICIntSelect &= ~(1<<VIC_Channel_Timer0);
  VICIntEnable |=  (1<<VIC_Channel_Timer0);// Enable Timer0 Interrupt
  VICIntEnable |=  (1<<VIC_Channel_adc0);


  // assign VIC slot
  VICVectCntl0 = VICVectCntl0_ENABLE | VIC_Channel_Timer0;// use it for 
Timer 0 Interrupt
  VICVectCntl1 = VICVectCntl0_ENABLE | VIC_Channel_adc0;

  VICVectAddr0 = (unsigned long )tc0_IRQ;// set interrupt vector in  0
  VICVectAddr1 = (unsigned long )adc0_IRQ;// set interrupt vector in 1

  /* Enable interrupts */
  EnableIRQ();

}
****************************************************************

void adc0_IRQ (void)
{

#define VIC_Channel_adc  18

unsigned int r,ch;
     VICVectAddr = 0x00000000;       // clear this interrupt from the 
VIC
    //
    //------------------------------------------------------
  r = AD0DR; // Read Data Register and clear DONE flag
  ch = (r >> 24) & 0x07; // which channel was converted
  ADCresult0[ch] = (r>>6) & 0x03FF; // bit 6:15 is 10 bit AD value
:
:Some code in here....
}
/******************************************************* */
void tc0_IRQ (void)
{
:
:some code in here...
:

            VICVectAddr = 0x00000000;             // clear this 
interrupt from the VIC
     T0IR |= 0x00000001;
}
/**********************************************************/
 void init_adc0(unsigned char clk_div){

 PINSEL0 |= 0x00003C00; // P0.5, P0.6 setup for AD0.7, AD1.0
 PCONP |= 0x00001000;   /*Power on the A/D converter 0 */
                          // AD0CR = 0x00200604; // enable ADC, 11 
clocks/10 bits, ADC clock = 4.286MHz
   AD0CR = ( ((clk_div-1))<<8 ) | pdn_bit  ; /* | (1<<ch) configuerthe 
A/D control register of A/D 0  with clock = PCLK/(14+1) = 3.8Mhz
*/
  // power up
   AD0CR |= 0x00010000;    // start burst mode

}
//***************************************************************
//********************************************************************** 
******
int main(void)
{

some code.......

init_adc0(14); /*pass channel number and clkdiv*/
init_adc1(14);
:
:
:
:
}
------------------------------------------------------------------

Best regrads
kamil

Reply

Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]




Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.