This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F2274: Using Timer-B1, up-mode, to generate an interrupt

Part Number: MSP430F2274

Simply put, what I'm trying to do is use timers to give me asynchronous one-shots.  I have read the "Family User's Guide" relevant sections a dozen times.  Via experimentation, I've managed to use both TA0 and TB0 successfully (up mode).  Both generate the required interrupts.  I've also managed (using the test code in slac123i) to get TB1 interrupts with TB in continuous mode (so I understand the TBIV code structure).  But I need to run the timer in UP Mode, and while both TA0 and TB0 are happy, TAx and TBx stubbornly refuse to interrupt - after 3 days of messing with it.  Also, I've failed to find any code samples that run TB1 in a way similar to TB0.  In an ideal world, I could set TimerB for Up Mode, plug values into TBCCR0 and TBCCR1 independently, and get CCIFG interrupts (0 in timer int and 1 in TBIV).  My sticking point is the lack of clarity on TBR.  It's unclear to me what impacts the TBR count.  Is it free-running?  Then TBCCRx writes would have some kind of hidden math goiing on.  Is it set at TBCCRx value?  That's not clearly indicated (at least to me) but it would explain why only one (independent) timer per peripheral module.

Enough. Can I run 2 independent one-shot timers (stopped in the ISR by changing TBCCRx to zero) in the TimerB module?  Any clarification about why not would be helpful.  Any ideas about getting TBCCR1 CCIFG interrupts may also help.

  • Point of terminology: TB1 refers to a second TImerB module, which doesn't exist on the F2274. I'm supposing you're actually referring to TBCCR1 (more recently known as TB0CCR1) here.

    (Also, when applied to a pin, TB1 refers to the pin associated with TB[0]CCR1, an unfortunate anachronism -- later devices refer to this pin as TB0.1.) 

    TBR is free-running, but -- in Up or Up/Down mode -- changes (resets or reverses) when it compares equal with TBCCR0. You can't use TBCCR1/2 to affect Up mode.

    If, in Up mode, you set TBCCR1 to a value less than TBCCR0, you will trigger TBCCTL1:CCIFG (and if you set CCIE, an interrupt) when TBR reaches that value. If TBCCR1 > TBCCR0, you won't get an interrupt since it will never be equal to TBR. 

    Ergo, you can't create a third one-shot using the Up-mode method you've been using. 

    My suggestion: Use Continuous mode, and set TBCCRx = TBR + delta for each one-shot. You can use CCR0 along with CCR1/2, just don't forget that the CCR0 interrupt uses a different vector. This will give you all three one-shots on a single timer (you can use TimerA for something else). 

  • Bruce,

    Most Excellent!  THANKS.  Two comments:

    1 - On one hand, I'm guessing that nothing you said isn't covered in the TI documents - probably obvious to most readers.  On the other, your phrasing - particularly "TBR is free-running, but -- in Up or Up/Down mode -- changes (resets or reverses)" cleared it all up for me.  Maybe you should be writing TI tech docs?  :-)

    2 - And I think I now understand your closing suggestion about continuous mode.  If I do, then completely asynchronous operation would require coding differently than snippets provided.  Both sample code and the User Guide indicate that the TxCCRx is written in the interrupt (suggesting a fixed period if a single value is used).  What I would need to do if I wanted an asynchronous one-shot (started in real time) would be - read TxR; add delta; write TxCCRx.  Does that sound right to you?

    I'm going to assume I understand (perhaps dangerous) and mark this as answered.  Thanks again for much clarity!

**Attention** This is a public forum