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.

Using MSP430G2231 as I2C Real Time Clock

Other Parts Discussed in Thread: MSP430G2231

Hi,

 

I have been attempting to use the MSP430G2231 as an I2C real time clock, however, I have been encountering quite a bit of time drift (on the order of several minutes in a day).  I am using Micro Crystal 12pF 20ppm part that is on evaluation board, which should only have a drift of 1.7 seconds a day.  I would appreciate any suggestions on how to better implement this.  My current implementation is as below:

My RTC timer is setup as:

     TACTL = TASSEL_1 + MC_1 + TAIE;
     TACCR0 = 32767;

With the interrupt routine simply:

     #pragma vector=TIMERA1_VECTOR
     __interrupt void Timer_A(void)
     {
         switch( TAIV ) {
             case  2:  break;                        // CCR1 not used
             case  4:  break;                        // CCR2 not used
             case 10:
                 realTimeClockSeconds++;
                 break;
         }
     }

I also have a USI interrupt routine with an I2C slave state machine, which will handle requests to set the realTimeClockSeconds variable or to read back the variable.

  • The oscillator may have stopped and restarted. Or it may have picked up noise and generated extra cycles.

    Was it too fast or too slow? If you check it every 15 minutes, how much inaccuracy do you see?

  • The clock runs slow.  It was giving me several minutes of skew over the span of a day.  I have since fixed a floating digital line issue, removed the 12pF capacitors I had on the crystal and de-soldered the crystal from the ground plane and now I am down to a few seconds worth of delay over a period of 12 hours.

    While this is much better, and probably tolerable, I want to know if I am handling this crystal properly.  Right now I have it connected through 0 Ohm resistors to the XIN/XOUT pins, no capacitors, no ground plane connection.  I am using the Micro Crystal 12pF 20ppm part that came with the LaunchPad kit.  On the LaunchPad schematic, it has 12pF capacitors to ground on each crystal line, but they are not placed.  The footprint on the board has a ground connection for the crystal body, but the schematic also says not to place that connection.  How should this be handled?

    Thanks!

    Justin

  • The crystal has its 20ppm only if the load capacitance is exactly the specified value. Anything below or above will cause a significant drift.

    And capacitors are notoriously unprecise. Not to mention the parasitic capacitances by the PCB.
    The internal load capacitance of the MSP isn't that bad, but if you need precision, then use a lower internal capacitance and add an adjustable external capacitor. Then calibrate it by hand. I do it this way and get <10ppm.

    Keep in mind that 0Ohm resistors create a small inductance (as well as vias) which also influence crystal oscillation.

    The ground connection for the crystal body should be used or not based on the crystal datasheet. Sometimes, the given load capacitance already takes the case capacitance into account, sometimes the case is part of this value and needs to be subtracted from the load. Grounding the case is not really necessary, but improves EMI.

    Nobody said that crystals are easy stuff. :)

  • Thank you for such a detailed response. In my next revision, I will be removing the 0 Ohm resistors.

    I did not realize that the xin/xout line capacitance was software configurable.  That is very handy.  In fact, while researching this I was able to find an MSP430 configuration guide for this line of crystals from the manufacturer's website. http://www.mcrystal.ch/Support/Support.aspx

    Neither the datasheet for the crystal, nor the design guide mentioned how to handle the crystal body connection, so I contacted Micro Crystal.  They stated that it will work either way, but they recommend grounding the crystal body.

    I do have a question regarding configuring the capacitance in software, however.  I added the following line to my initialization code.  Is this the proper way to handle it?

        WDTCTL = WDTPW + WDTHOLD;                    // Stop WDT
        P1DIR = 0xFF;
        BCSCTL1 |= XCAP_2;
        if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF) { 
            while(1);
        }
        BCSCTL1 = CALBC1_1MHZ;               // Set DCO
        DCOCTL = CALDCO_1MHZ;

        ...

  • Justin Forrester said:
    they recommend grounding the crystal body

    It improves EMI (less emission and less sensibility for external EMI) But indeed not vital.

    Justin Forrester said:
    Is this the proper way to handle it?

    Yes. And no. It depends on the previous (default) setting. XCAP is a bitfield. ORing XCAP_2 will set all bits that are in the bit pattern of XCAP_2, but keeps all bits set that are previously set already. The default is XCAP_1, so you'll end up with XCAP_3. (XCAP_1|XCAP_2 = XCAP_3)
    Also, XCAP is in BCSCTL3 register. ;)

    So the proper way would be
    BCSCTL3 = (BCSCTL3 & XCAP_3)|XCAP_2;
    clear the whole bitfield first, as XCAP_3 is the maximum and has all bits of teh bitfield set, then OR XCAP_2 in.

**Attention** This is a public forum