Seven Segment Goodbye

IMG_20130508_222601
One of the reasons I started this blog was to document my side projects and yet it’s been over a month so I decided to write up this little project I did as a warm up. About two weeks ago a good friend of mine was leaving BU for a while and I wanted to make her something special. Thing is earlier in the year I had promised to make her a blinking LED light or something which just got pushed on the call stack and proceeded to be buried by function calls. What followed was the idea to hack together some kind of electronic goodbye card with the parts I had left in my electronics kit the day before she left. As you can see in the picture there are only four components to this design: an MSP430 microcontroller, 4-digit seven segment clock display, AA battery pack, and a DPST slide switch. The operation is simple, at the flip of the switch the MCU is powered on and my message is shown on the clock display. I managed to hack this all together within a few hours.

First order of business was to get the display and MCU setup working on a breadboard. Looking at the datasheet for the display I found that the segments had a common anode for each digit. The solution of course is to multiplex the digits with a refresh rate greater than 60hz using the MCU. Since the only functionality I needed from the MCU pins was GPIO, I simply used wired the MSP430’s port 1 pins to the seven segments and the port 2 pins to the anode of each digit. One thing to note was the MCU I was using had a broken pin which just made the code a little more complicated by not having things map directly to bit positions on the port MMR’s. After wiring it all up though, the first thing I like to do is to simply load up an empty main loop and do a quick hardware debug by directly manipulating the registers in the debugger. This helped me catch a few small errors in wiring and the encoding of the segments.

Then came the task of actually writing the code. In general I tend to program bottom up because I like to break things up into small pieces that can be debugged and incorporated into a larger program. The plan was to light up a digit, multiplex the four digits, translate ASCII text, and finally marquee an entire string. To accomplish this my program basically needed four main components: A slow timer for the marquee, a fast timer for the multiplexing, an ASCII lookup table, and the goodbye card text. To take care of both periodic tasks I setup a single TimerA module for the fast timer with a delay variable for the slow timer. Within the timer handler I had two offset variables. The first offset dealt with the multiplexing of the digits and ranges from zero to four and increments every overflow. The second offset determines where in the message the display is and is incremented every ~500ms. Together, these determine which character to display on the segment by incrementing the base pointer of the message array which is then translated using an ASCII to seven segment lookup table.

With the code written and debugged, I set out to solder the components to a protoboard and make it look nice. Placement was pretty simple given the BOM of five components. Only real design choice I made was to rotate the MCU such that most of its pins had a direct route to the corresponding display pin. All other components such as the battery and switch I placed just for aesthetics. Soldering was really easy with these big through hole components on protoboard. If I had to change anything it would be to use some higher gauge wire than the solid core 24 AWG I had lying around. Routing got a little messy in the end and there’s a huge bundle of wires on the underside. Otherwise, the final product looked presentable and my friend was very happy with the gift.

Just a few last remarks, there remained one last bug that I didn’t bother fixing. Because of the way I handled the offset variables, when the marquee reaches the end of the array the multiplex variable can access memory locations beyond the message which also don’t necessarily lookup a character in the ASCII LUT. The result is some garbage is displayed at the tail end of my message, but I figured the conditional statements required to stop the bug was more trouble than it was worth. Another thing I noticed was a “ghosting” effect on the display early on in development. This is where I learned the importance of having turning off the segment before changing what’s being displayed. In regards to the ASCII LUT though, it was troublesome to find seven segment equivalents for each letter. If it weren’t for the fact that our brains can fill in the blanks for us when reading, the text would have been borderline legible. Next time I do something like this, I’d like to use a much better display and perhaps other components such as buzzers or LEDs on the side. Until then this project serves as a reminder to me as to why I love EE. That ability to create really complicated and fascinating objects both cheaply and easily.

Leave a Reply

Your email address will not be published.