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.

Timer A ISR not triggered with external 32kHZ crystal

This is weird.

I got my timer working with the DCO clock, and everything was fine.

This was the old code:

void init(){

//other init stuff


     BCSCTL1 = CALBC1_1MHZ;            //Set DCO to calibrated 1 MHz.
    DCOCTL  = CALDCO_1MHZ;
     
      TACCR0 = DEFAULTTACOUNT;                 
    TACCTL0 = CCIE;                  //CCR0 interrupt enable

    TACTL = TASSEL_2 +         //select SMCLK as the clock for Timer_A (runs off the DCO by default),
            ID_3 +             //select input divider of 8 (1 MHz SMCLK becomes 125 kHz),
            MC_3 +             //select up/down mode, and
            TACLR;            //clear the count in TAR

    IE1 = WDTIE;
    __enable_interrupt();
   
    measuretempvcc();

}
void main(void) {
    init();
    _BIS_SR(LPM1_bits + GIE);
      while (1){   
      }
}

 

This works fine, both the watchdog timer and timer A interrupts work fine.

However, the DCO was losing a few seconds every day, which is more than my tolerance, and varying the TACCR0 count was getting complicated, . So I had to change to an external 32kHz xtal.

This is my new code:

void init(){

//other init stuff


    DCOCTL  = CALDCO_1MHZ;
    BCSCTL1 = 0x80;//XT2OFF = 1, XTS = 0, DIVAx = 0, RSELx = 0
   
    BCSCTL2 = 0x08;//SELMx = 00, DIVMx = 00, SELS = 1, DIVS = 00, DCOR = 0
   
    BCSCTL3 = 0x0c;//XT2Sx = 00, LFXT1Sx = 00, XCAPx = 11, faultx = 00
     
      TACCR0 = 100;                 
    TACCTL0 = CCIE;                  //CCR0 interrupt enable

    TACTL = TASSEL_2 +         //select SMCLK as the clock for Timer_A
            ID_1 +             //select input divider of 2

            MC_3 +             //select up/down mode, and
            TACLR;            //clear the count in TAR

    IE1 = WDTIE;
    __enable_interrupt();
   
    measuretempvcc();

}
void main(void) {
    init();
    _BIS_SR(GIE);
      while (1){   
      }
}

The new code triggers my watchdog timer just fine, but the timer A ISR is never called. I have put a breakpoint there, and stepped through the code. However, I can watch the TAR register getting modified when I step through.

 

Any ideas, folks? Anything wrong in my code?

I've found this forum awesome. So, thanks a lot.

Cheers,

Anirban

  • The issue seems to be a crystal fault. I did not solder the 'head' of the crystal properly.

    Whenever I touched it, the TIMER A0 ISR  would start to work. Now, when I soldered the head properly, nothing seems to work, including the WDT.

    Too bad the Launchpad comes with an SMD xtal :-(

     

    Anirban Banerjee said:
    This is weird.

     

  • Some things I noticed:

    Anirban Banerjee said:
    IE1 = WDTIE;

    You never init the WDT for counter mode.  And you do not trigger it. So it will finally reset the device after 32768 clock cycles. Settign the WDTIE bit has only effect if the WDT is in counter mode. And then you'll need an ISR for it too,

    Anirban Banerjee said:
    TACTL = TASSEL_2 +         //select SMCLK as the clock for Timer_A


    Anirban Banerjee said:
    BCSCTL2 = 0x08;//SELMx = 00, DIVMx = 00, SELS = 1, DIVS = 00, DCOR = 0
    You don't write the exact processor you use. SELS1 selects the XT1 (LF crystal) only if there is no XT2 oscillator unit on this chip (independently of whether there is an XT2 installed or not).
    So if your MSP could have an XT2 attached, then XT2 is selected by SELS=1.
    In this case, you should use ACLK on teh timer, which is by default driven by an LF crystal on XT1.

    In any case, you do not wait for the crystal to come up properly, by checking the oscillator fault bits. The procedure is described in the family users guide.

  • Hi Jens,

    Thanks for the reply.

     

    Jens-Michael Gross said:

    Some things I noticed:

    IE1 = WDTIE;

    You never init the WDT for counter mode.  And you do not trigger it. So it will finally reset the device after 32768 clock cycles. Settign the WDTIE bit has only effect if the WDT is in counter mode. And then you'll need an ISR for it too,

    Anirban Banerjee said:
    TACTL = TASSEL_2 +         //select SMCLK as the clock for Timer_A

    The WDT is used in the counter mode, and I have an ISR for that.

    Anirban Banerjee said:
    BCSCTL2 = 0x08;//SELMx = 00, DIVMx = 00, SELS = 1, DIVS = 00, DCOR = 0

    You don't write the exact processor you use. SELS1 selects the XT1 (LF crystal) only if there is no XT2 oscillator unit on this chip (independently of whether there is an XT2 installed or not).
    So if your MSP could have an XT2 attached, then XT2 is selected by SELS=1.
    In this case, you should use ACLK on teh timer, which is by default driven by an LF crystal on XT1.

    In any case, you do not wait for the crystal to come up properly, by checking the oscillator fault bits. The procedure is described in the family users guide.

    [/quote]

     

    Sorry, I wasn't clearer on that. I am using a G2231 that shipped with the Launchpad kit.

    The crystal is working now (I had shorted one pin to the ground cap while soldering :-( )

    After some tweaking, I left DCOCTRL and BCSCTL1/2 at their reset values, and set the XCAP on BCSCTL3 to 2'b11 (to select 12pF).

    I set the TASSEL value to 1 (ACLK) and the ISR is working fine.

    Thanks much.

    -Anirban


     

**Attention** This is a public forum