Hi,
I'm trying to run Timer B on my MSP430F233. The MSP receives a variable number from another MSP430 and the MSP should turn on an H-Bridge for that amount of time, then turn it off again. I am using Capture Compare Register 0 to set the timer and then when the interrupt comes it turns off the bridge. TimerB uses the ACLK = VLO/4 = 12kHz/4 = 3kHz.
Because the time to wait may be more than 21.845s (65535/3000 = 21.845) I need to use the timer rollover TBIFG interrupt to subtract the passed time from the time that is yet to be waited. The number passed from the other controller is /150 the number of cycles that need to be waited, so I can wait up to 9830250 timer cycles or ~54 minutes. In other words, only 436.9 are counted off each Timer B rollover of 65535 cycles, so if the number passed was 500, after 1 rollover I still need to wait 63.1 or 9465 Timer B cycles.
I now have 2 problems with the Timer B interrupts.
1. I set TBCTL to 0x122 or Continuous Mode, ACLK, and TBIE.
So when the timer B rolls over after 65535 it should cause a TBIFG interrupt to happen so I can subtract 436.9 from my original wait time. This interrupt does not seem to happen. The timer just rolls over and continues counting. TBIFG also does not set, or is reset somehow. However, when I set TBCTL to 0x120, so the interrupt in NOT enabled, the TBIFG sets but no interrupt is entered. Is there something else I need to set to get this interrupt?
I use this as an interrupt vector handler:
#pragma vector=TIMERB0_VECTOR
__interrupt void TIMERB0_ISR(void)
{
//Code
}
2. When the number passed is less than 436.9, I set the TBCRR0 to 150* that number and TBCCTL0 |= CCIE; so that an interrupt is generated when the proper time has elapsed. This uses the same interrupt vector as TBIFG. This interrupt works fine. However, TBCCTL0 should have bit 1 set when the interrupt happened. This bit is reset as soon as the interrupt is entered (or is never set). Since I'm using both TBIFG and TBCCR0 CCIFG within the interrupt handler I need to find out what case caused the interrupt. I do this by testing "if(TBCTL & TBIFG)" and "if(TBCCTL0 & CCIFG)". However, if neither flag is set or they are reset, when the interrupt happens it enters neither statement and the interrupt does nothing. Is the CCIFG flag supposed to reset as soon as the interrupt is handled, and if so, how can I test for it?
Right now, the program calls the CC0 interrupt but doesn't enter the if statement since the flag is reset, and it just interrupts again after it's rolled over and counted to TBCCR0 again, and so on infinitely (timer gets turned off in interrupt). If I do not activate the TBCTL interrupt, the TBIFG flag sets and the second time it reached TBCCR0 it enters the TBIFG case.
I've read through the manual on TimerB a few times now and I'm wondering if something is wrong with my understanding or with my MSP430.The manual says "The TBCCR0 CCIFG flag is automatically reset when the TBCCR0 interrupt request is serviced." I am not sure whether that is supposed to mean as soon as the interrupt is entered or after it's left... I need to distinguish between the TBIFG rollover case and TBCCR0IFG case somehow.
I discovered these problems and what is happening using the CCS debugger. I tried it using the TBCCR1. In this case the CCIFG flag is set just fine and not reset until I read TBIV. That doesn't change the fact that I'm not entering an interrupt when TB rolls over.
I am grateful for any help with this!