This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

can mdk3.11 simulate the LPC2103 ADC interrupt?

device:LPC2103 Keil MDK 3.11 I want to control the sample speed with MAT0.3 in simulator,but I can't reach the interrupt subroutine and the ADC do not work at all! Thanks everyone read the message!

the following is my code:

*******************************************************
#include <lpc2103.h>

void InitADC(void); __irq void irq_adc (void) ;

void InitTimmer(void); __irq void irq_t0 (void) ;

int main(void)
{

InitADC(); InitTimmer(); while(1); return(0) ;
}

// T0.3
void InitADC(void)
{ // SEL CKDIV PDN START

int x=0x000000ff | 100<<8 | 1<<21 |5<<24 ;

ADCR = x;

ADINTEN=0X1FF;

PINSEL0 |= 3<<20 | 3<<22 | 3<<24;

PINSEL1 |=3<<12 | 3<<14 | 3<<16 | 3<<18 | 3<<20 ;

VICVectAddr1=(long)irq_adc ;

VICVectCntl1 |= 0x20 | 18; VICIntEnable |= 1<<18;

}

void InitTimmer(void)
{ T0MCR = 3<<9;//On match reset the counter and generate an interrupt

T0MR3 = 1500; //Set the cycle time

T0TCR = 0x00000001;//enable timer

VICVectAddr0=(long)irq_t0 ;

VICVectCntl0 = 0x20 |4; VICIntEnable|= 1<<4;

}

__irq void irq_adc (void) { int adc_channal;

adc_channal=ADSTAT & 0x00ff;

switch(adc_channal)

{ case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; } }

__irq void irq_t0 (void) { T0IR = 1; // Clear interrupt flag

VICVectAddr = 0; // Acknowledge Interrupt

switch(T0IR) { case 1:break; case 2 :break; case 4 :break; case 8 :break; case 0x10 :break; case 0x20 :break; case 0x40:break; case 0x80:break; }

}

Parents
  • You need to setup the External Match Control 0 to Toggle (T0EMR = 0x0C00) in order for External Match 0 (EM0 bit in T0EMR) to change and trigger the A/D.

    Current version of the simulator will however work only with Match Outputs that are actually connected to pins (MAT0.3 is not connected to a pin on LPC2103). This is fixed in the next release of MDK. Please contact support.intl@keil.com for an update.

    Next problem in your code is the A/D Converter IRQ routine which doesn't clear the A/D Interrupt flag which will lead to an endless IRQ. You need to clear the IRQ flag by reading the A/D Global Data register (ADGDR).

Reply
  • You need to setup the External Match Control 0 to Toggle (T0EMR = 0x0C00) in order for External Match 0 (EM0 bit in T0EMR) to change and trigger the A/D.

    Current version of the simulator will however work only with Match Outputs that are actually connected to pins (MAT0.3 is not connected to a pin on LPC2103). This is fixed in the next release of MDK. Please contact support.intl@keil.com for an update.

    Next problem in your code is the A/D Converter IRQ routine which doesn't clear the A/D Interrupt flag which will lead to an endless IRQ. You need to clear the IRQ flag by reading the A/D Global Data register (ADGDR).

Children