Jump to content
xv4y

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

Recommended Posts

Hi,

 

I have updated the library to be a little bit cleaner :

http://xv4y.radioclub.asia/2012/12/19/bibliotheque-rtc-pour-energia-version-1-02/

Here's the downloads page :

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

 

And, well, guys, I am sorry but I don't think I will put much more work on it.

It works for my purpose, so...

I have a DS1307 in my hands but will hook it to an Arduino for a "weather station" project I have. The Arduino having the EEPROM embedded is more suited for this project as it allows to save measurements and compute statistics...

 

Yan.

Share this post


Link to post
Share on other sites

it is working,thanks xv4y. But it is (seconds) around 2 times slower. How can we fix that? I am using the latest Energia and soldered the crystal to my launchpad rev 1.4 (2553 chip) thanks.

 

edit: after some trial and errors i have noticed if i change below on sRTC.cpp the seconds are almost accurate (maybe one second error in one minute) i believe that accuracy can be improved.

 

here is the change it worked for me, in case some beginner like me uses:

    TA1CCTL0 = CCIE;             //  CCR0 interupt activated
//    TA1CCR0 = 4096-1;               // 4096 ticks of 32KHz XTal = 1 second => CCR0 counts N+1
  TA1CCR0 = 1568-1;
    TA1CTL = TASSEL_1 | ID_3 | MC_1;  // Clock for TIMER 1 = ACLK, By 8 division, up front
 

Share this post


Link to post
Share on other sites

Hi Sirri,

 

Your workaround should work but the problem is not here.

The problem is that by default, Energia is sourcing the ACLK from the VLO 12 KHz instead of the 32KHz crystal.

This make the RTC around 2-3 times slower.

We should be able to change this by settings in the sRTC lib code but unfortunately it does not work as expected.

Rob is currently working on this issue :

http://forum.43oh.com/topic/2993-new-energia-release-0101e0009-12062012/page-2

 

For now, the right solution is to go inside Energia files to edit the hardware/msp430/cores/msp430/wiring.c file and comment out the line BCSCTL3 |= LFXT1S.

 

Regards,

Yan.

Share this post


Link to post
Share on other sites

Hi Sirri,

 

Your workaround should work but the problem is not here.

The problem is that by default, Energia is sourcing the ACLK from the VLO 12 KHz instead of the 32KHz crystal.

This make the RTC around 2-3 times slower.

We should be able to change this by settings in the sRTC lib code but unfortunately it does not work as expected.

Rob is currently working on this issue :

http://forum.43oh.com/topic/2993-new-energia-release-0101e0009-12062012/page-2

 

For now, the right solution is to go inside Energia files to edit the hardware/msp430/cores/msp430/wiring.c file and comment out the line BCSCTL3 |= LFXT1S.

 

Regards,

Yan.

Hi Yan,

Your library is awesome and i am getting closer to my own Light Alarm : ) thanks to you. Is there a way to set up the time? (For example current pc time > msp430 or at least a method to set it up manually?)

Thanks,

Sirri

Share this post


Link to post
Share on other sites

Hi Yan,

Your library is awesome and i am getting closer to my own Light Alarm : ) thanks to you. Is there a way to set up the time? (For example current pc time > msp430 or at least a method to set it up manually?)

Thanks,

Sirri

Hi,

 

Well, yes. The method is called settime and takes 3 parameters : hours, minutes and seconds...

The library by itself does not communicate with anything, but using Serial you could ask for 3 values and then set them as time...

 

Yan.

Share this post


Link to post
Share on other sites

I've finally solved the problem with it running slow on Energia 9.
I also had the problem where it was running slow, and if I commented out the BCS3CTL line in wiring.c the clock wouldn't start at all.

After a lot of mucking around I finally came up with the following solution. My file is based on version 1.03 of your source.

I took all the clock commands out of the constructor, so all it does is initialise the variables, and moved them to the Begin function.  My Begin now looks like the following:

void RealTimeClock::begin(void) {
     

    BCSCTL1 &= ~DIVA_3;     // ACLK without divider, set it to DIVA_0

    P2SEL |= (BIT6 | BIT7); // This is to override default Energia settings that set P2_6 and P2_7 to GPIO instead of ACLK
    BCSCTL3 = (LFXT1S_0 | XCAP_3);// Override default Energia setting sourcing ACLK from VLO, now source from XTal

     
    TA1CCTL0 = CCIE;             //  CCR0 interupt activated
    TA1CCR0 = 128-1;             // 4096 ticks of 32KHz XTal = 1 second, so 4 slices are 1 second => CCR0 counts N+1
    TA1CTL = TASSEL_1 | ID_0 | MC_1;  // Clock for TIMER 1 = ACLK, No division, up mode
     
};

 

 

