Hello
#include "mbed.h"
DigitalOut LiveLED(LED1);
void Timer1_init(void);
void Timer1_IRQHandler(void);
int main()
{
Timer1_init();
LiveLED=0;
while(1)
{
}
}
void Timer1_init(void)
{
LPC_SC->PCONP |= 1 << 2; // Power on Timer
LPC_TIM1->TCR = 0x2; // Reset and set to timer mode
LPC_TIM1->CTCR = 0x0;
LPC_TIM1->PR = 0; // No prescale
LPC_TIM1->MR0 = 2398; // Match count for 100mS
LPC_TIM1->MCR = 3; // Interrupt and Reset on Match
LPC_TIM1->TCR = 1; // Enable Timer
// Enable the ISR vector
NVIC_SetVector (TIMER1_IRQn, (uint32_t)&Timer1_IRQHandler);
NVIC_EnableIRQ(TIMER1_IRQn);
}
void Timer1_IRQHandler(void)
{
LPC_TIM1->MR0 = 2398;
LiveLED!=1;
}
I found some of this code in an example. I am simply attempting to toggle an LED via a timer based Interrupt. I have modified it slightly for my purposes, but it is not functioning correctly. I understand what each statement does. My questions are:
1) why use
LPC_SC->PCONP |= 1 << 2; // Power on Timer
instead of addressing the register regarding power for the timer directly? or is it not bit adressable?
2) is this necessary at all?
LPC_TIM1->CTCR = 0x0;
as this is its reset value is it necessary considering that i only call this function during initialisation?
3) Shouldn't this be set to 00000001
LPC_TIM1->MR0 = 2398;
That would enable the IRQ for match channel 0?
Apologies if there is a good tutorial on this somewhere else.
Regards, Joel
Hello
I found some of this code in an example. I am simply attempting to toggle an LED via a timer based Interrupt. I have modified it slightly for my purposes, but it is not functioning correctly. I understand what each statement does. My questions are:
1) why use
instead of addressing the register regarding power for the timer directly? or is it not bit adressable?
2) is this necessary at all?
as this is its reset value is it necessary considering that i only call this function during initialisation?
3) Shouldn't this be set to 00000001
That would enable the IRQ for match channel 0?
Apologies if there is a good tutorial on this somewhere else.
Regards, Joel