Hello everyone,
I am having some issues setting up multiple interrupts based off of the same timer source. I thought this would be relatively simple to implement, by simply altering the values written to two separate capture/compare registers and then having an interrupt service routine driven by each capture/compare register. However, when I attempt to implement this, I find that the two interrupts are not called at the same rate, even when I write the same value to both capture/compare registers. Here is a scaled-down version of the code I am implementing, and I'm not quite sure what I'm missing to have these ISR's called at the same rate (I know one will have higher priority than the other, but they aren't even close as far as how fast they get called; for example, the value of "a" will equal 2 and the value of "b" will be something ridiculous like 35479).
#include "msp430f5529.h"
/*
* main.c
*/
int main(void) {
WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer
P1DIR = BIT0;
P4DIR = BIT7;
//Interrupt timer setup:
TBCCTL0 = CCIE; // TBCCR0 interrupt enabled
TBCCR0 = 1000; //Capture/Compare register value
TBCCTL1 = CCIE; // TBCCR1 interrupt enabled
TBCCR1 = 1000; // Capture/Compare register 1 value
TBCTL = TBSSEL_1 + MC_2 + TBCLR; // ACLK, upmode, clear TBR
__bis_SR_register(GIE); //enable maskable interrupts
while(1){
}
return(0);
}
// Timer B0 interrupt service routine
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR (void){
static unsigned int a = 0;
P1OUT ^= BIT0;
a++;
}
// %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// %%%%%%%%%%%%%%%%%%%%%% ATTEMPT TO IMPLEMENT MULTIPLE INTERRUPTS %%%%%%%%%%%%%%%%%%%%%%
#pragma vector=TIMERB1_VECTOR
__interrupt void TIMERB1_ISR (void){
static unsigned int b = 0;
P4OUT ^= BIT7; //toggles LED2
b++;
}
// %%%%%%%%% END SECOND INTERRUPT SERVICE ROUTINE %%%%%%%%%%%%%%%%%%%%%%%%%%%
Any suggestions you may have or gratuitous errors you may see would be very appreciated to know about.
As always, thanks in advance for your help!
-Thomas