I noticed that in your version 1.02 of RealTimeClockSec, you have moved the clock initialisation to Begin() but it doesn't work. But the version of Begin() in that file doesn't have the lines to reset Bit 6 & 7 of P2. I suspect that something is playing with P2 after the constructor runs.
 
I have left the comments the same that you had in your original file, but I suspect they are wrong, because the comment talks about 4096 ticks, but you set TA1CCR0 to 127 ??
 
Also, could you please explain the change to BSCTL1? - I tried commenting that line out and it still worked correctly, what does it do?
 
BTW - thanks so much for your work on this library - I am no going to try modifying it to do date as well.

Share this post


Link to post
Share on other sites

Hi Grahamf72,

 

Thanks for searching around this problem.

I have tried to place the lines in both begin() and the constructor but without success.

Tomorrow I will try to put everything in the begin() as you have done.

If it works ok I will publish it as 1.04.

You can send me your full name in PM if you want acknowledgements.

 

I have tried to do some clean up in the comments but perhaps they are not accurate.

I try to maintain two versions of the library, one with one second accuracy for low CPU overhead and ok for most applications, one with better accuracy for my own needs.

Sometime I do copy-paste from one to the other and forgot to change comments...

 

Yan.

Share this post


Link to post
Share on other sites

Hi and thanks for your sharing !

 

I had issues with your lib (last version you just released) : compilation is OK but I only get zeros (reading by connection) with this code (energia 1E00009 and MSP430G2553) :

 

 

#include <sRTC.h>

RealTimeClock MyClock;


void setup(){
  Serial.begin(9600);
  MyClock.begin();
}

void loop(){
  delay(500);
  Serial.println(MyClock.RTC_sec);} 

#pragma vector=(TIMER1_A0_VECTOR) __interrupt void Tic_Tac(void) {   
  MyClock++;            // Update chunks  
}

 

Note that your interrupt sketch proposed in your .h doesn't compile.

 

Regards,

Share this post


Link to post
Share on other sites

 

Hi and thanks for your sharing !

 

I had issues with your lib (last version you just released) : compilation is OK but I only get zeros (reading by connection) with this code (energia 1E00009 and MSP430G2553) :

 

 

#include <sRTC.h>

RealTimeClock MyClock;


void setup(){
  Serial.begin(9600);
  MyClock.begin();
}

void loop(){
  delay(500);
  Serial.println(MyClock.RTC_sec);} 

#pragma vector=(TIMER1_A0_VECTOR) __interrupt void Tic_Tac(void) {   
  MyClock++;            // Update chunks  
}

 

Note that your interrupt sketch proposed in your .h doesn't compile.

 

Regards,

 

You have to put the interrupt declaration outside the loop, your code is not correct.

I will had an exemple sketch to my lib this evening...

 

Yan.

Share this post


Link to post
Share on other sites

Huh, sorry sorry.

I was lost with your loop closing } being at the end of the line.

Well unfortunately now it's close to 11pm local time and I will have a look at it tomorrow...

 

Regards,

Yan.

Share this post


Link to post
Share on other sites

 

Hi and thanks for your sharing !

 

I had issues with your lib (last version you just released) : compilation is OK but I only get zeros (reading by connection) with this code (energia 1E00009 and MSP430G2553) :

 

 

#include <sRTC.h>

RealTimeClock MyClock;


void setup(){
  Serial.begin(9600);
  MyClock.begin();
}

void loop(){
  delay(500);
  Serial.println(MyClock.RTC_sec);} 

#pragma vector=(TIMER1_A0_VECTOR) __interrupt void Tic_Tac(void) {   
  MyClock++;            // Update chunks  
}

 

Note that your interrupt sketch proposed in your .h doesn't compile.

 

Regards,

 

I'm just about to head out to work so I haven't had time to try your code, but I'll have a look at it this afternoon (my time) if it hasn't been solved by then. In the meantime though, a quick look at it makes me think your problem might actually be an implicit type conversion in your call to Serial.Println.  Can I suggest the following to help debug:

 

Create a global integer variable - "int testcounter" or similar above your setup() function. In your setup() make testcounter a non-zero value, eg testcounter=10. In your loop, print the value of that counter to the serial port, with a call to Serial.Println.  In your interrupt add a line "testcounter++".  This will show whether your interrupt code is getting called. If testcounter increments, then the problem is most likely the type conversion when you print RTC_sec. If testcounter doesn't increment then we know the problem is that the interrupt function isn't getting called.

 

For the record, I had absolutely no problems getting the interrupt function given by xv4y to compile, and I am using 0009 and 2553.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×