Hi all. I want to use all 4 T0MRx in my program. whit TxMCR we can set what happen after T0MRx match with T0TC. my problem is here : I could wrote code for 1 T0MRx , but I can't write code for all of them.
one point : timerx jast have one isr , how i can use all of 4 T0MRx interrupt ? thanks.
oh , the MCU is lpc2378.
"but I can't write code for all of them"
Why not? What's the problem?
"timerx jast have one isr , how i can use all of 4 T0MRx interrupt?"
Study the chip's documentation to see what features are available to identify which timer caused the interrupt...?
actually , i could wrote a code , but it didn't work.
I have already read UM and i have not problem with that , and i wrote code for just one match register , now i want code for all of 4 match register on Timer0 for example.
thanks for your answer.
i could wrote a code , but it didn't work.
And it really didn't occur to you that
a) you'll not just have to write code, but also show it to people, if they're to have any chance at helping you, nor that
b) "it didn't work" is an utterly useless way of describing any error
?
The timer 0 can only have one single ISR for a simple reason. One ISR can handle all four match registers, since the ISR can check which of the match registers that resulted in the interrupt.
Have you located the part of the user manual documentation that tells you how to figure out which match register(s) that have matched?
it's my code :
#include <lpc23xx.h> #define LCD_PORT_0 #define LCD_RS 25 #define LCD_E 24 #define LCD_DB4 23 #define LCD_DB5 22 #define LCD_DB6 21 #define LCD_DB7 20 #include <lcd.h> int i=0; int j=10000; void timer0_isr(void) __irq{ if(T0MR0==T0TC) i++; else if(T0MR1==T0TC) j--; T0IR=3; VICVectAddr=0; T0TCR=1; } int main(){ SCS=1; lcd_init(); lcd_clear(); //timer0 setting T0TCR=2; // reset counter , disable counter T0CTCR=0; // set T/C for Timer T0PR=0; // no prescale T0MR0=1500000; T0MR1=3000000; T0MCR=63; T0TCR=1; //enable counter //interrupt setting VICIntSelect=0; // set timer0 interrupt on IRQ mood VICIntEnable=1 << 4; // enable interrupt for timer0 VICVectAddr4=(unsigned long) timer0_isr; //set label for jump when T0MR0 is match with T0TC //LEDs setting PINSEL6=0; FIO3DIR0=255; //main loop while(1){ lcd_gotoxy(1,1); lcd_puts(i); lcd_putsf(" "); lcd_gotoxy(2,1); lcd_puts(j); lcd_putsf(" "); }}
I set register T0MCR when match in happened , stop counting.so in Timer0_isr , i compared T0TC whit T0MRx that i used them. and wrote when T0MR0 is match , i++ and when T0MR1 is match , j--. but on lcd I just one of them working.
please help me.
thanks all.
is there any special register to find out ?
When you did spend time reading the user manual - especially the chapter about the timers - how many of the registers did you spend time reading about?
Did you read anything about the IR register? Maybe any sentence like "The IR can be read to identify which of eight possible interrupt sources are pending."? What was your conclusion, when you did read that sentence? Did it make you excited, and motivated you to take a closer look at the IR register? I don't see your code test any contents of the IR register.
void timer0_isr(void) __irq{ if(T0MR0==T0TC) i++; else if(T0MR1==T0TC) j--; T0IR=3; VICVectAddr=0; T0TCR=1; }
What make you think that you can compare the fixed value (your configuration) in T0MR0 and T0MR1 with T0TC? Haven't you considered that T0TC is constantly ticking - potentially at a quite high frequency? What if T0TC happens to tick up one or more ticks before your ISR has a change to check the value of it? How would then your == tests manage to compare with T0MR0 or T0MR1?
Your code doesn't contain any code where you compute any times or frequencies, so I can't tell. I don't even know what crystal you have. But let's say that T0TC ticks at 10MHz - 1 tick ever 100ns. Do you expect your ISR to be called, and your two if statements to be procesed within less than 100ns? Or maybe the timer is ticking even faster...
T0IR=3;
How, just how, can you clear interrupts for both match register 0 and match register 1, when you don't even know which of the match registers that trigged the interrupt?
T0TCR=1
So you ask for a reset of the timer, i.e. for it to restart from zero. You do this on every interrupt. But if match 0 is after 1.5 million ticks, and match 1 after 3 million ticks - how will the timer ever be able to reach 3 million ticks when you reset it to zero already after 1.5 million ticks?
Next thing - what makes you think you need to restart the timer manually? Haven't you - when you did read the user manual (specifically the chapter about timers) noted that each match register (through the match control register) can be configured to: - possibly generate an interrupt on match - possibly restart the timer on match - possibly stop the timer on match
Wouldn't it be much better to have match register 0 generate an interrupt on match, and match register 1 generate both an interrupt, and a reset of the timer? Then the timer would - all by itself - count to 3 million and directly restart from zero.
By the way - are you sure you should have the match register match for 1500000 and 3000000? Would a match value of 1 mean a timer with only 1 tick or a timer with two (0 and 1)? What does the user manual say?
OK , you are right. I think my problem is on T0IR , isn't it ?
thank you.
"I think my problem is on T0IR , isn't it ?"
That's not your only problem - I do cover more problems in my previous answer. And I didn't spend any time looking at your timer initialization. Just at your "detect" and "acknowledge" sections of your ISR.