Monday, August 9, 2010

MSP430 Bicolor LED Clock

When Texas Instruments announced their new Launchpad development platform last month, I jumped on it as fast as I could, considering how hard their e-store went down.  The price was right ($4.30), but more importantly, I've been looking for a way to get into their platform, because I see a lot of future in it.
The MSP430 microcontroller is specifically designed for low-power battery applications, and the Launchpad finally provided me with the tools I need to get into the platform.  I've been wanting to give a battery powered project a shot, but my first project based on the MSP430 core seemed pretty obvious; time to build another clock, but this time battery powered.

Video:


I'm a big fan of minimalism, so I decided to go with a single bicolor LED display, and minimal controls for setting the time.
  • The switch is to select the mode, between displaying the current time, setting the current hour, and setting the current minute.
  • The LED is a red-green LED, which displays the current time upon request.  Green flashes mean 10, yellow 5, and red 1, so the time 5:28 would be displayed as YELLOW [PAUSE] GREEN GREEN YELLOW RED RED RED (5:10+10+5+1+1+1).  It also adds an alternating red-green pattern to the time in the PM.
  • The push button activates the display, bringing the controller out of sleep mode long enough to either blink out the current time, or update the time based on the mode select switch.
 The internals are nothing surprising: small piece of perf board for the controller and the few passives, and a 2xAA battery holders for power, which should last for a VERY long time (rated current draw during sleep is sub-1μA).

Parts list:
  • MSP430G2101 controller (though any MSP430G2 controller with 1k+ of flash should work
  • 32.768kHz quartz crystal. I happened to only have a 6pF one, instead of the more standard 12.5pF, but the crystal oscillator in the MSP430 can be adjusted in software to match either.
  • perf board large enough to fit the controller
  • 1 14 pin DIP3 socket
  • 2x 120Ω resistors for the bicolor LED anodes
  • 1 bicolor red-green LED
  • 1 5mm LED panel mount
  • 1 100μF and 1 0.1μF capacitor for power filtering on the perf board
  • 1 2xAA battery clip
  • 1 4k pull-up resistor for the reset pin
  • 1 NO (normally open) push button
  • 1 SPDT (single pole double throw) switch with center off position
  • 1 gang box and blank cover
The gang box enclosure is particularly unique to this project.  If you buy "new-work" gang boxes, they're only 25-50 cents a piece, depending on if you get the 18 or 20 cu in sizes.  Add to that a 50 cent blank cover, and you have a half decent project box for little more than a dollar.  The one thing to be very careful of is the fact that the white plastic is INCREDIBLY brittle, even when brand new.  You must be very careful when drilling into it, due to its tendency to crack.  Another option is to instead mount the interface on one of the other sides, since the blue plastic box itself drills very nicely.

Schematic:
 Note: TEST should not be pulled high with the reset line.  This makes for unstable uC starting.

Source code:


Update 9/17/2010: Fixed the error in the schematic, and it turns out this project has been reimplemented by one of my readers.  :-)

