This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

match register on lpc2378

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.

Parents
  • 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?

Reply
  • 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?

Children