Yahoo Groups archive

Lpc2000

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

Thread

Timer Interrupt on Crossworks

Timer Interrupt on Crossworks

2005-11-10 by mhaines4102

I have a dumb question. I am embarrassed to ask but... I am using a
timer interrupt. My setup is as follows:
	/* Timer 0 interrupt is an IRQ interrupt */
	VICIntSelect &= ~(0x10);
	/* Enable timer 0 interrupt */
	VICIntEnable = (0x10);
	/* Use slot 0 for timer 0 interrupt */
	VICVectCntl0 = 0x24;
	/* Set the address of ISR for slot 0 */
	VICVectAddr0 = (unsigned long)timer0ISR;
	/* Reset timer 0 */
	T0TCR = 0;
	/* Set the timer 0 prescale counter */
	T0PR = 2500;
	/* Set timer 0 match register */
	T0MR0 = 1000;
	/* Generate interrupt and reset counter on match */
	T0MCR = 3;
	/* Start timer 0 */
	T0TCR = 0x01;
	T0IR = 0xFF;

The interrupt was being called, then it stopped. I changed some
settings and it came back, then it stopped again. I added T0IR = 0xFF;
to the end of the setup and it worked, then it stopped again. What
have I missed? I am beginning to feel like a goof.

Thanks,

Mike Haines

Re: [lpc2000] Timer Interrupt on Crossworks

2005-11-10 by Karl Olsen

---- Original Message ----
Show quoted textHide quoted text
From: "mhaines4102" <mhaines4102@...>
To: <lpc2000@yahoogroups.com>
Sent: Thursday, November 10, 2005 9:40 PM
Subject: [lpc2000] Timer Interrupt on Crossworks

> I have a dumb question. I am embarrassed to ask but... I am using a
> timer interrupt. My setup is as follows:
> /* Timer 0 interrupt is an IRQ interrupt */
> VICIntSelect &= ~(0x10);
> /* Enable timer 0 interrupt */
> VICIntEnable = (0x10);
> /* Use slot 0 for timer 0 interrupt */
> VICVectCntl0 = 0x24;
> /* Set the address of ISR for slot 0 */
> VICVectAddr0 = (unsigned long)timer0ISR;
> /* Reset timer 0 */
> T0TCR = 0;
> /* Set the timer 0 prescale counter */
> T0PR = 2500;
> /* Set timer 0 match register */
> T0MR0 = 1000;
> /* Generate interrupt and reset counter on match */
> T0MCR = 3;
> /* Start timer 0 */
> T0TCR = 0x01;
> T0IR = 0xFF;
> 
> The interrupt was being called, then it stopped. I changed some
> settings and it came back, then it stopped again. I added T0IR = 0xFF;
> to the end of the setup and it worked, then it stopped again. What
> have I missed? I am beginning to feel like a goof.

Have you remembered a
   VICVectAddr = 0x00;  /* Clear interrupt flag in the VIC */
and a
   T0IR = 0x01  /* Clear the match 0 interrupt flag */
in your interrupt handler?

Karl Olsen

Re: Timer Interrupt on Crossworks

2005-11-10 by mhaines4102

Well this is what I have now and it is working:
	/* Timer 0 interrupt is an IRQ interrupt */
	VICIntSelect &= ~(0x10);
	/* Enable timer 0 interrupt */
	VICIntEnable = (0x10);
	/* Clear a selected interrupt. 0s should do nothing. */
	VICIntEnClr = 0x0000;
	/* Use slot 0 for timer 0 interrupt */
	VICVectCntl0 = 0x24;
	/* Clear a previous interrupt call */
	VICVectAddr = 0x0;
	/* Set the address of ISR for slot 0 */
	VICVectAddr0 = (unsigned long)timer0ISR;

	/* Reset timer 0 */
	T0TCR = 0;
	/* Set the timer 0 prescale counter */
	T0PR = 2500;
	/* Set timer 0 match register */
	T0MR0 = 1000;
	/* Generate interrupt and reset counter on match */
	T0MCR = 3;
	/* Start timer 0 */
	T0TCR = 0x01;
	T0IR = 0xFF;

I just went through the book and made sure anything that could be
reset, was.

Thanks,

Mike Haines


