--- In lpc2000@yahoogroups.com, "ylavoie66" <ylavoie66@...> wrote:
> Is it something you already tried and tested?
> Philips documentation does not clearly state that. Then again it
> won't be the first time an IC manufacturer gives incomplete
> documentation :(
>
> Regards,
>
> Yves Lavoie
>
Yves,
The following code generates a 1ms "tick" interrupt, which I believe is
what you're looking for. It assumes a 60 MHz system. The manual is
quite clear about the need to subtract one from the desired value when
setting the counter value.
Hope this helps: it's been tried an tested on a LPC2134 (pretty much
the same as the LPC2138). Note that the function to initialise the
timer is called once on system startup, and assumes (all) interrupts
are disabled.
Brendan
>>>>>>>>>>>>>> CODE EXAMPLE <<<<<<<<<<<<<<<<<<<<
/* TIMER counter value for 1ms tick */
#define TIMER_TICK_1_MS (59999) /* VPB at 60 MHz clock */
/* system tick count in milliseconds */
static volatile
int tick_count;
/*
* Interrupt handler for 1ms "tick"
*
* The handler will be called from interrupt processing context
*/
static
void tick_isr(void)
{
/* reset the interrupt */
REG(TIMER1_IR) = 0x01;
/* bump the millisecond conter */
tick_count++;
/* call RTOS to handle tick */
RtosTick();
return;
}
/*
* Start "tick" interupt for 1ms system "tick" using TIMER 1
*/
static
void tick_init(void)
{
/* ensure timer 1 is off */
TIMER1_TCR = 0x00;
/* set timer counter and prescale counter */
TIMER1_TC = 0x0;
TIMER1_PC = 0x0;
/* set prescale and match values to give 1 ms "tick" */
TIMER1_PR = 0x0;
TIMER1_MR0 = TIMER_TICK_1_MS;
/* set control to interrupt on MR0 match,
and reset to 0 (i.e. "tick") */
TIMER1_MCR = 0x3;
/* vector TIMER 1 as mid-level priority and enabled */
VICVectCntl11 = 0x25;
/* vector TIMER 1 interrupt address */
VICVectAddr11 = (unsigned int) tick_isr;
/* enable TIMER 1 in VIC */
VICIntEnable = 0x0020;
/* go start timer 1... */
TIMER1_TCR = 0x1;
return;
}
>>>>>>>>>>>>>> END CODE EXAMPLE <<<<<<<<<<<<<<<<<<<<Message
Re: Timer interrupts on LPC2138
2006-05-15 by brendanmurphy37
Attachments
- No local attachments were found for this message.