Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Interrupts in LPC2148

Status
Not open for further replies.

mjanani

Newbie level 2
Joined
Feb 12, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,312
Hi friends...i am doing project in LPC2148 series....i need to generate an interrupt for every 1sec...timer is working but the interrupt is not working..i.e., it is matched with vectored address...the interrupt is not being serviced...can anyone help me and say whats the mistake in my code..........

Here is the code:

#include<LPC214x.H>
void init_PLL(void);
void T0isr(void) __irq;
void T1isr(void) __irq;
float sine[71]={0.0,0.109,0.216,0.317,0.411,0.494,0.566,0.623,0.665,0.691,0.7,0.691,0.665,0.623,0.566,0.494,0.411,0.317,0.216,0.109,0.0,-0.109,-0.216,-0.317,-0.411,-0.494,-0.566,-0.623,-0.665,-0.691,-0.7,-0.691,-0.665,-0.623,-0.566,-0.494,-0.411,-0.317,-0.216,-0.109,0.0,0.109,0.216,0.317,0.411,0.494,0.566,0.623,0.665,0.691,0.7,0.691,0.665,0.623,0.566,0.494,0.411,0.317,0.216,0.109,0.0,-0.109,-0.216,-0.317,-0.411,-0.494,-0.566,-0.623,-0.665,-0.691,-0.7};
float a,b,c,t,x=0.01,incoper=0.01;
int i=0,flag=0,j,k,m,n,p,slope=5;
int main(void)
{
init_PLL();
IO1DIR=0x00FF0000;
//IO1SET=0x00030000;
T0IR=0x00000000;
T0PR=0x0000001E;
T0TCR=0x00000000;
T0MCR=0x00000003;
T0MR0=500;
T0TCR=0x00000001;
VICVectAddr4=(unsigned)T0isr;
VICVectCntl4=0x00000014;
T1IR=0x00000000;
T1PR=0x0000001E;
T1TCR=0x00000000;
T1MCR=0x00000003;
T1MR0=2;
T1TCR=0x00000001;
VICVectCntl0 = 0x0000002F;
VICVectAddr0 = (unsigned)T1isr;
VICIntEnable |=0x00000010;
//VICIntSelect=0xFFFFFFCF;
while(1)
{
if(i<20)
{
if(a<=t)
{
IO1SET=0x00010000;//m=1;
IO1CLR=0x00020000;
}
else
{
IO1CLR=0x00010000;
IO1SET=0x00020000;//m=0;
}
}
else
{
if(a>=t)
{
IO1SET=0x00010000;//m=1;
IO1CLR=0x00020000;
}
else
{
IO1CLR=0x00010000;
IO1SET=0x00020000;//m=0;
}
}
if(j<20&&j>40)
{
if(b<=t)
{
IO1CLR=0x00080000;
IO1SET=0x00040000;
//n=1;
}
else
{
IO1CLR=0x00040000;
IO1SET=0x00080000;
//n=0;
}
}
else
{
if(b>t)
{
//n=1;
IO1CLR=0x00080000;
IO1SET=0x00040000;
}
else
{
//n=o;
IO1CLR=0x00040000;
IO1SET=0x00080000;
}
}
if(k>40&&k<60)
{
if(c<=t)
{
//p=1;
IO1CLR=0x00200000;
IO1SET=0x00100000;
}
else
{
IO1CLR=0x00100000;
IO1SET=0x00200000;
//p=0;
}
}
else
{
if(c>t)
{
//p=1;
IO1CLR=0x00200000;
IO1SET=0x00100000;
}
else
{
//p=0;
IO1CLR=0x00100000;
IO1SET=0x00200000;
}
}
}
}

void T0isr(void) __irq
{
IO1SET=0x00800000;
i++;
j=i+13;
k=i+27;
a=sine;
b=sine[j];
c=sine[k];
if(i>40)
i=0;
T0IR |=0x00000001;
VICVectAddr=0x00000000;
}

void T1isr(void) __irq
{
t=slope*x;
IO1SET=0x00400000;
x=x+incoper;
flag++;
if((t<-4.9)&&(flag>48))
{
incoper=-1*incoper;
flag=0;
}
if((t>4.9)&&(flag>48))
{
incoper=-1*incoper;
flag=0;
}
VICVectAddr=0x00000000;
}
void init_PLL(void)
{
PLL0CFG=0X00000024;
PLL0CON=0X00000001;
PLL0FEED=0X0000000AA;
PLL0FEED=0X00000055;
while(!(PLL0STAT&0X00000400));
PLL0CON=0X00000003;
PLL0FEED=0X000000AA;
PLL0FEED=0X00000055;
VPBDIV=0X00000002;
}
 

