Monday, April 30, 2012

Fixing a Dead Kill A Watt

The Kill A Watt is a neat little device that you can plug into your wall, then plug other devices into it, and it will give you continuous readings of how much energy it is using, line voltage, power factor, and total power consumed.  I had never bothered to buy one, because my dad and I put together a similar device well before this was available, using just a gang box, some banana terminals, an amp meter, and the ability to multiply by 120 in our heads.

As luck would have it though, one of my friends was kind enough to gift me a dead Kill A Watt that died while he was testing exactly what they mean when they say "do not use for loads greater than 15A."  I was optimistic that this repair would involve little more than replacing a fuse.
It would have been kind of nice if they had used a glass fuse holder in it, but it turns out they used a through-hole 15A 250VAC fuse, which is the silver cylinder to the left of the receptacle.

An entertaining point to notice is that the load resistor, which the Kill A Watt measures the voltage across to figure current, isn't really a resistor at all, but simply a piece of heavy gauge copper wire, marked R2.
Instead of replacing it with another through-hole fuse, I decided to scrounge an in-line glass fuse holder from my junk box.  These come wired to themselves, which is a little bizarre, but are meant to be cut in the middle and wired into whatever circuit you want to protect.  The red end-cap on the top is held on with a bayonet  connector, and the cylinder has a spring-loaded base to hold the fuse.
Snip, solder, twist, insert 15A glass fuse, bam.  Working Kill A Watt.
I really appreciate why so many people (notably AdaFruit) elect to build power monitoring projects using these; the case is ENORMOUS!  Even with this huge extra fuse holder inside the case, I still could have thrown a party in this thing.  Perhaps I'll eventually hack some networking smarts into this thing, but it may justify its existence as it is, as something easier to deal with than an amp meter.  Amazon is currently selling them for the surprisingly low $17.

I am not so much a fan of how the Kill A Watt manages to cover five outlets when you plug it in, but I guess most people actually plug devices into those things mounted in the walls, and not exclusively power strips like I do (my 15 outlet data center power strip helps, but I still have three more normal-length strips chained off of it).

Tuesday, April 24, 2012

ATMega Oscillator Stability

Now that I have my HP 5328A frequency counter up and running, I figured I'd show you the contrast between the stability of the internal RC oscillator built into the ATMega328 (the brains of the Arduino) and the external 16MHz crystal that you usually need to use with it.


Datasheets referenced in the video are for the ATMega328P and a random 16MHz crystal I found on Digikey.  I bought the specific crystal used for this demo on eBay, so I know almost nothing about it, but these crystals are usually rated in the range of 20-50ppm.

The two avrdude commands I used were:
avrdude -p m328p -c usbtiny -U lfuse:w:0x86:m -U hfuse:w:0xd9:m
avrdude -p m328p -c usbtiny -U lfuse:w:0xa2:m -U hfuse:w:0xd9:m

This really demonstrates how both oscillators, but particularly the internal one, are very sensitive to temperature changes around the microcontroller.  This is why my counter's oscillator is contained in a small oven, such that it's held at a specific elevated temperature and doesn't change temperature along with the room.  Another compensation option is to not try and control temperature (which takes a lot of power), but instead merely compensate for it.  High-end real time clocks such as the DS3232 do this, by measuring the ambient temperature and trying to compensate the crystal in the other direction.  It's better than nothing, but this does still introduce uncertainty.

When buying this counter, I specifically looked for one with the HPIB  option on the back, because it means that I will eventually be able to connect this meter up to my computer and take these measurements over a LONG period of time.  Once that is possible, we can start asking more subtle stability questions about better oscillators, such as real time clocks, and even my Rb reference.

Sunday, April 22, 2012

HP 5328A Universal Counter Teardown

Last quarter I decided that I needed a good universal counter for a few of the projects I had in mind for this summer.  A universal counter contains a high quality time reference, which it uses to measure and count external events for you.  The simplest example is to count frequency; the universal counter resets a counter, waits a second, and then saves the value counted up to.  This count would be the number of cycles in one second, commonly referred to as Hertz.  There are numerous other function available on these, including measuring the period of a signal (which is the inverse of Hertz), measuring the interval between two events on different signals, or the ratio between two different frequencies.

