Sunday, January 23, 2011

DS1307 Tinkering

A couple of weeks ago I finally had a chance to assemble the Adafruit DS1307 Breakout Board I bought awhile back.  The DS1307 is a popular real-time clock that communicates with an I2C interface.  The Adafruit board is a really simple kit - the DS1307 itself, a timing crystal, a bypass capacitor, a couple of pull-up resistors for the I2C bus, and backup coin cell.



Once I got the board assembled, I started to interrogate the DS1307 with my Bus Pirate (another recent purchase).  The Bus Pirate is a great tool for testing and experimenting with new hardware.  In a nutshell, it's a device that connects your computer's USB to a variety of common interfaces like I2C, SPI, 1-Wire, etc.  Using the Bus Pirate's command-line interface, one can quickly evaluate a device by sending the appropriate bit patterns and monitoring the response.  There's a bunch of tutorials for the the Bus Pirate at the Dangerous Prototypes web site, including one for the DS1307.  Loosely following that tutorial I quickly verified that my DS1307 was working.




Once I verified the device worked, I wrote a quick and dirty Arduino program to display the time.  My plan was to use the Arduino to directly drive a four-digit seven-segment display I had in my junk box.  I used seven digital outputs for the segments and four additional digitals for each digits common cathode.  Using a timer interrupt routine, the display digits are scanned by setting segment bits high and one of the digit CC lines low every time the timer overflow interrupt fires.  (The source code is over here at github.)



While the display worked, I was disappointed by how dim it appeared.  I slowed down the scan rate by putting a counter dividing variable in the timer ISR, but that didn't help.  It looked dim even when I slowed down the scan rate to 1 second per digit.  (Obviously the scan flicker at that rate is exaggerated, but I wanted to see what effect the scan rate had on the dimness.)   So thinking dimness might be due to the Arduino's inability to source or sink enough current to light the display brightly, I added some driver transistors to the circuit to drive the LEDs from an external power supply.  (Schematic below.) That didn't help either, so for now I'll chalk it up to the display itself and its lack of contrast under my shop light and lack of red filter.  However, the LED segments do seem to glow a little brighter when tested with a power supply, so the transistor approach probably could be made to drive the LED brighter.  But that's for another day...

Saturday, January 15, 2011

Blog Relaunch: PowerBook Surgery

When I started Facebooking and Twittering, the activity on my blog went from little to none.   I hadn't touched it in a couple of years and the Movable Type installation was woefully out of date.  At the same time, the open source hardware movement has inspired me to try to contribute a little here or there...  So I moved the technology-related postings from the past to a new platform (that I don't have to maintain) and decided to start posting bits here and there on what I've been up to in the workshop.

The most recent activity on the bench was major surgery on my laptop.  Now mind you, my laptop is a 6+ year-old Apple PowerBook (PB) G4, so when the power jack got worn out, I thought this would be a good reason to finally upgrade to a shiny new MacBook pro.  However, given my wife's desire for new windows on our home and her quickness to remind me about the Self-Repair Manifesto poster in my workshop, I decided it would be best to take a crack at fixing the laptop myself.   After all, we do have a relatively new iMac in the house, so I have access to a faster machine.  The PB is still perfectly good for development tools like gcc and Eagle (and I don't have to share it), so it's definitely useful for me to keep it around.

First, here are a couple of photos of what I was replacing.  The Apple "Magsafe" connector didn't show up until the MacBook.  What they used on the PowerBook is a modified 3.5 mm phono plug.  The shroud that surrounds it keeps you from plugging it into a regular audio jack and serves as a connection for the green/yellow LED in the plug.  I believe jack/plug combo was failing because their contacts get pitted over time from the arcing that occurs from plugging in an energized power adapter.  Over time, the pitting itself makes the arcing more apt to occur and the problem snowballs.  (More arcing -> more pitting -> more arcing...)  It's difficult to see in the photo, but there are whole pieces of the ring and sleeve missing in the plug.  There are a few spots where only the plastic insulator that sits inside the connector remains.




As noted in a previous post, I have torn my laptop open before using the iFixit Repair Guide.  Once again, their information did a wonderful of guiding me through the process of removing the almost 5000 screws that hold the laptop together.  After about 30 minutes, I got down to the DC input board which is buried under just about everything else, including the motherboard:


Now, before I started this endeavor, I Googled a bit to see if anyone had posted any on doing a similar repair.  I found an blog article where someone replaced the original power jack on a 15-in PB with a standard coaxial DC power jack, which is exactly what I planned to do.  So while I had some guidance, I am glad I did some investigation on my own before blindly following those directions.  What I found was that the polarity marking in the photos did not match what I found by checking continuity and voltages on my own.  (Luckily, the connection between my jack and plug was still working enough so I could measure the voltages on the jack.)  The 15" PB power jack mounted with a different PCB arrangement than the 12" PB, so it's quite possible Apple used a jack on the 12" PB that had a completely different footprint.  Either that, or the guy who wrote the article marked his photo wrong.  Either way, I'm glad I checked things out before smoking my PB's DC-to-DC converter. 

After I removed the DC input board, I did a test fit of the new coaxial jack.  Once I verified everything would fit, I carefully removed the old jack from the PCB:


Then I prepared the new jack with some sort wires and heat shrink tubing.  (Note the PB's insides scattered all over my bench...)

Finally, I reinstalled the PCB and put the machine back together:




As you can see, the PB worked when I put it back together.  It actually took two tries; the first time I put it together, the display had no raster.  I opened it back up and reseated the video cable and success!  I am happy to report that the power adapter works and charges the battery as well.  I guess I have to come up with another excuse to buy that MacBook Pro...

One last note: In the article I cited above, there is a discussion in the notes about a sensing voltage set by a resistor connected to the tip of the original plug.  I decided to leave it out since I only have a 45 W adaptier.  Without seeing the sensing voltage, the PB charges at the slowest rate.  (At least that seems to be the consensus in the article comments.)  I've kept an eye on the power adapter and it doesn't seem to be heating up, so I think I'm safe.