Hi Folks,
I am trying to work on Timer Interrupts. I want to start an LED when a TIMER match occurs. I have called an Interrupt on match and the LED should glow when the match occurs. I am not able to perceive the output. I am not exactly getting where its going wrong. Can you please help me out on this. Below is the code, please review
#include<lpc21xx.h>
#define MR0I_FLAG 0X01 void led(void)__irq { long int regval; regval = T0IR;
if(T0IR & MR0I_FLAG) { T0MR0 = 0XFF; T0TC = 0X00; T0TCR = 0X00000001;
IO0CLR = 0X00000002; IO0SET = 0X00000008; }
T0IR = regval; VICVectAddr0 = 0X00000000; }
int main() { IO0DIR = 0X0000000A; T0TCR = 0X00000000; T0MCR = 0X00000003; //Reset and generate an interrupt on Match T0PC = 0X00000000; T0PR = 0X00000000;
VICIntEnable = 0X00000010; VICVectCntl0 = 0X00000024; VICVectAddr0 = (unsigned)led;
IO0SET = 0X00000002; }
So - what frequency do you get? The difference between expected and actual frequency is normally a good hint at what is incorrectly configured - debugging is all about picking up the available clues and evaluate them.
If you have 12 MHz, then you somehow have to divide that down to 1 Hz for your expected interrupt frequency. I haven't seen you try any values that would be even close to such attempt - on the first code post you ignored the match control register despite requesting an interrupt on match. In the second post, you made a bit of a random assignment for the match control register - and arbitrary values tends to give arbitrary results.
Wouldn't it be an idea to fix the things that have already been mentioned?
Like making some reasonable attempt at setting a value for the match control register?
Or making sure the program doesn't exit main() before the processor have time to produce the first interrupt?
The processor will not ignore details, even if you do.