Wednesday, August 31, 2011

Using a 4511 to drive a 7-segment LED with an Arduino

An Arduino UNO can drive a 7 segment LED digit directly, but it takes seven output pins to do it. Additionally, your program is exposed to how the segments in the digit are wired to the Arduino.

A binary coded decimal (BCD) driver like the 4511 hides this level of detail for you. It takes 4 pins as input, another for latch, and drives the LED segments directly. You "tell" it what number to display, and it figures out which segments to light up.

The flipside to using the 4511 is you have to accept the way it draws digits like 6 and 9 without their tails. Also, it doesn't draw letters like A, b, C, d, etc. Well, using the 4511 is just an exercise, a stepping stone to a more sophisticated driver.

Anyhow, this is the code I whipped up in about an hour. I'm putting it in the public domain, so enjoy!

 * Arduino UNO 4511 BCD to 7-digit LED driver
 * 4511 pins 3 (lamp test), 4 (ripple blanking), and 16 (Vcc)
 * are connected to +5V on the Arduino UNO.
 * 4511 pin 8 is connect to GND on the Arduino UNO.
 * The common cathode on the LED digit also connects to GND.
 * 4511 pins 9 through 15 connect to the LED digit as
 * appropriate.
#define LATCH_ENABLE  13  // to pin 5 on the 4511
#define DATA1          1  // to pin 7 on the 4511
#define DATA2          2  // to pin 1 on the 4511
#define DATA3          3  // to pin 2 on the 4511
#define DATA4          4  // to pin 6 on the 4511

void setup()
  pinMode( DATA1, OUTPUT ) ;
  pinMode( DATA2, OUTPUT ) ;
  pinMode( DATA3, OUTPUT ) ;
  pinMode( DATA4, OUTPUT ) ;

// This macro tests bit 'b' in value 'v' and reports
// high or low as appropriate.
#define T(v,b)  (v & (1<<b) ? HIGH : LOW)

void show( unsigned int value )
  if ( value <= 9 )
    // enable the latch so we can write
    digitalWrite( LATCH_ENABLE, LOW );
    digitalWrite( DATA1, T(value, 0) );
    digitalWrite( DATA2, T(value, 1) );
    digitalWrite( DATA3, T(value, 2) );
    digitalWrite( DATA4, T(value, 3) ); 
    // disable the latch now that we're done writing
    digitalWrite( LATCH_ENABLE, HIGH );

void loop()
  for ( int i = 0; i <= 9; i++ )
    show( i ) ;
    delay( 1000 ) ;  // msec
The 4511 does a fine job driving a single 7-segment LED display, but it's old school compared to the MAX7219 which can drive up to eight of those displays. Here's a well written resource on the 7219. I'm going to try getting one soon.

Hitachi Z7K320

I had to make a snap decision today on whether to buy a new hard drive for my x220t. The x220t only takes 7mm drives, which are less common than the typical 9.5mm drive for most notebooks. So seeing a 7200rpm drive on sale really caught my eye.

Drive performance was my primary concern, capacity was secondary. Sadly, few people actually published benchmarks for this drive. Mostly I just found marketing hyperbole and speculation.

The folks at Red Hill were kind enough to share a formula that they found was consistently able to predict a hard drive's performance: (2 log(data transfer rate) / sqr(seek + latency)). The higher the number, the faster the drive should perform.

Since my x220t is at home, I had to guess what hard drive it actually uses. So I chose the Seagate Momentus Thin based on vague recollections and what specifications I knew (250GB, 5400rpm, 7mm thickness). (Update: yes, exactly right, the ST9250301AS.) Here are the relevant numbers:

DTR 300 MB/s
random read seek 14ms
average latency 5.6ms
calculated result 1.119

This is the drive that was on sale at

Hitachi Z7K320:
DTR 300 MB/s
average read seek 13ms
average latency 4.2ms
calculated result 1.195

So a slight performance improvement, according to the forumla.

It's possible I am making an apples-to-oranges comparison because I had to use "random read seek" versus "average read seek". Also, I've seen conflicting numbers for the Momentus Thin. If its seek time is actually 11ms according to this, then it's faster than the Hitachi, which defies expectations.

After a little more searching, I found a comparison between the z7k320 against the z7k500:

*** TRAVELSTAR 7K500 ***
CrystalDiskMark 3.0 (C) 2007-2010 hiyohiyo
Crystal Dew World : -----------------------------------------------------------------------
* MB/s = 1,000,000 byte/s [SATA/300 = 300,000,000 byte/s]

Sequential Read : 111.361 MB/s
Sequential Write : 112.255 MB/s
Random Read 512KB : 39.582 MB/s
Random Write 512KB : 49.046 MB/s
Random Read 4KB (QD=1) : 0.516 MB/s [ 126.0 IOPS]
Random Write 4KB (QD=1) : 0.772 MB/s [ 188.6 IOPS]
Random Read 4KB (QD=32) : 0.972 MB/s [ 237.4 IOPS]
Random Write 4KB (QD=32) : 0.787 MB/s [ 192.0 IOPS]

Test : 1000 MB [D: 0.0% (0.1/232.9 GB)] (x5)
Date : 2010/12/14 16:13:58
OS : Windows 7 Home Premium Edition [6.1 Build 7600] (x86)

*** TRAVELSTAR Z7K320 ***
CrystalDiskMark 3.0 (C) 2007-2010 hiyohiyo
Crystal Dew World : -----------------------------------------------------------------------
* MB/s = 1,000,000 byte/s [SATA/300 = 300,000,000 byte/s]

Sequential Read : 107.458 MB/s
Sequential Write : 106.552 MB/s
Random Read 512KB : 43.852 MB/s
Random Write 512KB : 47.439 MB/s
Random Read 4KB (QD=1) : 0.578 MB/s [ 141.2 IOPS]
Random Write 4KB (QD=1) : 1.085 MB/s [ 264.9 IOPS]
Random Read 4KB (QD=32) : 1.037 MB/s [ 253.3 IOPS]
Random Write 4KB (QD=32) : 1.091 MB/s [ 266.3 IOPS]

Test : 1000 MB [D: 0.0% (0.1/298.1 GB)] (x5)
Date : 2010/12/16 17:01:09
OS : Windows 7 Home Premium Edition [6.1 Build 7600] (x86)

According to the xbitlabs roundup, the 7K500 was the fastest among a group of 500-750GB drives. Yet the z7k320 had higher random read and write numbers than the 500, according to the Italian benchmark. So it does look like the z7k320 is a real performer, and the answer is "GO! BUY! NOW!"

Saturday, August 27, 2011

Rohm LU-3011 LED display module

I found this at Active Surplus today for $1.50. It has eleven LA-301VL (7-segment common cathode displays) on a 2-layer pcb. Numbering the pins and digits from left to right, here's how the pins correspond to digits:
With respect to the segments, here's the relationship between the segments and the pins on the PCB: I'll need to build a multiplexer to control the display. This should be interesting.