16 comments:

  1. Kenneth,
    I'm a msp430 newbie and want to thank you for sharing a nice project that was perfect for learning.

    ReplyDelete
  2. how can i get code nd schematic...

    ReplyDelete
  3. Hi Kenneth, very well written.
    Is it alright if we post it in the project section of the 43oh forums? You could also post in there.
    http://www.43oh.com/forum/viewforum.php?f=9

    Your project is also up at www.43oh.com .

    I also like the Launchpad shield idea. Got to know of this place from NJC's blog.

    ReplyDelete
  4. @Amit: Code and schematics are right there at the end of the post...

    @bluehash: Feel free to post this anywhere you want, as long as there's linking back to here. I've been thinking about getting involved in the forums cropping up, but I don't have much more time than the Google mailing list...

    ReplyDelete
  5. There are two types of plastic faceplates: Those made of Bakelite, and those made of nylon (often labeled "unbreakable).

    The two types are often sold side-by-side, sometimes even from the same bin.

    Nylon, of course, is pretty easy to work with. Bakelite, on the other hand...

    ReplyDelete
  6. Cool stuff dude... I too see a bright future in the msp430. I specifically am interested in their RF radio enabled uC's. I picked up the msp430 watch however have been busy with a few other projects so nothing 'cool' yet. :)

    Blog on the watch here:
    https://www.synthetos.com/blog/ez430-chronos-watch-unboxing/

    ReplyDelete
  7. Hi Kenneth,

    I am new to the MSP430 - my launchpad arrived just Monday morning - and want to thank you for contributing this project to the world :). It was very useful for learning about how the usual stuff is done with the device.

    I "ported" your code to work ok with the mspgcc4 compiler (interrupt definitions are different, if I am not mistaken) and added indication of 10s interval and some indication method to differentiate the 3 values (hours, minutes, seconds), which makes the clock much more usable around 0:00 (and helped me to understand that the code was correctly working while I saw nothing after pressing S2 directly after reset... which correctly blinked me only zeros :)).

    I am going to integrate this clock into my living room furniture, so, because random un-techy people are going to play with it, I also adjusted the intervals a bit, to enable these people to read the time without a visual blow to the head :).

    For this code to "work" in mspgcc, just #include and instead of the "msp430G2101.h" and define interrupts as

    interrupt(TIMERA0_VECTOR) TIMERA0_ISR(void) { ... }
    interrupt(PORT1_VECTOR) PORT1_ISR(void) { ... }

    and remove the #pragma lines... that should do it.

    If someone is interested, I can post the code if Kenneth is fine with that. :)

    Kenneth, just a few questions to you...

    fist one: did you ever try to run this clock from a capacitor as backup, while in powersafe? I'd like to add some battery changing backup power source, because setting the clock seems rather hard. Is your 100µF capacitor doing something like that?

    second one: how many bytes of byte code does the compiler you use create from your source? it was quite shocking to me, that your code compiled to just a few bytes less than 1k of code.... giving me the impression that there is not very much room for enhancements when using a 1k-flash device from the MSP430 Value line.

    Greeting from cologne, DE

    Joel

    ReplyDelete
  8. @Joel: Blogger ate your include statements in the tag brackets, but feel free to post all your code and link to it here (I'm vague on IP rights for my code, cause I really don't care that much about an hour of coding). A prominent link back to this page is enough attribution for me. I don't have the 0:00 problem because my clock runs in 12 hour mode, so worst case is 1:00am. I can appreciate slowing it down for others, but once you get the rhythm of it, you really want it to read out fast so you can find out what time it is.

    1. The 100uF cap I put on it is for noise filtering, mainly because I was having stability issues, cause I was pulling the test pin high, which you DON'T have to do. The controller should run fairly long on 100uF as long as it isn't lighting LEDs (I'd expect something on the order of ~2 minutes). I've had one running off a pair of super capacitors for almost three weeks for another project (obviously, it isn't using LEDs). With 100uF, I would expect you to be able to switch batteries as long as you work fast, but I expect these AAs to expire before they're drained by this clock, unless you having it lighting LEDs by itself. Mine requires user interaction to light LEDs.

    2. Did I really get that close? (*looks up obj size*) Guess I did... 844 bytes of text and 6 bytes of data. Well, if you start running out of space, just switch in a 2k chip like a 2211 or 2231, or wait around for some of the larger chips to be released... I just bought an AVR with 128k of flash on it. No reason to kill yourself on space, unless you're into that type of thing.

    I've been meaning to set up a mspgcc tool chain on my Linux box to play with, but I'm pushing through the last week of my summer internship (4+ hrs of OT a day -_-), so I haven't had much (any) free time. School started next week, so I'll finally have some free time again.

    Keep up the good work. I'm very heartened to see my stuff helping others get started.

    ReplyDelete
  9. Thanks for all the info... I will try with a 1500µF then for off-battery duty. I just tested it and well... The capacitor survived blinking out the time once (fading though). I am more doubtful, if the internal resistance of the capacitor might drain the batteries faster than that µC in low power state would :).

    The information on the test pin was very valuable. Should one pull that pin to GND then or is it safe to keep it floating?

    Keep going, though. The week is coming to an end tomorrow (at least here... from your timezone, its another day to go), so, I guess, will your internship. Thank you again... I will release the modified code once the clock is running.

    ReplyDelete
  10. I would look that up in the MSP430X2 user manual. I recall seeing a table as to how to treat unused pins...

    ReplyDelete
  11. Hi Kenneth,

    Nice work! I ran your code on the LaunchPad development board with the 32.768kHz crystal installed. I like how your code uses the same pins for the leds and the time display switch on the board (I had to add jumpers for the mode select). I did have to change TACCR0 to 0x1000 get the timing to work. The board uses a MSP430G2231, maybe thats why??? I will investigate further.

    Mike

    ReplyDelete
  12. I found the problem. One of the crystal connections had a bad solder joint. That sure is small!

    ReplyDelete
  13. does this need a 32khz crystal or can i just un conect the osc. pins

    ReplyDelete
  14. @Anonymous: The time keeping absolutely requires the 32kHz crystal. The internal oscillator has a frequency tolerance of something on the order of 5%. Low-grade quartz watch crystals are on the order of 20ppm (parts per million), which is still more than half a second per day, but isn't several minutes. Feel free to experiment without the crystal and report back your findings; they'd be an interesting statistic.

    ReplyDelete
  15. so i tried it with no crystal but no luck it has been on all after noon and the time is the same as when i set it 4:12 pm and it is now 7:58 pm
    i am using the msp430g2211 and have left its internal osc. at default which i assume to be 1mhz but i stand to be corrected on this
    anyway it says that when the chip enters Lpm1 that the dco is disabled if it is not in use in active mode so maybe the clock is getting turned off, ill have to experiment more so if any one can give more info on the LPM thing or how to reset the internal osc. on the chip it would be much appreciated

    ReplyDelete
  16. Hey!
    I have a problem: MSP430: GEL: Encountered a problem loading file: C:\Users\pc\workspace_v5_2\ura\Debug\ura.out Could not open file
    what should i do?

    ReplyDelete