Jump to content
43oh

RTC on F53xx - couple minutes drift


Recommended Posts

Hi!

 

I program RTC module on MSP430F5342 with code from MSP430F543xA Code Examples. ACLK (32768 quartz) run RTC. 

After one day running CPU in LPM3 and update RTC time to LCD every minute, I get a couple of minutes error. What could be wrong for so much big error in one day?

 

Internal cup for XTAL is default (12.5pF). I measure quartz and it is in predicted range (32768.xx).

 

Any suggestions or ideas?

Link to post
Share on other sites

I'm sure someone more knowledgeable than I will chime in....

 

If it's the same on 10 identical boards, I might think (and I'm new at this), since you're running fast, you don't have enough load capacitance, i.e. the caps are too small. So they charge and discharge at a rate that doesn't complement the crystal's characteristics, and thus the crystal oscillates a little bit faster than expected.

 

I don't have any experience with PCB design, but is it possible that the boards themselves, the way the traces route and such, may be affecting the crystal's requirements?

 

I do have RF experience and have seen things where something so small as a sliver of coax can affect VSWR and such, so I can imagine simple, subtle changes from "reference designs" could make a large difference in actual performance.

Link to post
Share on other sites

Using 32768Hz crystal at +30 ppm should result in ~2.6 second deviation per 24 hours.

 

Are you sure you are enabling the crystal correctly, and not REFOCLK?

 

Capacitance matching of course makes a difference.  Of course, your code makes a difference.  TI code is not always perfect.  Make sure that it lets the RTC run without stoppages, or value changes.

 

Power supply probably does not matter.  I am not reading the datasheet now, but I seem to remember that MSP430F5 devices have internal regulators for the core and crystal driving.

Link to post
Share on other sites

Thank you all for all ideas, problem is solved for now!

 

Problem was in software (quartz settings).

 

In the beginning, I used that kind of code (witch is obviously wrong) to initialize 32768 quartz :

 

// Set MCLK, SMCLK, ACLK
UCSCTL4 = SELS0 | SELS1 | SELM0 | SELM1;// MCLK = SMCLK = DCO, ACLK = 32kHz
// ACLK = 32768kHz
P5SEL |= (XIN | XOUT);					// P5.4, 5
UCSCTL6 &= ~(XT1OFF);                   // XT1 On
UCSCTL6 |= XCAP_3;                      // Internal load cap 
do
{
	UCSCTL7 &= ~XT1LFOFFG;              // Clear XT1 fault flags
}while (UCSCTL7&XT1LFOFFG);             // Test XT1 fault flag

 

After that I found "MSP430F543xA, MSP430F541xA Code Examples (Rev. C)" and right code for initialize 32768 quartz.
I also give MCU a little delay to settle down quartz at power on :

// Set MCLK, SMCLK, ACLK
UCSCTL4 = SELS0 | SELS1 | SELM0 | SELM1 | SELA_0;// MCLK = SMCLK = DCO, ACLK = 32768kHz	
P5SEL |= (XIN | XOUT);					// P5.4, 5
UCSCTL6 &= ~(XT1OFF);                   // XT1 On
UCSCTL6 |= XCAP_3;                      // Internal load cap
delay_ms(100);				
// Loop until XT1,XT2 & DCO stabilizes
do
{
     UCSCTL7 &= ~(XT2OFFG + XT1LFOFFG + DCOFFG);
	                                // Clear XT2,XT1,DCO fault flags
SFRIFG1 &= ~OFIFG;                      // Clear fault flags
}while (SFRIFG1&OFIFG);                 // Test oscillator fault flag

Now RTC work fine. Deviation of time is in tolerance borders of quartz.

 

 

After that I dig a little deeper in RTC module. I think I found a little bug in code examples "MSP430F543xA, MSP430F541xA Code Examples (Rev. C)", in "msp430x54xA_RTC_02.c" example, when you initialize "Day Of Week".
In data sheet of RTC, for Day Of Week register write that days are marked from 0-6 [0 = Monday, 1 = Tuesday...]. 
But in code example "msp430x54xA_RTC_02.c" Monday is marked with "0x01".
Should Monday be commented by "0x00" ?
 

Link to post
Share on other sites

It seems that first day of the week is Sunday! If we look at Example 4 in "Real-Time Clock Alarm Function", there say that Tuesday is "0x02".

So, there is no error in two post back mentioned bug in code samples.

I usually start week with Monday, so I didn't think of it:)

 

@Level 1: I didn't know that 32k LFXT port has more than one driving options. I'll check that!

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...