Jump to content
xv4y

Real-Time Clock (RTC) Library for the MSP430/LaunchPad

Recommended Posts

Hi,

 

On this page you can find the code for a simple C library using the RTC capabilities included in the MSP430g2553 shipped with the LaunchPad.

I know TI already offer a nice RTC lib but it is in assembler and not easy to compile outisde of the given IDE.

This one has been designed to work under Energia and should be easier to port.

 

http://xv4y.radioclub.asia/2012/05/22/bibliotheque-rtc-pour-le-msp430/

 

Regards,

Yannick.

Share this post


Link to post
Share on other sites

Hello Yannick,

 

thank you for the RTC library. It's very useful for me.

Is works fine with Energia 0005a.

But with 0006 the clock is slow (~2 seconds per "Tick_Tac").

 

Is it possible to fix that for 0006?

 

Thank you

Hannes

Share this post


Link to post
Share on other sites

Energia 0101E0006 sets the ACLK to internal VLO which is about 12KHz typical. The following patch should fix it:

 

--- a/hardware/msp430/cores/msp430/wiring.c
+++ b/hardware/msp430/cores/msp430/wiring.c
@@ -78,7 +78,7 @@ void initClocks(void)
       /* SMCLK = DCO / DIVS = nMHz */
       BCSCTL2 &= ~(DIVS_0);
       /* ACLK = VLO = ~ 12 KHz */
-        BCSCTL3 |= LFXT1S_2;
+        //BCSCTL3 |= LFXT1S_2;
}

#define SMCLK_FREQUENCY F_CPU

Share this post


Link to post
Share on other sites

Hallo I have download your library and it was working fine. But I have a question: why you set the ACLK divided by 8 while the timer clock is also divided by 8? I don't get it.

Huh... well... the truth is that I don't know.

You need to divide by 8 because if not the Timer will overflow. Why I have written is divided by 8 twice ???

 

I guess the comments are not accurate. I have two versions of the library one with a better precision than one second.

I have uploaded updated libs here, but I still need to correct the comments I think :

http://xv4y.radioclub.asia/boutique/docs/

 

Yan.

Share this post


Link to post
Share on other sites

You're doing low-level setup in the constructor of your RTC, and you do not even depend on it. I suggest you change your constructor from

RealTimeClockSec::RealTimeClockSec(void)
{
    RTC_sec = 0;
    RTC_min = 0;
    RTC_hr = 0;
 
    WDTCTL = WDTPW | WDTHOLD; // Kill watch-dog
 
    BCSCTL1 = DIVA_3;        // Clock = ACLK / 8
    BCSCTL3 |= (LFXT1S_0 | XCAP_3);        // Internal 12.5pF cap for 32KHz crystal
 
    TA1CCTL0 = CCIE;             //  CCR0 interupt activated
    TA1CCR0 = 4096-1;               // 4096 ticks of 32KHz XTal = 1 second => CCR0 counts N+1
    TA1CTL = TASSEL_1 | ID_3 | MC_1;  // Clock for TIMER 1 = ACLK, By 8 division, up front
 
};

to

RealTimeClockSec::RealTimeClockSec(void)
{
    RTC_sec = 0;
    RTC_min = 0;
    RTC_hr = 0; 
};

And let the library's user place code similar to

    WDTCTL = WDTPW | WDTHOLD; // Kill watch-dog
 
    BCSCTL1 = DIVA_3;        // Clock = ACLK / 8
    BCSCTL3 |= (LFXT1S_0 | XCAP_3);        // Internal 12.5pF cap for 32KHz crystal
 
    TA1CCTL0 = CCIE;             //  CCR0 interupt activated
    TA1CCR0 = 4096-1;               // 4096 ticks of 32KHz XTal = 1 second => CCR0 counts N+1
    TA1CTL = TASSEL_1 | ID_3 | MC_1;  // Clock for TIMER 1 = ACLK, By 8 division, up front

in their setup() themselves.

 

Also, you could implement operator++() to let a user call the RTC like

myRTC++;

to increment the time.

Share this post


Link to post
Share on other sites

Thanks for the suggestion.

As for low-level init you are right I should do it in another routine as I have done in the AD9850 lib following the structure I saw in Rei Vilo 3110 library.

 

I will try to do this tomorrow, it is a bit late for coding right now...

 

Yan.

Share this post


Link to post
Share on other sites

I guess this is the only Energia RTC Library? Am i right?

My other question is;  Does it work with DS1307 IC just like it works in Arduino? Anyone tried?

Thanks.

 

I tried two RTCs with the MPS430G2553: the DS1307 and the even more integrated PCD2129A (no quartz needed).

 

Both work fine and the Arduino libraries require no special adaptation to run on Energia.

Share this post


Link to post
Share on other sites

I tried two RTCs with the MPS430G2553: the DS1307 and the even more integrated PCD2129A (no quartz needed).

 

Both work fine and the Arduino libraries require no special adaptation to run on Energia.

Thanks. Is it possible to use Launchpad 3.3 V for DS1307, instead of coin cell (3V) Anyone tried that?

Share this post


Link to post
Share on other sites

I guess this is the only Energia RTC Library? Am i right?

My other question is;  Does it work with DS1307 IC just like it works in Arduino? Anyone tried?

Thanks.

Hi,

 

This is for using "inboard" RTC capabilities of the LaunchPad.

If you solder the provided 32KHz Xtal to the LaunchPad board and using the MSP430G2553 internal clocks/timer, you can have a really accurate RTC clock. However, you have to the time calculation yourself. This library only implements time. A little bit more work would allow you to compute days, months, years... The real difficulty is that the UTC calendar is a little bit more complex than just adding numbers, since the Earth rotation is not exactly 365 days, you have bissextiles years, leap seconds...

 

Yan.

Share this post


Link to post
Share on other sites

Hi,

 

This is for using "inboard" RTC capabilities of the LaunchPad.

If you solder the provided 32KHz Xtal to the LaunchPad board and using the MSP430G2553 internal clocks/timer, you can have a really accurate RTC clock. However, you have to the time calculation yourself. This library only implements time. A little bit more work would allow you to compute days, months, years... The real difficulty is that the UTC calendar is a little bit more complex than just adding numbers, since the Earth rotation is not exactly 365 days, you have bissextiles years, leap seconds...

 

Yan.

Thanks. I will work on it..

Share this post


Link to post
Share on other sites

The RTC library does not (or should not) "support" any chip; instead, the user needs to provide a call to the IncSec() method once per second.

It would be nice ofcourse to derive RTC classes from this one that set up clock sourcing themselves. Then a derived RTC could be made for the DS1307 is wanted. At least, that's the way C++ is supposed to work.

Share this post


Link to post
Share on other sites
A solution would be to use the Unix time

 

Unix time, or POSIX time, is a system for describing instances in time, defined as the number of seconds that have elapsed since midnight Coordinated Universal Time (UTC), 1 January 1970, not counting leap seconds. It is used widely in Unix-like and many other operating systems and file formats. It is neither a linear representation of time nor a true representation of UTC.[note 3] Unix time may be checked on some Unix systems by typing date +%s on the command line.

 

 
Unix time to year-month-day hour-minute-second converting functions and libraries are widely available.

Share this post


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...