Quantcast
Channel: Forums - Recent Threads
Viewing all articles
Browse latest Browse all 262198

MSP430 Clock with external 32768 crystal goes wrong

$
0
0

Hi!

I have finished my alarm clock now, and i see that it is not synchronous to our other clocks. It is slower.

I have used an MSP430G2553 for that and a 32768 crystal. This is my setup setting:


BCSCTL1 = CALBC1_16MHZ; // clock speed at 16mHz
DCOCTL = CALDCO_16MHZ; // DCO Clock 16mHz
BCSCTL1 = DIVA_3; // clock divider 8

WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer
P1OUT = 0x0; // Drop all outputs to zero by default
P2OUT = 0x0; //Drop all outputs of port 2 too
P1DIR = 0xFF; // set port1 all pins as output
P2DIR = 0x1F;

TACTL |= TASSEL_1 | MC_1 | ID_3; // use ACLC, up mode, divider 8
CCTL0 |= CCIE; // CCR0 timer enabled
CCTL1 |= CCIE; // CCR1 interrupt enabled
CCTL2 |= CCIE;
TACCR0 = 30719; // CCR0 set to 1 minute

It is made to wake up only every single minute to save as much power as possible.

I think the CCR0 has the highest interrupt priority, so only the code in the CCR0 interrupt can cause a problem.

This is the code of the interrupt:

// Port 1 interrupt service routine (CCR0 triggered)
#pragma vector=TIMER0_A0_VECTOR
__interrupt void Timer_A(void)
{
if (ma<3){
if (mp != 27){
mm++; //increase minute counter
if (mm>59){hh++; mm = 0;}; //reset minutes and increase hours if 60 minutes are over
if (hh>23){hh = 0;}; //reset hours if 24 hours are over
TACCR1 = TAR + frequency;
if (TACCR1 > TACCR0) {TACCR1 = frequency;}
sum = 1;
if (am==mm && ah==hh && al==1) {LPM3_EXIT; starttimers(); mp = 40;}
}
}
if(mp==0 && delay == 0 && debounce == 0) {CCTL1 &= ~CCIE;};
if (sleepmins > 0) {sleepmins--;};
if (sleepmins == 0 && sleeptime == 2) {LPM3_EXIT; starttimers(); mp = 40;}
}

The starttimers() function is this:

inline void starttimers(void) {
CCTL1 |= CCIE;
CCTL2 |= CCIE;
TACCR1 = TAR + frequency;
if (TACCR1 > TACCR0) {TACCR1 = frequency;}
TACCR2 = TAR + pwmvalue;
if (TACCR2 > TACCR0) {TACCR2 = pwmvalue;}
P1OUT = 0x00; P2OUT &= 0x1F;
}

I could offer the whole code and schematics if you want, but i think the other parts can not cause the problem because of the interrupt priority.

But i would be happy if someone can tell me what i dont see.

Thanks!

Steffen


Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>