Hello :-)
I am trying to run for the first time the Timer1 interrupt, for having a tick
off 5ms on my system.
The "timers.c" file:
#include "lpc210x.h"
void timer1_int_handler (void) __attribute__ ((interrupt("IRQ")));
void timer1_int_handler (void)
{
TIMER1_IR = 1;
VICVECTADDR = 0xff;
}
void timer1_init (void)
{
/* Initialize VIC */
VICCNTL0 = 0x25;
VICVECTADDR0 = (unsigned long) timer1_int_handler; /* Address of the ISR
*/
VICINTSEL = 0; /* Timer 1 selected as IRQ */
VICINTEN = (1 << 5); /* Timer 1 interrupt enabled */
/* Initialize Timer 1 */
TIMER1_TC = 0; /* Counter register: Clear counter */
TIMER1_PR = 0; /* Prescaler register: Clear prescaler */
TIMER1_PC = 0; /* Prescaler counter register: Clear prescaler counter */
/* Match register 0: We want an interrupt every 5 ms. Fclk = 53.2368 Mhz.
*/
TIMER1_MR0 = 263157; /* 0,005/(1/53236800) ~= 263157 */
TIMER1_MCR |= 3; /* Reset and interrupt on match */
/* Start timer */
TIMER1_TCR = 1;
}
And I run this on main():
/* Initialize the Timer0 */
timer1_init ();
enableIRQ ();
I am doing JTAG debug and using a break point I never see the timer1_int_handler
happening :-(
I did read the AN10254 from Phillips and also many messages on Internet about
the Timer1... but I can't understand why the interrupt do not happen.
My full code is here:
http://code.google.com/p/casainho-projects/source/browse/#svn/trunk/pedal_power_meter/lpc2103_version
Thank is advance.
Timer1 interrupt not working
Started by ●May 9, 2009
Reply by ●May 10, 20092009-05-10
--- In l..., "JPCasainho" wrote:
>
> Hello :-)
>
> I am trying to run for the first time the Timer1 interrupt, for having a tick off 5ms on my system.
>
> The "timers.c" file:
>
> #include "lpc210x.h"
>
> void timer1_int_handler (void) __attribute__ ((interrupt("IRQ")));
>
> void timer1_int_handler (void)
> {
> TIMER1_IR = 1;
> VICVECTADDR = 0xff;
> }
>
> void timer1_init (void)
> {
> /* Initialize VIC */
> VICCNTL0 = 0x25;
> VICVECTADDR0 = (unsigned long) timer1_int_handler; /* Address of the ISR */
> VICINTSEL = 0; /* Timer 1 selected as IRQ */
> VICINTEN = (1 << 5); /* Timer 1 interrupt enabled */
>
> /* Initialize Timer 1 */
> TIMER1_TC = 0; /* Counter register: Clear counter */
> TIMER1_PR = 0; /* Prescaler register: Clear prescaler */
> TIMER1_PC = 0; /* Prescaler counter register: Clear prescaler counter */
>
> /* Match register 0: We want an interrupt every 5 ms. Fclk = 53.2368 Mhz. */
> TIMER1_MR0 = 263157; /* 0,005/(1/53236800) ~= 263157 */
>
> TIMER1_MCR |= 3; /* Reset and interrupt on match */
>
> /* Start timer */
> TIMER1_TCR = 1;
> }
> And I run this on main():
>
> /* Initialize the Timer0 */
> timer1_init ();
> enableIRQ ();
>
> I am doing JTAG debug and using a break point I never see the timer1_int_handler happening :-(
>
> I did read the AN10254 from Phillips and also many messages on Internet about the Timer1... but I can't understand why the interrupt do not happen.
>
> My full code is here: http://code.google.com/p/casainho-projects/source/browse/#svn/trunk/pedal_power_meter/lpc2103_version
>
> Thank is advance.
I got it working :-) I had 3 errors on my code:
-- I didn't have Timer/Counter 1 power/clock enable, because I disable it at begin.
-- VICVECTCNTL0 register were wrong defined, it as defined as if was the VICVECTCNTL10.
-- Timer1 Prescaler was 0 and it do not works for me at 0, just at 1 or more.
Thanks to JTAG debug I could see the register values and seeing Timer1 incrementing, the interrupt flag going to 1, etc :-)
Here is the working code:
void timer1_int_handler (void) __attribute__ ((interrupt("IRQ")));
void timer1_int_handler (void)
{
TIMER1_IR = 1;
VICVECTADDR = 0xff;
}
void timer1_init (void)
{
/* Timer/Counter 1 power/clock enable */
PCONP |= (1 << 2);
/* Initialize VIC */
VICVECTCNTL0 = 0x25;
VICVECTADDR0 = (unsigned long) timer1_int_handler; /* Address of the ISR */
VICINTSEL = 0; /* Timer 1 selected as IRQ */
VICINTEN = (1 << 5); /* Timer 1 interrupt enabled */
/* Initialize Timer 1 */
TIMER1_TC = 0; /* Counter register: Clear counter */
TIMER1_PR = 0; /* Prescaler register: Clear prescaler */
TIMER1_PC = 0; /* Prescaler counter register: Clear prescaler counter */
/* Match register 0: We want an interrupt every 5 ms. Fclk = 53.2368 Mhz. */
TIMER1_MR0 = 263157; /* 0,005/(1/53236800) ~= 263157 */
TIMER1_PR = 1; /* Prescaler = 1 */
TIMER1_MCR |= 3; /* Reset and interrupt on match */
/* Start timer */
TIMER1_TCR = 1;
}
>
> Hello :-)
>
> I am trying to run for the first time the Timer1 interrupt, for having a tick off 5ms on my system.
>
> The "timers.c" file:
>
> #include "lpc210x.h"
>
> void timer1_int_handler (void) __attribute__ ((interrupt("IRQ")));
>
> void timer1_int_handler (void)
> {
> TIMER1_IR = 1;
> VICVECTADDR = 0xff;
> }
>
> void timer1_init (void)
> {
> /* Initialize VIC */
> VICCNTL0 = 0x25;
> VICVECTADDR0 = (unsigned long) timer1_int_handler; /* Address of the ISR */
> VICINTSEL = 0; /* Timer 1 selected as IRQ */
> VICINTEN = (1 << 5); /* Timer 1 interrupt enabled */
>
> /* Initialize Timer 1 */
> TIMER1_TC = 0; /* Counter register: Clear counter */
> TIMER1_PR = 0; /* Prescaler register: Clear prescaler */
> TIMER1_PC = 0; /* Prescaler counter register: Clear prescaler counter */
>
> /* Match register 0: We want an interrupt every 5 ms. Fclk = 53.2368 Mhz. */
> TIMER1_MR0 = 263157; /* 0,005/(1/53236800) ~= 263157 */
>
> TIMER1_MCR |= 3; /* Reset and interrupt on match */
>
> /* Start timer */
> TIMER1_TCR = 1;
> }
> And I run this on main():
>
> /* Initialize the Timer0 */
> timer1_init ();
> enableIRQ ();
>
> I am doing JTAG debug and using a break point I never see the timer1_int_handler happening :-(
>
> I did read the AN10254 from Phillips and also many messages on Internet about the Timer1... but I can't understand why the interrupt do not happen.
>
> My full code is here: http://code.google.com/p/casainho-projects/source/browse/#svn/trunk/pedal_power_meter/lpc2103_version
>
> Thank is advance.
I got it working :-) I had 3 errors on my code:
-- I didn't have Timer/Counter 1 power/clock enable, because I disable it at begin.
-- VICVECTCNTL0 register were wrong defined, it as defined as if was the VICVECTCNTL10.
-- Timer1 Prescaler was 0 and it do not works for me at 0, just at 1 or more.
Thanks to JTAG debug I could see the register values and seeing Timer1 incrementing, the interrupt flag going to 1, etc :-)
Here is the working code:
void timer1_int_handler (void) __attribute__ ((interrupt("IRQ")));
void timer1_int_handler (void)
{
TIMER1_IR = 1;
VICVECTADDR = 0xff;
}
void timer1_init (void)
{
/* Timer/Counter 1 power/clock enable */
PCONP |= (1 << 2);
/* Initialize VIC */
VICVECTCNTL0 = 0x25;
VICVECTADDR0 = (unsigned long) timer1_int_handler; /* Address of the ISR */
VICINTSEL = 0; /* Timer 1 selected as IRQ */
VICINTEN = (1 << 5); /* Timer 1 interrupt enabled */
/* Initialize Timer 1 */
TIMER1_TC = 0; /* Counter register: Clear counter */
TIMER1_PR = 0; /* Prescaler register: Clear prescaler */
TIMER1_PC = 0; /* Prescaler counter register: Clear prescaler counter */
/* Match register 0: We want an interrupt every 5 ms. Fclk = 53.2368 Mhz. */
TIMER1_MR0 = 263157; /* 0,005/(1/53236800) ~= 263157 */
TIMER1_PR = 1; /* Prescaler = 1 */
TIMER1_MCR |= 3; /* Reset and interrupt on match */
/* Start timer */
TIMER1_TCR = 1;
}