xv4y 46 Posted May 22, 2012 Share Posted May 22, 2012 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. bluehash, energia, jeshuah and 3 others 6 Quote Link to post Share on other sites
bluehash 1,581 Posted May 22, 2012 Share Posted May 22, 2012 Hello Yannick, Thanks for sharing your code. Keep them coming. AnthonyKl 1 Quote Link to post Share on other sites
HannesBK 2 Posted June 10, 2012 Share Posted June 10, 2012 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 AnthonyKl 1 Quote Link to post Share on other sites
energia 485 Posted June 10, 2012 Share Posted June 10, 2012 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 HannesBK and AnthonyKl 2 Quote Link to post Share on other sites
xiaodoudou172 8 Posted November 1, 2012 Share Posted November 1, 2012 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. AnthonyKl and sirri 2 Quote Link to post Share on other sites
xv4y 46 Posted December 18, 2012 Author Share Posted December 18, 2012 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. AnthonyKl 1 Quote Link to post Share on other sites
roadrunner84 466 Posted December 18, 2012 Share Posted December 18, 2012 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. AnthonyKl 1 Quote Link to post Share on other sites
xv4y 46 Posted December 18, 2012 Author Share Posted December 18, 2012 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. AnthonyKl 1 Quote Link to post Share on other sites
sirri 28 Posted December 18, 2012 Share Posted December 18, 2012 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. AnthonyKl 1 Quote Link to post Share on other sites
Rei Vilo 695 Posted December 18, 2012 Share Posted December 18, 2012 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. sirri and AnthonyKl 2 Quote Link to post Share on other sites
sirri 28 Posted December 18, 2012 Share Posted December 18, 2012 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? AnthonyKl 1 Quote Link to post Share on other sites
xv4y 46 Posted December 19, 2012 Author Share Posted December 19, 2012 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. AnthonyKl 1 Quote Link to post Share on other sites
sirri 28 Posted December 19, 2012 Share Posted December 19, 2012 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.. AnthonyKl 1 Quote Link to post Share on other sites
roadrunner84 466 Posted December 19, 2012 Share Posted December 19, 2012 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. AnthonyKl 1 Quote Link to post Share on other sites
Rei Vilo 695 Posted December 19, 2012 Share Posted December 19, 2012 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. from http://en.wikipedia.org/wiki/Unix_time Unix time to year-month-day hour-minute-second converting functions and libraries are widely available. AnthonyKl 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.