Is it possible to get a CCR to throw up its interrupt flag more than once in the same timer period?
I'm trying to output several independent PWM signals out of my Launchpad G2553's Timer_A to control 5 servos. Each CCR is set up so that the interrupt will toggle on its respective output and then increment the CCR by some amount. On the second interrupt, it is supposed to check to see if that CCR was changed from its original value, and if so, toggle the output off. I'm getting the feeling that CCR interrupts don't work that way, since it's not giving me a nice pulse.
The pulse works fine when I try to get a pulse to start on the beginning of a timer period after an overflow, but I'd like to be able to stagger the CCRs so that the current spike from the servos is spread out over each period and doesn't overwhelm my power supply.
Here is the code, in case it's actually not a CCR problem but something else. I'm using MSPGCC, not CCS.
#include <stdlib.h>
#include <stdbool.h>
#include <msp430.h>
#include <legacymsp430.h>
#define MCLK_FREQ 12000000UL /* run @12MHz */
int main() {
WDTCTL = WDTPW | WDTHOLD; /* Disable watchdog */
DCOCTL = 0;
BCSCTL1 = CALBC1_12MHZ; // 12MHz MCLK
DCOCTL = CALDCO_12MHZ;
BCSCTL2 |= DIVS_2; // 3MHz SMCLK
P2DIR |= BIT0;
P2SEL &= ~BIT0; // general IO
TA1CCTL0 = CCIE;
TA1CCR0 = 7000;
TA1CTL = TASSEL_2 + ID_0 + MC_2 + TAIE; // SMCLK is Timer_A's clock, SMCLK/1, continuous mode, enable interrupts
__bis_SR_register(LPM0_bits + GIE);
}
interrupt(TIMER1_A0_VECTOR) CCR0_ISR() {
unsigned int time = TAR;
if(TA1CCR0 == 7000) { // if this is the original CCR value
P2OUT |= BIT0; // pulse starts
TA1CCR0 += 4500; // increment the CCR
}
else // otherwise
P2OUT &= ~BIT0; // pulse ends
//CCIFG flag is automatically cleared by servicing the interrupt
}
interrupt(TIMER1_A1_VECTOR) OVERFLOW_ISR() {
P2OUT &= ~BIT0; // pull output low just in case
while(TA1IV); // clear TAIV
}
I'd really appreciate having some light shed on the capabilities of the CCRs or help in an alternate approach.