Can 2 MRs generate separate interrupts on the same timer?

I’m a bit confused over the documentation regarding interrupts.

I am trying to set up MR0 and MR1 to trigger on the same timer like this:

MR0 triggers after time t on Timer 0 and causes vectored interrupt 0.

MR1 triggers after time 2*t and causes vectored interrupt 1 and resets Timer 0.

I didn’t think too much about it until I was about to code the setup of the VICIntEnable and VICVectCntl registers.

The description of the VICVectCntl control registers says:

Bit 4:0

The number of the interrupt request or software interrupt assigned to this vectored IRQ slot.

Is “number of the interrupt request” refering to the interrupt sources in Table 33 (in which Timer 0 Match 0-2, Capture 0-2 is one source) ?

If that is the case, it’s not possible to generate separate interrupt vector function calls for MR0 and MR1 on Timer 0, is it?

I am asking because I’m very new at this and it will take me some time to figure all this out and test it so I just wanted to ask.

I have a feeling that both of the MR interrupts will case both interrupt vectors to trigger, in which case only vector 0 will be used.

In case my suspicions are correct I could probably just use MR0 alone and alternate between two ISR functions (or alternate the flow in the ISR function) when it triggers.

So, to be brief:

Can I trigger two separate interrupts on the same timer using two match registers?

Each timer channel has a single interrupt handler. So, for example if you are using timer channel 0, and interrupts are enabled on MR0, and MR1, either of these could generate an interrupt, but only a single handler would be called. You can tell which one triggered the interrupt by looking at the T0IR register, and have the handler deal with each appropriately. Having a single interrupt handler deal with multiple interrupt sources is quite common.

manton:
You can tell which one triggered the interrupt by looking at the T0IR register

Aaah, ok.

So I’ll just use one function and look at T0IR to see which MR it was (and clear it I guess) and the function can can handle the interrupts as separate interrupts sort of.

Thanks a lot! :slight_smile:

Is it possible to change the MR timer value while the timer is running without resetting or is something else needed?

In particular, what if I change the MR value to a timer value that has already passed? :I

What I am trying to do is generate a tempo beat for a simple sequencer by generating interrupts for each note to be triggered.

I think I am in trouble if I increase the tempo (lowering the MR timer value) while the timer is running since I might “miss” the actual MR time.

I might just have to come up with a different solution.

Anyway, thanks for your help :slight_smile:

You can change match times on the fly without stopping the timer.

If the match time has already passed when you set up a new one, then it will be missed until the timer wraps around. Could you set an additional match for a count of 0? When it hits that one, you can change the desired match to anything without worry of underflow (within reason, as the timer is still incrementing, so this may not work well for very short time intervals).

Alright, thanks for your reply!

I’ll see if I get this thing going and which approach suits me best :slight_smile:

Thanks a lot!