Why I specifically chose the HP 5328A model was because it has a BNC connector on the back panel which allows you to feed in an external time base.  Even with a "good" crystal oscillator as the counter's time reference, you can still build a "better" oscillator by stabilizing a crystal oscillator in an oven, or even using an atomic oscillator like my Rubidium reference, which I managed to kill yesterday.

Unfortunately, while bidding on a few of these on eBay, I accidentally bought two of them.
You see, one of them had a broken power switch.  A trivial fix, so I figured "meh; I'll put in the minimum bid, and then not be too disappointed when someone else outbids me." No one ever out-bid me, which I did not expect, so I got an amazing deal on this one, in addition to the moderately good deal I got on the other one (which I'll show you at the end of this post).  I figure fixing this switch shouldn't be too bad, then I can sell it on eBay as not broken, and at least cover costs.

So this simple fix to pop open the box, desolder the switch, and replace it.  Turns out, by virtue of having no idea what I was doing, I approached the problem from the entirely wrong direction.
Four screws were all that I needed to take out to remove the display module...  Two of them are indicated above, and the other two are directly below them on the bottom.  Trust me, I felt very silly after tearing apart the entire tool to realize that I could have just popped out those four screws.  To make up for this silliness, I figured that while I had it completely torn apart, I may as well take some pictures of it for ya'll.
This is the 10MHz time base which the counter uses to measure everything against.  It's rather unique being in a TO-5 package; I've only ever seen oscillators in the 0.3"x0.3" square cans you see in modern equipment.  The trim pot next to it is presumably for calibration.  With my GPS receiver, I was tempted to try and calibrate it, but figured it may be more kosher to just leave it as-is and tell the next owner what its offset is.
I was toying with the idea of salvaging out some of the option modules that didn't happen to be loaded in the other counter, but it seems HP went as far as not even soldering in the edge connectors for options not ordered. So much for that plan...
Look at that purdy power supply; gold traces and everything.  That fan is horribly loud, and if I weren't selling it, I'd probably replace it with a modern fan.  I measured it and it seemed to be a standard size, but as I now write this post I can't remember what that was...
I meticulously removed all of the screws and nuts holding the frame to the face plates before realizing that they were actually holding the face plates to the frame.  My roommate can attest to me actually having the counter's super structure half disassembled before one of the modules just fell out... Man I felt stupid.
Front of the display module.  The plastic parts of the knobs are broken off as well; I didn't notice that in the eBay pictures...
With the face plate off. Bunch of 7 segment displays in DIP sockets, and standard size switches and 3mm LEDs.
I enjoyed that all the cards were connected by big fatty edge connectors.
This is the "universal input module," which allows you to selectively monitor signals using either a 1MΩ or 50Ω termination, instead of only the 1M option in the standard model. It also seems to have some more intelligent circuitry as far as edge-sensing.
Universal Input Module with face plate off.
Annnd back view.
I definitely removed way more than I needed to to get to the display module...
One trip to Halted with the broken part, and for $1.49 I got a close enough match to solder back in, reassemble the whole affair, and we've got a perfectly functional counter again!

Now looking at my other counter, which I did pay a bit more for, we have the amazing luck of seeing the only three options that didn't happen to be install in the first counter; the oven-compensated oscillator, the HPIB IEEE-488 network card, and the option C 500MHz channel.
 This giant silver box replaces the little TO-5 oscillator in the first counter.  What it has in it is a thermostat, a heater, and a bunch of insulation around the crystal oscillator, such that regardless of how much the ambient room temperature changes, the oscillator is always at a single temperature point, preventing the drift caused by temperature change.  The heater in this continues to run even when the counter is turned off, so I plan to make a point of leaving it unplugged until a few hours or a day before I think I'll happen to need to use this counter.
 This is the network card which allows you to control and monitor the counter over an IEEE-488 bus, which is a 24 pin parallel network specification for scientific equipment.  I haven't been able to find any adapters from 488 to anything I can talk to for less than a couple hundred dollars online, but it isn't too difficult of a protocol, so I expect I'll eventually build a 488-to-USB adapter.
 These are the channel A, B, and C capture cards, which need to feed into both the network card in addition to the local display logic.  The local interconnect is through the bottom motherboard, but the network card connections are all of the colorful ribbon cable you see.
 This was another relatively novel chip package I've never seen in the wild before; a ceramic quad flatpack. It's a strange surface mount package because of how ridiculously long the leads are, which were used because it made for a more robust physical mounting.  If memory serves, this package was often required in dynamic applications such as military equipment.
Finally, here is both of my counters measuring the same 1pps taken from my AdaFruit GPS receiver.  The lower one with the oven-compensated oscillator (which is marked as being calibrated in 1999) is spot on, while the top counter using an unprotected crystal oscillator drifts up and down 0.1-0.2ppm, and is almost 5ppm slow.  It's likely most of this difference could be removed with some calibration (or its previous owner not dropping it ಠ_ಠ), but even just watching the stability makes for a marked demonstration of the difference the option 010 oven makes.  The standard time base is rated for 2.5ppm drift between 0 and 50 degrees Celsius, where the option 010 time base has the much tighter 0.007ppm.  Since these counters display eight (or nine) digits, 2.5ppm is very visible, where 0.007ppm will at worst only effect the least significant digit.

So, if you've been pining for test equipment that typically retails for a couple thousand dollars, and don't happen to have that type of cash laying around, eBay is an option to get equipment in the $100-$300 range that at the most need some trivial TLC before being a perfectly serviceable piece of equipment.  Better still if you can either hack together or get access to a good standard to calibrate it against.

Saturday, April 21, 2012

DP-9 Connector Breakout Board


Why You Should Take the Time to Build Yourself the Proper Tools

I'm really kicking myself tonight; I was working on my frequency counters, and finally got them into a state working enough that I was able to fire up my Rubidium frequency reference and phase compare it to my GPS time source and see if there is a measurable difference between them.
This is my Rubidium frequency reference.  It outputs a very good 10MHz sine wave, and a TTL one pulse per second, both derived for an intrinsic physical property of elemental Rubidium, meaning this is something on the order of a million times more accurate than your typical wrist watch.  The Rb reference needs both 5V and 15V, for the TTL logic and the heater, respectively.  I want you to notice how I have 15V stupidly fly-wire clipped next to all those TTL I/O pins on the same DB-9 connector...

I came to regret that tonight.  I bumped the setup, and managed to short the 15V power pin to the /LOCK pin, putting 15V onto all of the logic, and made both my Rb reference and power supply very cranky.  This released the magic blue smoke from my Rb reference, which now has little use beyond being an impressive, but painfully expensive, heated drink coaster...
This was stupid, because I was cutting the corner of sitting down and only taking the 15 minutes it would take to build the proper breakout board.  People don't appreciate this, and I'm certainly guilty of this, but when you're working on a project, you (should) often end up spending more time building the jigs, frames, and target boards that will make the project turn out better than actually working on the final project itself.

It isn't glamorous, and it doesn't feel like you're getting anything useful done, but the 15 minutes I just spent building this would have saved me a $50 part, and now it's sitting in my "connectors" junk box, ready to go the next time I need to probe a DB-9 connector for something.
Lesson learned, and it cost me a $50 part.  Hopefully you heed my advice and take the extra time to be careful the first time.

Friday, April 20, 2012

Product Review - CC3000 TI WiFi Development Platform

This CC3000 development kit showed up on my front doorstep this week; I haven't gotten to do much more than open it and play with the demo app (my summer is turning out to be way busier than I expected), but I'm dutifully impressed with the raw potential for this kit and what we could do with it.
The kit comes with a 16kB FRAM MSP430 development board, a CC3000 WiFi module to plug into it, and a TP-LINK router to set up an isolated WiFi network to experiment on (since most people don't have nearly as many routers laying around as I do, and I haven't figured out if this supports WPA yet).  The demo application that comes with it is a little silly (planet MSP430 orbiting sun laptop), but certainly shows off the potential of the WiFi, thermometer, and accelerometer on the board.


Future projects will follow.

Thursday, April 19, 2012

Addressable I2C Arduino Motor Driver

For my senior project for UC Davis, I needed to have several interchangeable modules that can control typical DC hobby motors, and monitor their position via an infrared sensor.  This design isn't particularly optimized, since an Arduino is a little over-kill for doing little more than listening on an I2C bus for rotation commands, and then handling the control loop between the motor H bridge and IR sensor, but it was fast and super easy to hack together, and makes for a good reference design to start with.
The main components to this driver board are, from left to right:
  • A 5x2 female socket for GND, 5V, 12V (for the motor), and SDA and SCL for the I2C bus. This connector is doubled up so simple 5 conductor cables can be chained from board to board.
  • A reset button and 6 pin serial port for the Arduino.
  • An ATMega328 and all the supporting circuitry needed to have it run the Arduino software stack. I flashed the bootloader on the ATMegas using my previously mentioned target board.
  • A 500k trim pot, which is used as a voltage reference for the voltage regulator inside the H bridge. A better voltage reference would use something more regulated than a trim pot, since if the input voltage doubles, the drive voltage doubles.  Ideally you should be able to set the drive voltage to a specific voltage, instead of a fraction of the rail voltage, but again, quick and dirty here.
  • A Toshiba TA7291SG H bridge motor driver.  This is called an H bridge because it is four transistors arranged like the legs of an H around the motor (which is on the center beam), allowing you to selectively apply current in either direction, isolate the motor (to let it coast), or short the motor to ground (which acts as a brake). This chip comes in an easy-to-solder SIP9 package, and can handle 400mA.
  • A 4 position DIP switch, which the Arduino checks to see what I2C address to use, such that you can chain up to 16 of these onto a single bus and be able to control them independently.
  • A 5 position screw terminal block for the two terminals of the motor, 5V, GND, and the returned output of the analog reflectance sensor used to monitor the motor's speed.
 Taking the block diagram from the TA7291 datasheet, I've highlighted the H configuration of the four drive transistors in red.

I'm unable to release my specific software that I developed for this board, but the Wire library makes it very easy to program I2C slaves using the onReceive and onRequest hooks. You'll need to come up with some sort of command code set between your master and these slaves, but writing the handler functions and state machine to allow for issuing rotation commands, and even polling the drivers for their current status, shouldn't be too hard.
What isn't shown is the motor and sensor attachment.  I used 0.1" screw header to make them somewhat detachable, and used a motor and IR sensor from Pololu. By using a dab of black oil-based paint on the aluminum mounting hub and a simple low-pass filter, it is fairly reliable to watch for the black dot using one of the Arduino's ADC channels.
Pololu's IR sensor board is based on the QRE1113 reflectance sensor, which is both an IR LED and an IR phototransistor in a single (very small) package.  If Pololu's breakout board doesn't happen to meet your needs, building your own will only take that part and two resistors.
Having access to an oscilloscope makes tuning the driver easier, since the reflectance sensor is somewhat picky about how far and at what angle it is from the encoder wheel.  Properly positioned, you can get a 4V pulse from a dark spot on the wheel, which means you could likely rely on a digital input, but I found using an analog-to-digital converter more reliable.
I built my three boards by hand from high quality perf board, but only because I didn't have enough time to spin a custom PCB for them.  If you're making more than one or two, you really probably want to make a board, because building three of these and debugging them got a little tired.
And yes, I agree, those 0.1" screw blocks are adorable.
The two rows of female header are connected in parallel, since I2C is a multidrop bus, so these boards can be chained together, saving wire.

Wednesday, April 18, 2012

AVR ATMega328 Target Board

Like most contemporary electronics hobbyists, I got my initial start on the Arduino four years ago.  Of course, after about a year playing around with their bulky blue PCBs, you want to start being able to put Arduinos in projects without paying $30 a piece for the whole development platform.
The trick is that the Arduino platform essentially boils down to an ATMega328 running a bootloader, which lets you reprogram the chip through a serial port instead of needing an in-circuit AVR programmer.  You can then buy just the ATMega328 chip online for a few dollars, and then build around it only the parts of the Arduino board you truly need. The problem is that when you buy the AVR from a chip supplier, it doesn't usually have the Arduino bootloader preloaded on it, so using the Arduino IDE there is no way to reprogram it. (Note: you can buy preprogrammed chips, but you pay a $2 premium)

I opted to buy a tube of 25 blank AVRs, which saves me money as I continually drop Arduinos into projects, but I need some way to burn the bootloader the first time before I can start reprogramming it.  Of course, burning the bootloader uses a different six pin header than the serial port, so you need to either wire both headers into every project or have a separate board which you can use just for the initial burn. One board you can use for this is actually the original Arduino board, because they have the ICSP header and are often at hand, but trying to get more than a few new chips into and out again from a normal DIP socket gets tired fast. New DIP chips come with their pins bent out 20-30 degrees, so to get one into a regular DIP socket requires bending pins and a light hand as you put it in and pull it out to prevent breaking off pins.
Meet the Zero Insertion Force (ZIF) socket! There are most commonly used on computer motherboards to allow users to replace the hella-high-pin-count CPUs, but you can get them for DIP parts as well.  Mine happens to be designed for 40 pin 0.3" or 0.6" DIPs, which I got on eBay for $2. Ideally, I would have gotten a 28 pin version to match the ATMega328 28 pin package, but this one happened to be cheaper, and I plan to add in ATtiny85 programming capability at the bottom of the socket.
Grabbing a random piece of perf board and all the components shown in the schematic, it only took me about an hour to solder this target board together.  Now, I can sit down with a new tube of 25 ATMega328s, an ICSP programmer, and easily burn all of them with the Arduino bootloader without running the risk of breaking any pins off.
I first plotted out about where I wanted all of the connectors; ICSP in the middle, serial port on the left, and reset button between.  I left space on the right for a DC jack and 5V regulator to allow this to be programmed independent of the programmer, and will eventually wire up the right 8 slots of the ZIF to support the ATTiny85 AVR as well.
Most of the wiring was done on the bottom using 32 gauge wire-wrap wire.  Feel free to use any technique you like, as it suits you and your perf board.
One thing to notice is that I've started using mostly 0603 surface mount passives, even when I'm working on through-hole projects on 0.1" perf board.  Removing the need to figure out where to fit a 0.2" capacitor when you can just tack it between pins makes layout quite a bit easier and cleaner.  Can you spot the four capacitors in the bottom view of the board? :-P
In the end, this is a very useful little piece of kit to have rubber banded to your programmer, such that any time that you just need to program an AVR one time real quick, it's just a matter of dropping in the chip, pushing down the ZIF lever, running avrdude, and then lifting out the programmed chip and installing it in your project.

In my next post, I'll show you one of these applications of the Arduino which profited both in size and price from not using the entire Arduino board. I'll also eventually post an update to this post showing the power supply section built (which you won't normally need, but I will need it for a future project) and the wiring to program ATTiny85s on this target board as well, but I'm looking to be rather busy for the next few weeks.

Monday, April 16, 2012

Windows 7 Explorer RAM Usage

Want to see something really neat? Set up a media center with Windows 7, and have it record ~500 tv shows at 1-3GB a piece. Windows Media Center of course dumps all 1.2TB of video files into a single directory, which really shouldn't be a problem.

Now open that folder, and ask Windows Explorer to perform any sort of meta-data operation on all 1.2TB of files.  Just metadata.  For example, I asked Windows to sort these 500 files by date created.  RAM usage took off. Our system went from 1.5/4GB RAM usage to thrashing and completely catatonic in a matter of seconds, to the point where I couldn't even ask Windows to reboot, and had to yank the power cord.  I tried turning off indexing, compression, thumbnails, and anything else I could find in the control panel that at all sounded like it would be expensive on large files.  It still croaks, and I'm stumped.  The exact sequence is:
  • Open Windows Explorer and navigate to this magical huge folder
  • Switch to detailed view
  • Click one of the column headers to have Explorer sort by date or size, etc
  • RAM usage takes off. I saw it go as high at 6GB, but it took ~10 minutes of thrashing to get there. Task Manager nor Resource Monitor will show any processing taking this RAM; it just disappears.

How in the world can Windows 7 not be able to handle 500 files / 1.2TB directory with 4GB of RAM without even blinking?!?

We carefully cleaned out our recorded TV folder down to about half, and performing metadata requests now cause only a 1.5GB RAM usage jump, which hangs around for 5-15 minutes before just disappearing again.  I have no idea why Windows does this, and with >2TB file systems becoming the new norm, I sure hope there will be a solution to this.

Am I missing something? Has someone seen this before? I can't believe I wasn't able to find anything about this online.