Hello all,
I need some suggestions on how to get a stable clock from a 32kHz crsytal on MSP430F2274 using MSP-TS430DA38 target board. I am using the code as below:
The crystal I am using is a tuning fork crystal which requires a 12.5pf load. I am setting the internal cap. to be 10 pf.
#include "msp430x22x4.h"
int sec;
char one,two,three,four,five;
void send_data(int datas);
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
BCSCTL1 = CALBC1_8MHZ; //BIT0
DCOCTL = CALDCO_8MHZ;
BCSCTL2 |=0x40; // Set MCLK to 8 MHz and SMCLK to 8Mhz
BCSCTL3 |= XCAP_2 + LFXT1S_0;
P1DIR |= 0x01; // P1.0 output
P2DIR |= BIT0;
// Loop until 32kHz crystal stabilizes
do
{
IFG1 &= ~OFIFG; // Clear oscillator fault flag
__delay_cycles(500000000); // Delay
}
while (IFG1 & OFIFG); // Test osc fault flag
P2SEL |= BIT0;
//*******************************************************//
TACCTL0 = CCIE; // TACCR0 interrupt enabled
TACCR0 = 31250 - 1;
TACTL = TASSEL_1 + MC_1; // ACLK, upmode
__bis_SR_register(GIE); // interrupt
for(;;);
}
// Timer A0 interrupt service routine
#pragma vector=TIMERA0_VECTOR
__interrupt void Timer_A (void)
{
P1OUT ^= 0x01; // Toggle P1.0
sec++;
}
I am routing the ACLK on one of the port pins. When i measure the frequency on that pin i get about 31.8kHz for some time and then it will drop to a very low frequency like 133 Hz or something close to it. So, I know that the crystal works for some time and then it fails.
Please advice on how to get a stable clock.