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