--- In lpc2000@yahoogroups.com, "Karl Olsen" <kro@p...> wrote:
Show quoted textHide quoted text
>
> ---- Original Message ----
> From: "mhaines4102" <mhaines4102@y...>
> To: <lpc2000@yahoogroups.com>
> Sent: Thursday, November 10, 2005 9:40 PM
> Subject: [lpc2000] Timer Interrupt on Crossworks
> 
> > I have a dumb question. I am embarrassed to ask but... I am using a
> > timer interrupt. My setup is as follows:
> > /* Timer 0 interrupt is an IRQ interrupt */
> > VICIntSelect &= ~(0x10);
> > /* Enable timer 0 interrupt */
> > VICIntEnable = (0x10);
> > /* Use slot 0 for timer 0 interrupt */
> > VICVectCntl0 = 0x24;
> > /* Set the address of ISR for slot 0 */
> > VICVectAddr0 = (unsigned long)timer0ISR;
> > /* Reset timer 0 */
> > T0TCR = 0;
> > /* Set the timer 0 prescale counter */
> > T0PR = 2500;
> > /* Set timer 0 match register */
> > T0MR0 = 1000;
> > /* Generate interrupt and reset counter on match */
> > T0MCR = 3;
> > /* Start timer 0 */
> > T0TCR = 0x01;
> > T0IR = 0xFF;
> > 
> > The interrupt was being called, then it stopped. I changed some
> > settings and it came back, then it stopped again. I added T0IR = 0xFF;
> > to the end of the setup and it worked, then it stopped again. What
> > have I missed? I am beginning to feel like a goof.
> 
> Have you remembered a
>    VICVectAddr = 0x00;  /* Clear interrupt flag in the VIC */
> and a
>    T0IR = 0x01  /* Clear the match 0 interrupt flag */
> in your interrupt handler?
> 
> Karl Olsen
>

Re: Timer Interrupt on Crossworks

2005-11-10 by rtstofer

--- In lpc2000@yahoogroups.com, "mhaines4102" <mhaines4102@y...> 
wrote:
>
> I have a dumb question. I am embarrassed to ask but... I am using a
> timer interrupt. My setup is as follows:
> 	/* Timer 0 interrupt is an IRQ interrupt */
> 	VICIntSelect &= ~(0x10);
> 	/* Enable timer 0 interrupt */
> 	VICIntEnable = (0x10);
> 	/* Use slot 0 for timer 0 interrupt */
> 	VICVectCntl0 = 0x24;
> 	/* Set the address of ISR for slot 0 */
> 	VICVectAddr0 = (unsigned long)timer0ISR;
> 	/* Reset timer 0 */
> 	T0TCR = 0;
> 	/* Set the timer 0 prescale counter */
> 	T0PR = 2500;
> 	/* Set timer 0 match register */
> 	T0MR0 = 1000;
> 	/* Generate interrupt and reset counter on match */
> 	T0MCR = 3;
> 	/* Start timer 0 */
> 	T0TCR = 0x01;
> 	T0IR = 0xFF;
> 
> The interrupt was being called, then it stopped. I changed some
> settings and it came back, then it stopped again. I added T0IR = 
0xFF;
> to the end of the setup and it worked, then it stopped again. What
> have I missed? I am beginning to feel like a goof.
> 
> Thanks,
> 
> Mike Haines
>

I have Timer0 interrupt 2000 times per second using a prescale of 2 
and a count of 14400.  Besides toggling an LED, it increments a tick 
counter for the uIP (TCP/IP) stack - specifically for telnet.

Here is my Timer0 setup (setup.c):

// set up Timer 0
TIMER0_TC    = 0; // clear the timer count
TIMER0_PR    = 1; // prescale divide by 2
TIMER0_MR0   = 14400; // divide by 14400 to get 2048 ints per second
TIMER0_MCR   = 0x03; // interrupt on match, reset on match
TIMER0_TCR   = 0x01; // start the timer
VICVectCntl3 = 0x00000024; // set priority 3 for Timer 0
VICVectAddr3 = (unsigned long) T0ISR; // pass the address of the ISR
VICIntEnable = 0x00000010; // enable interrupt

This is my interrupt routine (interrupt.c):

void T0ISR(void)
{
 ticks++;
 if ((ticks & 0x07FF) == 0) // every 2048 ticks
 {
 if (ticks & 0x0800) // every 4096 ticks
 IOSET = LED_YELLOW;
 else
 IOCLR = LED_YELLOW;
 }
 TIMER0_IR = 0x01;
 VICVectAddr = 0xFF;
}

Here is my interrupt routine prototype (interrupt.h):

void T0ISR (void)   __attribute__ ((interrupt));
	

The only other changes I have made is to increase all of the stacks 
to 64 bytes from 4.  Not necessary perhaps, but safe.

Richard

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.