try this

---------- Post added at 22:37 ---------- Previous post was at 22:34 ----------

[/COLOR]try this

#include "LPC214x.h"
#define PLOCK 0x400
void init(void);

void IRQ_Routine(void) __attribute__ ((interrupt ("IRQ")));
void FIQ_Routine (void) __attribute__ ((interrupt("FIQ")));
void SWI_Routine (void) __attribute__ ((interrupt("SWI")));
void UNDEF_Routine (void) __attribute__ ((interrupt("UNDEF")));

int main(void)
{
int i;
IODIR0 = 0x30600000;
IOCLR0 = 0x30600000; //LEDs off
init();
T0MCR = 0x0003; //interrupt and reset on MR0
T0MR0 = 0x00ffffff; //compare-hit count
T0TCR |= 0x01; //enable Timer0
T0TCR |= 0x02; //reset counter

VICVectAddr0 = (unsigned long)&IRQ_Routine; //set interrupt vector in 0
//or
//VICVectAddr0 = (unsigned long)IRQ_Routine; //set interrupt vector in 0
VICVectCntl0 = 0x00000024; //use it for Timer 0 Interrupt
VICIntSelect = 0x00000000; //Configure for IRQ
VICIntEnable = 0x00000010; //enable TIMER0 interrupt

while(1);
}

void IRQ_Routine(void)
{
int i;
IOSET0 = 0x30600000; //4 LEDs blink
for(i=0;i<0x0000ffff;i++);
IOCLR0 = 0x30600000;
T0IR = 0x01; //clear interrupt
VICVectAddr0 = 0; //end of interrupt - dummy write
}

void init(void)
{
PLLCFG=0x24; //set multiplier/divider values
PLLFEED=0xaa;
PLLFEED=0x55;
PLLCON=0x01; //enable PLL
PLLFEED=0xaa;
PLLFEED=0x55;
while(!(PLLSTAT & PLOCK)); //wait for the PLL to lock to set frequency
PLLCON=0x3; //connect the PLL as the clock source
PLLFEED=0xaa;
PLLFEED=0x55;
MAMCR=0x02; //enable MAM
MAMTIM=0x04; //set number of clocks for flash memory fetch
VPBDIV=0x01; //set peripheral clock(pclk) to system clock(cclk)
}

void FIQ_Routine(void){
while (1) ;
}
void SWI_Routine(void){
while (1) ;
}
void UNDEF_Routine(void) {
while (1) ;
}

---------- Post added at 22:41 ---------- Previous post was at 22:41 ----------

http://infocenter.arm.com/help/topic/com.arm.doc.ddi0181e/DDI0181.pdf
 

Thank you sir..your reply was useful..again the problem is that as there are two interrupts, only one interrupt vector(IRQ) is working...timer 1 interrupt is a problem...can you suggest me a solution.....
 

This is your code for timer0 interrupt
Code:
VICVectAddr4=(unsigned)T0isr;
VICVectCntl4=0x00000014;

0x14 is for EINT0, you should use 0x24 to enable interrupt and use TIMER0
Code:
VICVectAddr4=(unsigned)T0isr;
VICVectCntl4=0x000000[COLOR="red"][B]2[/B][/COLOR]4;

Also in the other interrupt
Code:
VICVectCntl0 = 0x0000002F;
VICVectAddr0 = (unsigned)T1isr;

0x2F is for EINT1, you should use 0x25 for TIMER1
Code:
VICVectCntl0 = 0x0000002[COLOR="red"][B]5[/B][/COLOR];
VICVectAddr0 = (unsigned)T1isr;

Also at the end of the T1isr you should also add
Code:
T1IR |=0x00000001; // to clear the TIMER1 interrupt flag

You should remove VICIntEnable |=0x00000010;, you have no fast IRQ (both are vectored interrupt) in your code so don't change TIMER1 to FIQ.

one more note, I'm not sure if unsigned is the same as unsigned long , if not you should use VICVectAddr = (unsigned long)function;

Alex
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top