Jump to content
43oh

Launchpad RTC backup battery


Recommended Posts

Hi,

 

I'm approaching LaunchPad after quite some time spent on Atmega MCUs, one of the first projects I would like to make is an alarm clock, the traditional approach I've followed in the past with Atmega was to use an external DS1307 or DS1388, a coin cell for RTC backup and EEPROM to store config and alarms.

 

The display can be either a 4 digits 7-segments or a MAX7219 (or similar IC) controlled 8x8 LED matrix.

 

I've read some posts on this forum about the possibility to use the internal RTC (there is even a lib for Energia), but my question here is if it's possible to use the external 32KHz quartz and the internal RTC instead of using an external DS1388 and still have the possiblity to use a coin cell battery backup to avoid time/date reset on power failures.

 

Am I on the wrong track or is this a feasible project?

Link to post
Share on other sites

The MSP430 (at least the MSP430G value line chips) don't have an internal RTC, they do however have internal timers. Using a little software you can expand these to be RTC. If you want prcision timing you're bount to use either a precicion clock source or a precicion crystal.

As far as I know you cannot power the timer separately from the rest of the MSP430. But you might use a buffer IC at the output and power the buffer from a second battery.

Another solution would be to connect the backup battery and the other power supply both via a diode to the MSP430 power supply, make sure the second power supply is at least a little higher in voltage than the coin cell (otherwise you'd run from the coincell all the time). Then Also feed the second power supply to a general purpose input pin. If this pin is high, you know the secondary power supply is available and you can drive the display, of not, you shut down all functions except the time keeping.

Link to post
Share on other sites

For battery powered system, can be used something like DS1314 (http://www.maximintegrated.com/datasheet/index.mvp/id/2691). MSP430 familly don't have dedicated internal EEPROM, but internal FLASH segments can be used like EEPROM (flashing during program execution outside of program memory space).

 

Thanks for the hints, can you please point me to an example or documentation (if any) about using this technique of using the flash for permanent storage (as EEPROM)? 

 

I assume that every time I re-flash the device with a new program the settings would be lost, right?

Link to post
Share on other sites

The MSP430 (at least the MSP430G value line chips) don't have an internal RTC, they do however have internal timers. Using a little software you can expand these to be RTC. If you want prcision timing you're bount to use either a precicion clock source or a precicion crystal.

As far as I know you cannot power the timer separately from the rest of the MSP430. But you might use a buffer IC at the output and power the buffer from a second battery.

Another solution would be to connect the backup battery and the other power supply both via a diode to the MSP430 power supply, make sure the second power supply is at least a little higher in voltage than the coin cell (otherwise you'd run from the coincell all the time). Then Also feed the second power supply to a general purpose input pin. If this pin is high, you know the secondary power supply is available and you can drive the display, of not, you shut down all functions except the time keeping.

 

Great advice, thanks. 

 

I'm completely new to Launchpad and when I saw that there was a 32KHz crystal in the package I thought that it was for a kind of on-board RTC.

 

Does anybody know what's exactly the reason for including that crystal in the package? Is it for running the MCU at lower speed when it's in one of the low-power modes?

Link to post
Share on other sites

I think you're misreading things. There is a separate 32kiHz crystal shipped in the box where the launchpad is shipped in. The crystal is not embedded in the microcontroller.

If precision clocking is not required, there is a VLO (Very Lowpower Oscillator) embedded in (most of) the MSP430 chip, it's running at about 12kHz but is very inaccurate; there is no way you can use it to keep time. It is very useful for PWM driving and the such, as that is mostly about duty cycle, not so much about frequency. Running in LPM3 enables you to use either the VLO or the external 32kHz crystal while almost all core features are dormant. You can get well under 1uA in those cases.

 

The crystal is useful when you do actually need precision timing. By default the MSP430 will try to enable the oscillator circuit for the crystal. If you don't have it connected or don't want to use it, you need to disable it and switch the ACLK to use a different clock source (or not use ACLK at all). If you search for the MSP430x2xx user guide (slau144i.pdf) the first chapters describe in detail the multiple stages of clock sources, clocks and peripheral clocking. The default (for the chips shipped with the launchpad) is to run ACLK (auxilliary clock) from an externally appached 32kiHz crystal and run MCLK (master clock source, used for the MCU core) at a Digitally Controlled Oscillator close to 1MiHz, the SMCLK (sub-master clock) is clocked from this same DCO source (by default).

 

You have quite some freedom to change clocking speed from the upper 16MHz (or 25MHz on the fancier chips) to the low sub-kHz speeds. For example, I built this LED driver, which sets ACLK to about 3kHz of which I use 3 tick increments to get a PWM resolution of 1msec, while I leave the core running at 1MHz but shut it down as much as possible. I don't use any crystal, as I do not need it.

Link to post
Share on other sites

Thanks for the hints, can you please point me to an example or documentation (if any) about using this technique of using the flash for permanent storage (as EEPROM)? 

 

I assume that every time I re-flash the device with a new program the settings would be lost, right?

 

There is only one problem. When there is some operation on flash, flash can not be used. Function that is making flash updates must be copied into RAM and executed from RAM. After flash updates, program can return to flash area and continue. There are examples "msp430x11x1_flashwrite" in slac011.

 

AFAIK all programers are making mass erase at flashing start. In the case of segment erase other segments are untouched.

 

Does anybody know what's exactly the reason for including that crystal in the package? Is it for running the MCU at lower speed when it's in one of the low-power modes?

 

I never used XTAL1 before. Problem of internal clock sources is precision. If application is sensitive to clock precision, external XTAL1 (or XTAL2) must be used.

Link to post
Share on other sites

I think you're misreading things. There is a separate 32kiHz crystal shipped in the box where the launchpad is shipped in. The crystal is not embedded in the microcontroller.

 

Well, no, I understood that the clock was external, what was misleading to me is that the crystal in the package is the typical RTC crystal 32....KHz. So I thought that it was for some kind of on-board RTC.

 

If precision clocking is not required, there is a VLO (Very Lowpower Oscillator) embedded in (most of) the MSP430 chip, it's running at about 12kHz but is very inaccurate; there is no way you can use it to keep time. It is very useful for PWM driving and the such, as that is mostly about duty cycle, not so much about frequency. Running in LPM3 enables you to use either the VLO or the external 32kHz crystal while almost all core features are dormant. You can get well under 1uA in those cases. The crystal is useful when you do actually need precision timing. By default the MSP430 will try to enable the oscillator circuit for the crystal. If you don't have it connected or don't want to use it, you need to disable it and switch the ACLK to use a different clock source (or not use ACLK at all). If you search for the MSP430x2xx user guide (slau144i.pdf) the first chapters describe in detail the multiple stages of clock sources, clocks and peripheral clocking.

 

I admit that I was a bit scared from that huge document   :smile:  But I will dig into it ASAP.

Link to post
Share on other sites

I admit that I was a bit scared from that huge document :smile: But I will dig into it ASAP.

I understand it's a little intimidating. You'll notice that the lot of it are chapters about each specific peripheral (WDT, Digital I/O, ADC, Timer, etc.). You don't need to touch those chapers until you're actually wanting to use those. I do recommend reading chapters 1, 2 and 5 (intro, system resets... and basic clock) to get a basic idea about the architecture (chapters 3 and 4 about CPU and CPUX are better left alone unless you're writing assembler). Then just skip ahead to chapter 8 (Digital I/O). This will give you plenty of knowledge to get simple demos like toggling an LED running.

You don't need to remember everything, just know that something is in a certain way (like how to switch an I/O line from output to input, the details you can look up later).

It's (in my opinion) important to realize that the MSP430 is designed around the concept of low power, this means that large counting loops to isert a delay are against the ideal of the architecture. You can make a 1 second delay by counting to a million, but you could just as well start a timer that will trip an interrupt after one second. Similar for buttons: instead of looping until a button is pressed, set up an interrupt and go to low power (which will automatically stall further execution of your code).

 

The 32kiHz crystal was added for the very same reason; it's much more low power to use a watch crystal than a mutli-megahertz crystal. You could use it for an RTC, but since it's not implemented in hardware (at least not the ones shipped with the lauchpad) you'd have to run your own code to achieve it:

set a clock to run from the crystal, set a timer to run from the clock, set the timer to overflow once per second, increment a seconds counter on that interrupt.

Link to post
Share on other sites

I understand it's a little intimidating. You'll notice that the lot of it are chapters about each specific peripheral (WDT, Digital I/O, ADC, Timer, etc.). You don't need to touch those chapers until you're actually wanting to use those. I do recommend reading chapters 1, 2 and 5 (intro, system resets... and basic clock) to get a basic idea about the architecture (chapters 3 and 4 about CPU and CPUX are better left alone unless you're writing assembler). Then just skip ahead to chapter 8 (Digital I/O). This will give you plenty of knowledge to get simple demos like toggling an LED running.

You don't need to remember everything, just know that something is in a certain way (like how to switch an I/O line from output to input, the details you can look up later).

It's (in my opinion) important to realize that the MSP430 is designed around the concept of low power, this means that large counting loops to isert a delay are against the ideal of the architecture. You can make a 1 second delay by counting to a million, but you could just as well start a timer that will trip an interrupt after one second. Similar for buttons: instead of looping until a button is pressed, set up an interrupt and go to low power (which will automatically stall further execution of your code).

 

The 32kiHz crystal was added for the very same reason; it's much more low power to use a watch crystal than a mutli-megahertz crystal. You could use it for an RTC, but since it's not implemented in hardware (at least not the ones shipped with the lauchpad) you'd have to run your own code to achieve it:

set a clock to run from the crystal, set a timer to run from the clock, set the timer to overflow once per second, increment a seconds counter on that interrupt.

 

Thank you!

 

This is really a precious roadmap for a beginner like me.

 

I've programmed mostly using Arduino libraries and a little plain AVR c, do you suggest to start experimenting with direct register/port/timers manipulation rather than using Energia libs or is it better doing the opposite and moving to register manipulation only when effectively needed?

 

By using Energia libraries I would probably miss the point in learning the advanced low power and interrupts driven programming style.

Link to post
Share on other sites

Erm... well... there seem to be a lot of people using Energia on this forum. I for one, do think Energia misses the point of the low power architecture that the MSP430 offers. I guess starting out with Energia will start out with a less steep learning curve, but you might end up using practices that are contrary to the idea of the MSP430.

I started out using IAR (you could use CCS just as well) on the then-cheapest MSP430 (MSP430F2012), that was before the value line MSP430s where released.

Although the learning curve might be a little steeper, if you want to learn how to really exploit all the power of the MSP430, I recommend you stay away from Energia libraries (though Energia without libraries is just fine for starting out).

Link to post
Share on other sites

Ok, I will try to learn the inner of the MCU without Energia libraries, I don't really need and IDE (I'm the kind of vim+Makefile programmer).

I've put together the first steps I made in this page: http://www.itopen.it/2013/03/01/msp430-energia-on-linux/ , maybe the Makefile could be interesting for other users.

Link to post
Share on other sites

Cool! I do most of my coding in vim too, then I scp the file to my windows machine and compile it with IAR :smile:

This is mostly because all how-to's I've found so far assume you have root priveleges on the linux machine you're going to dev on... which I do not have :-(

 

Strange. It's the first time I hear that you must be root to compile something on Linux.

Maybe you need root privileges in order to write on /dev/ttyACM* ports and hence to upload the hex onto the device ? This normally can be solved by adding the user to the right group.

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