Circuit Cellar Sept 2013 153198-Issue 278 Sept

84
Weekly Code Challenge | Q&A: Pro Electronics Entrepreneur Rubik’s Cube-Solving Robot | R-Pi I/O Board | Robotic Neural Networks Battery Basics for Engineers | LED Characterization| Cooling Servers | BMP Files Tips Electronics Beyond Silicon DATA ACQUISITION SEPTEMBER 2013 ISSUE 278 MCU-BASED COLOR DATA ACQUISITION CIRCUIT CELLAR | ISSUE 278 | SEPTEMBER 2013 DIY robot’s MCU captures and processes camera images of cube facelets robot control + search algorithm execution = solution circuitcellar.com

description

CC

Transcript of Circuit Cellar Sept 2013 153198-Issue 278 Sept

Page 1: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Weekly Code Challenge | Q&A: Pro Electronics Entrepreneur Rubik’s Cube-Solving Robot | R-Pi I/O Board | Robotic Neural Networks Battery Basics for Engineers | LED Characterization|

Cooling Servers | BMP Files Tips Electronics Beyond Silicon

DATA ACQUISITIONSEPTEMBER 2013

ISSUE 278

MCU-BASED COLOR DATA ACQUISITION

CIRCUIT CELLAR | ISSU

E 278 | SEPTEMBER 2013

circuitcellar.com

DIY robot’s MCU captures and processes camera images of cube facelets

robot control + search algorithm execution = solution

circuitcellar.com

Page 2: Circuit Cellar Sept 2013 153198-Issue 278 Sept

C

M

Y

CM

MY

CY

CMY

K

COREMODULE-AD-JUL2013_NV_CC.pdf 1 5/31/2013 2:58:47 PM

Page 3: Circuit Cellar Sept 2013 153198-Issue 278 Sept

ORE.

The widest selection of the newest products.

Authorized distributor of semiconductorsand electronic components for design engineers.

Primary Logo Secondary Stacked Logo

Mouser and Mouser Electronics are registered trademarks of Mouser Electronics, Inc. Other products, logos, and company names mentioned herein, may be trademarks of their respective owners.

The Newest Products for Your Newest Designs®

www.mouser.com

Mouser_MoreSelection_CircuitCellar_9-1.indd 1 7/16/13 3:03 PM

Page 4: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #2782

Issue 278 September 2013 | ISSN 1528-0608

CIRCUIT CELLAR® (ISSN 1528-0608) is published monthly by:

Circuit Cellar, Inc.111 Founders Plaza, Suite 300

East Hartford, CT 06108

Periodical rates paid at East Hartford, CT, and additional offices. One-year (12 issues) subscription rate US and possessions

$50, Canada $65, Foreign/ ROW $75. All subscription orders payable in US funds only via Visa, MasterCard, international

postal money order, or check drawn on US bank.

SUBSCRIPTIONS

Circuit Cellar, P.O. Box 462256, Escondido, CA 92046

E-mail: [email protected]

Phone: 800.269.6301

Internet: circuitcellar.com

Address Changes/Problems: [email protected]

Postmaster: Send address changes to Circuit Cellar, P.O. Box 462256, Escondido, CA 92046

ADVERTISING

Strategic Media Marketing, Inc.2 Main Street, Gloucester, MA 01930 USA

Phone: 978.281.7708

Fax: 978.281.7706

E-mail: [email protected] rates and terms available on request.

New Products:New Products, Circuit Cellar, 111 Founders Plaza, Suite 300

East Hartford, CT 06108, E-mail: [email protected]

HEAD OFFICE

Circuit Cellar, Inc. 111 Founders Plaza, Suite 300East Hartford, CT 06108

Phone: 860.289.0800

COVER PHOTOGRAPHY

Chris Rakoczy, www.rakoczyphoto.com

COPYRIGHT NOTICE

Entire contents copyright © 2013 by Circuit Cellar, Inc. All rights reserved. Circuit Cellar is a registered trademark of Circuit Cellar, Inc. Reproduction of this publication in whole or in part without written consent from Circuit Cellar, Inc. is

prohibited.

DISCLAIMER

Circuit Cellar® makes no warranties and assumes no responsibility or liability of any kind for errors in these programs or schematics or for the consequences of any

such errors. Furthermore, because of possible variation in the quality and condition of materials and workmanship of reader-assembled projects, Circuit Cellar® disclaims any responsibility for the safe and proper function of reader-

assembled projects based upon or from plans, descriptions, or information published by Circuit Cellar®.

The information provided by Circuit Cellar® is for educational purposes. Circuit Cellar® makes no claims or warrants that readers have a right to build things based upon these ideas under patent or other relevant intellectual property law in

their jurisdiction, or that readers have a right to construct or operate any of the devices described herein under the relevant

patent or other intellectual property law of the reader’s jurisdiction. The reader assumes any risk of infringement

liability for constructing or operating such devices.

© Circuit Cellar 2013 Printed in the United States

THE TEAM

EDITOR-IN-CHIEFC. J. Abate

MANAGING EDITORMary Wilson

ASSOCIATE EDITORNan Price

ART DIRECTORKC Prescott

ADVERTISING COORDINATORKim Hopkins

PUBLISHERHugo Van haecke

ASSOCIATE PUBLISHERShannon Barraclough

COLUMNISTS

Jeff Bachiochi, Ayse Coskun, Bob Japenga, Robert Lacoste, Ed Nisley, George Novacek, Colin O’Flynn

FOUNDERSteve Ciarcia

PROJECT EDITORSKen Davidson, David Tweed

CONTROLLEREmily Struzik

CUSTOMER SERVICEDebbie Lavoie

EDITOR’S LETTER

NEW ISSUE, NEW LOOK, NEW MEDIAOver the years, Circuit Cellar editors have learned you simply can’t stand

still when your magazine focuses on ever-evolving embedded electronics. So with this issue, we introduce a dramatic redesign to make the magazine’s look more contemporary and its connection with our website stronger.

The heart of our content is still project pieces and columns. For example, in this issue, Nelson Epp writes about a Rubik’s Cube-solving robot (p. 24), Walter Krawec examines evolving neural networks in robotics (p. 42), and Brian Millier describes how to configure his “Iso-Pi” I/0 board for the Raspberry Pi single-board computer (p. 32).

In addition, our column topics include examining different battery types and their characteristics (p. 48), exploring commodity LED characteristics with a stress tester and an optical output detector (p. 54), and understanding BMP graphical file formats (p. 64).

Speaking of columnists, this issue introduces a new one—Ayse Coskun, a Boston University assistant professor. Her bimonthly Green Computing column will focus on topics that recognize energy is a “first-order constraint” on any computing system, large or small. So she will be looking at everything from energy-efficient software and hardware-design strategies to electricity cost savings and battery-life extension (p. 60).

Another new feature is CC World (p. 8), which will provide monthly updates on topics of interest to the magazine’s international community of engineers, academics, and students. This month, we touch on the CC Weekly Code Challenge and the designers participating in Elektor-LABS.com, the lab-tested, project-sharing site provided by Elektor International Media (EIM).

But our changes are not simply about what you see on the magazine’s pages. This redesign makes it easier for you to connect our print content to related material at circuitcellar.com.

At the end of each article, you’ll discover an easier way to find project files and supporting documents online. You can either type circuitcellar.com/ccmaterials in your browser or use your smartphone to scan the printed QR code.

We hope you enjoy the new look and conveniences.

Mary [email protected]

Page 5: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 3

USAHugo Van haecke+1 [email protected]

UNITED KINGDOMWisse Hettinga+31 46 [email protected]

GERMANYFerdinand te Walvaart+49 241 88 [email protected]

FRANCEDenis Meyer+31 46 [email protected]

NETHERLANDSHarry Baggen+31 46 [email protected]

SPAINEduardo Corral+34 91 101 93 [email protected]

ITALYMaurizio del Corso+39 [email protected]

SWEDENWisse Hettinga+31 46 [email protected]

BRAZILJoão Martins+31 46 [email protected]

PORTUGALJoão Martins+31 46 [email protected]

INDIASunil D. Malekar+91 [email protected]

RUSSIANataliya Melnikova+7 (965) 395 33 [email protected]

TURKEYZeynep Köksal+90 532 277 48 [email protected]

SOUTH AFRICAJohan Dijk+31 6 1589 [email protected]

CHINACees Baay+86 21 6445 [email protected]

OUR NETWORK

SUPPORTING COMPANIES

NOT A SUPPORTING COMPANY YET?

Contact Peter Wostrel ([email protected], Phone 978-281-7708, Fax 978-281-7706) to reserve your own space for the next edition of our members’ magazine.

2014 International CES 43

AP Circuits 73

ARM 44

Artila Technologies, Inc. 13

Beta Layout 23

CC Gold Archive USB 59

Cleverscope 14

Crystalfontz America, Inc. 14

Elektor 52, 53

Elektor 71

Elprotronic, Inc. 51

EMAC, Inc. 23

ExpressPCB 29

EzPCB 73

Fabstream 47

Front Panel Express 51

FTDI Chip C3

Humandata, Ltd. 27

Imagineering, Inc. C4

Labcenter Electronics 9

Lauterbach GmbH 11

Microchip Technology, Inc. 39

Mouser Electronics, Inc. 1

NetBurner C2

Newark element14 35

Pico Technology, Ltd. 69

Pololu Corp. 31

RS Components 20-22

Saelig Co., Inc. 49

Sealevel Systems 63

SoC Conference 57

Technologic Systems 6, 7

Page 6: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #2784

CONTENTS

SEPTEMBER 2013 • ISSUE 278

DATA ACQUISITION

PULSED LED CHARACTERIZATION

CC COMMUNITY08 : CC WORLD

10 : QUESTIONS & ANSWERSElectronics EntrepreneurEngineer Jack Ganssle on projects, consulting, and the next big thing

14 : MEMBER PROFILESystems engineer Dean Boman (Chandler, AZ)

INDUSTRY & ENTERPRISE15 : NEW PRODUCTS

23 : CLIENT PROFILENetBurner (San Diego, CA)

FEATURES24 : Rubik’s Cube-Solving RobotBy Nelson EppMicrocontroller-based robot uses a 52-move algorithm to solve a Rubik’s Cube puzzle

32 : Raspberry Pi I/0 Board (Part 2)ISO-Pi Circuit Description and FirmwareBy Brian MillierBuild an I/0 board to interface with a Raspberry Pi

42 : Experiments in Developmental Robotics (Part 1)Artificial and Evolving Neural NetworksBy Walter O. KrawecRobot learning with an evolving neural network

COLUMNS48 : THE CONSUMMATE ENGINEERBattery Basics (Part 1) Battery TypesBy George NovacekTips on comparing battery characteristics and performance

54 : ABOVE THE GROUND PLANEPulsed LED CharacterizationBy Ed NisleyExplore LED features with a stress tester and optical output detector

60 : GREEN COMPUTINGEnergy-Efficient Cooling Strategies for Servers Analyze and Control Leakage and Fan PowerBy Ayse CoskunMinimize processor overcooling by designing practical control systems

ENERGY-EFFICIENT COOLING STRATEGIES

Page 7: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 5

CONTENTS

64 : FROM THE BENCHSerial Displays Save Resources (Part 3)BMP FilesBy Jeff BachiochiThe BMP file format and working efficiently with graphic icon data

TESTS & CHALLENGES72 : CROSSWORD

73 : TEST YOUR EQ

TECH THE FUTURE80 : Electronics Beyond SiliconBy Jeremy Ward and Oana JerchescuSilicon’s limits fuel research into flexible, organic electronics—from smart bandages and rollable displays to disposable single-use sensors

RASPBERRY PI I/0 BOARD

IMAGE DATA STORAGE AND DISPLAY

RUBIK’S CUBE-SOLVING ROBOT

PRO ENGINEERING AND CONSULTING

Page 8: Circuit Cellar Sept 2013 153198-Issue 278 Sept
Page 10: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #2788

CC WORLD

COM

MU

NITY

Since July 2013, electronics enthusiasts around the world have been entering the

CC Weekly Code Challenge, which is sponsored by IAR Systems. Thus far, hundreds of electrical engineers, academics, and DIYers have reviewed the code snippets and submitted their answers. What about you?

Here’s how the challenge works: Each week at CircuitCellar.com, Circuit Cellar’s crafty technical editors purposely insert an error into a code snippet. It could be a semantic error, a syntax error, a design error, a spelling error, or another bug the editors try to slip past you. You’re challenged to find the error and submit it via the online form. Once the submission period ends, Circuit Cellar will randomly select one winner from the pool of respondents who submitted the correct answer.

Prizes range from development kits to CC T-shirts to free subscriptions. Visit the CC Weekly Code Challenge webpage each week to analyze a new code snippet: circuitcellar.com/cc-weekly-code-challenge.

DEBUG CODE TO WIN by CC Staff (USA)

This code snippet was posted for the week of July 15, 2013. Alex Ivopol of New Zealand won the week’s challenge. He wrote: “The error was located in line 16. The double ampersand is a logical operator that returns true as long as k is nonzero. The intended operator here is a single ampersand, which is a bitwise operator used to test the least significant bit of k.”

Circuit Cellar’s parent company Elektor International Media’s online design community, Elektor.LABS (elektor-labs.com), has been growing on monthly basis. Here are just a

few of the current projects on Elektor.LABS that you can review: PLµX: Programmable Logic Microcontroller on Linux, Wireless Batter Charger, LPC810 as NE555 or as Capacitance Meter, FPGA Development Board, USB-IO24 Cable, and Wi-Fi RGB LED Strip.

Want to learn more? Browsing projects at Elektor.LABS is free! To join projects and submit your own you must be a member.

MCU PROJECTS AT ELEKTOR.LABS by CC (USA) & EIM Staff (The Netherlands)

Elektor.LABS is an electronics laboratory. It’s both virtual and real. In the real-world lab—which is located at Elektor International Media’s headquarters in the Netherlands—engineers are working on projects every day. The virtual lab is where you can create a new project.

Watch a video about Elektor.LABS! Go to bit.ly/ccmaterials

Page 12: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27810CO

MM

UNI

TY

QUESTIONS & ANSWERS

NAN: You’ve been interested in electronics since the age of 9. Give us a little background information. What was your first project?

JACK: My first project was a crystal radio with the inductor wound on the quintessential Quaker oatmeal box! It was really exciting to get AM reception over that. Back then, pretty much no one had FM. AM was it.

Later I learned to repair TVs and made pocket money doing that. Those sets were all vacuum tubes. Usually there was just a bad tube or dried out capacitor. But from there, my friends and I learned to design amplifiers (the Beatles were very hot and everyone was starting a band). For graduation from eighth grade, my dad gave me an old oscilloscope he had built from a kit years earlier.

He was part of a startup when I was in my early teens. We kids were coerced into being the (unpaid) janitors for the place. That was annoying at first. But, we were allowed to keep anything we swept up. The engineering lab’s floor was always covered in resistors, capacitors, transistors, and the like, so my parts collection grew. (ICs existed then, but were rare.)

When I was 16 I got a ham license, built various transmitters, and used WWII surplus receivers. One day an angry letter arrived from the Federal Communications Commission (FCC). They had picked me up on my second harmonic clear across the country. I was really proud of that contact.

But it wasn’t long before some resistor-transistor logic (RTL) digital ICs came my way. Projects included controls for tube

transmitters, Estes model rocket telemetry, and even a crude TV camera that used a photomultiplier tube to scan a spiral set of holes in a spinning disk. A couple of us worked on a ham radio moon bounce, but I accidentally shorted out a resistor and my only hydrogen thyratron (sort of a tube version of an SCR) blew up. There was no money for a replacement, so that project died. The transmitter used a little lighthouse tube that had a maximum rating of a couple of watts, but it worked OK when pulsing it for a few microseconds at 1 kW.

Senior year of high school a friend and I hitchhiked from Maryland to Boston to go to a surplus store. I bought a core memory plane that was 13,000 bits in a 6 in2 cube. Long hair didn’t help. We were picked up on the New Jersey Turnpike and strip searched. The cops never believed my explanation that the thing was computer memory.

A few years later, I had a 6501 microprocessor in the glove compartment of my Volkswagen bus (which I lived in for a year while saving for a sailboat). Coming into a sleepy Maine town from Canada that event was repeated when the border cops searched the bus and found the chip. They didn’t believe in computers on a chip. But the PC was years away and computers were mostly seen in science fiction films.

Freshman year of college, I designed and built a 12-bit computer using hundreds of TTL chips soldered together using phone company wire on vectorboards. For I/O there was an old Model 15 teletype using 5-bit Baudot codes that my software drove via bit banging. The OS, such as it was, lived in a pair of 1702

Electronics EntrepreneurAn Interview with Jack Ganssle

Jack Ganssle is a well-known engineer, author, lecturer, and consultant. After learning about oscilloscopes, transistors, and capacitors in his father’s engineering lab, Jack went on to write hundreds of articles and several books about embedded development-related topics. He also started and sold three electronics companies, worked on classified government projects, and founded The Ganssle Group, based in Reisterstown, MD. I recently spoke with Jack about some of his career highlights, his current work, and what’s next in the embedded design industry.—Nan Price, Associate Editor

Page 13: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 11CO

MM

UNITY

QUESTIONS & ANSWERS

EPROMs, which each held 256 bytes. The computer worked great! And then the 8008, the first 8-bit microcontroller, came out and the thing was obsolete. I junked it, and now I wish I had saved at least the schematics.

But by then I had been working part-time as an electronics technician for a few years and the company needed to update its analog products to digital. No one knew anything about computers, so they promoted me to engineer. Eventually I ran the digital group there. We designed one of the first floppy disk controllers, insanely high-resolution graphics controllers, and a lot of other products. We also integrated minicomputers (Data General Novas and DEC PDP-11s) into systems with microprocessors. We bought a 5-MB disk drive for a Nova. It cost $5,000 (back when that was a lot of money) and weighed 500 lb. How things have changed.

NAN: Tell us about The Ganssle Group (www.ganssle.com). When and why did you start the company? What types of services do you provide?

JACK: I formed The Ganssle Group in 1997 after 15 years of running an in-circuit emulator company. Working 70 h a week was getting old and I wanted more time with my kids. So my objective was to reverse the usual model. Instead of fitting life around a job, I wanted to fit the job into life.

Goal 1: Four months of vacation a year. It turns out that is elusive, in no small part due to the cool stuff going on around here, but most years we do manage two to three months off. My wife, Marybeth, works with me. She takes care of all of the administrative/travel and the like.

Goal 2: No commute. So we work out of the house (for the first few years, we worked out of the houseboat where we raised two kids).

Now the kids are grown, so there’s a Goal 3: Have as much fun as possible with Marybeth, so when I travel to new or interesting places she often accompanies me. There’s a lot more to life than work. Some of my side projects are available at www.ganssle.com/jack.

I’m not really sure what I do. I write—a lot. Readers are incredibly smart and vocal. The dialogue with them is a highlight of my day. I also give one- and two-day seminars on pretty much every continent (except Antarctica—so far!) about ways to get better firmware done faster. Sometimes I do an expert witness gig. Those are always fascinating as one gets to dig deeply into products and learn about the law. On rare occasions, I’ll do a day or three of consulting if the problem is particularly interesting. And there’s always some experiment I’m working on, which sometimes gets written up as an article.

NAN: Speaking of articles, you’ve written hundreds—including nine for Circuit Cellar magazine—on topics ranging from the history of the embedded systems programming industry, to memory management, to using programmable logic devices (PLDs). You also write a column for Embedded (www.embedded.com) and you are editor of the biweekly

The breadboard is discharging batteries. To the left, a battery is soldered to some coax. I’m using the oscilloscope’s waveform generator to measure the battery’s reactance (which, it turns out, is entirely capacitive). The IAR tool is profiling an evaluation board’s current consumption.

1500+supported

Cortex-MTM

based chips

advertisement_microtrace.indd 1 02.07.2013 12:13:58

Page 14: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27812CO

MM

UNI

TY

QUESTIONS & ANSWERS

newsletter The Embedded Muse. Tell us about the types of projects you enjoy constructing and writing about.

JACK: I have one experiment that’s running right now. For the last four months I’ve been

discharging coin cells. It sounds dull, but some microcontroller vendors are making outrageous claims about battery life that are true on the surface but irrelevant in real circuits. This circuit runs a complex profile on the batteries, tossing different loads on for a few milliseconds. An ARM microcontroller samples the batteries’ voltage (as

well as the transistors’ VCE drop) into a log file. That data goes into a spreadsheet for further analysis. I’m making a much bigger version of this now, which will handle far more batteries at a time. I recently gave some preliminary results at a talk in Asilomar, CA, which garnered a lot of interest. More results will be forthcoming soon...I promise!

Another aspect of this is leakage. Does handling a battery leave finger oils that can affect the decades-long life claimed by the vendors? To test this, I built a femtoammeter. A polypropylene capacitor is charged and feeds a super-low bias current op-amp. Another ARM board monitors the op-amp voltage to watch the capacitor discharge as various contaminants are electrically connected to the capacitor. With no contaminants connected, even after 48 h, the cap discharged less than 1 mV. The thing resolves to better than 10 fA. (One fA is a millionth of a nanoamp, or about 6,000 electrons/second).

In fact, the ADC’s transfer function is a proxy for temperature. We heat the house with wood and you could see a perfect correlation of op-amp output and temperature throughout the day. (It’s lowest in the morning as the fire burns out overnight.)

NAN: You wrote the two-part Circuit Cellar article series, “Writing a Real-Time Operating System” (Issues 7 and 8, 1989) about the Hitachi HD64180 Z80-based embedded microprocessor nearly 15 years ago. Circuit Cellar also featured another HD64180-based article, “Huge Arrays on the HD64180: Taking Advantage of Memory Management” (Issue 16, 1990). What was your fascination with the HD64180? Also, is either of these projects still current? Have you changed any of the design components?

JACK: Gee, I have no idea. I wrote those using Microsoft Works, but the file format has changed and Works can no longer open those articles. Alas, the HD64180 is quite obsolete. It was a grown-up version of the Z80 and very popular in its day.

In 1974, Intel introduced the 8080, which was the first really decent 8-bit microprocessor. But it needed two clocks and three power supplies. The folks at Zilog came out with the Z80 a year later. It could run 8080 code, but had one clock, a single 5-V supply, and it offered additional instructions that massively improved code density. Intel responded with the 8085, but it was really an 8080 in drag. The couple of new instructions added just couldn’t give the Z80 a run for its money. Eventually Zilog came out with the Z180, and Hitachi the 64180 clone, which included on-board peripherals and a memory management unit to address 1 MB using standard Z80 instructions. It was a great idea, but since there was no on-board memory, it couldn’t compete with microcontrollers such as the ancient, and still-going-strong, 8051.

NAN: In addition to writing, you lecture and teach at conferences and symposiums worldwide. Tell us about your one-day “Better Firmware Faster” seminar. How did it begin? What can attendees expect to gain from it?

JACK: I’m completely frustrated with the state of firmware. It’s inevitably late and buggy. While there’s no doubt that crafting firmware is extremely difficult—after all, software is the most complex engineered product ever invented—we can and must do better. It’s astonishing that so few groups keep even the simplest metrics, yet engineering is all about numbers.

The seminar is a fast-paced event that shows developers better ways to get their code to market. It covers process issues, as well as a lot of technology areas unique to embedded systems, such as managing memory and dealing with tough real-time problems.

What can attendees get from it? It varies from very little to a lot. Some groups refuse to change anything, so will always maintain the status quo. Others do better. Some report 40% improvements to the schedule and up to an order of magnitude of reduction in shipped bugs.

NAN: You started three high-tech companies prior to The Ganssle Group. Tell us about your work experience. Any highlights?

“Whi l e there ’s no doubt that crafting firmware is extremely difficult, we can and must do much better.”

Page 15: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 13CO

MM

UNITY

QUESTIONS & ANSWERS

JACK: Well, there was one instrument that used infrared light to measure protein in cow poop. Though it was interesting technology, it’s hard to call that a highlight. The design I’m most proud of was my first emulator, which had only 17 ICs and used insanely complex code. Eventually we offered emulators that required hundreds of chips, but those cost $7,000, while the first one sold for $600.

Some of the government work I’ve done was very interesting and used extremely sophisticated electronics. But I can’t talk about those projects. A buddy and I did the White House security system during the Reagan administration. It was fun to work in the basement there, but the bureaucracy was stifling. We lost our White House passes the same day Oliver North did, but he got more press.

NAN: What do you consider to be the “next big thing” in the embedded design industry? Is there a particular technology that you’ve used or seen that will change the way engineers design in the coming months and years?

JACK: Everything is going to change for us over the next five to 10 years. We will have

tools that automatically find lots of bugs. Everyone is familiar (and has a love/hate relationship) with lint. But static analyzers can today find lots of runtime bugs. These are currently expensive and frustrating, but they demonstrate that such products can, and will, exist. When the issues are resolved, I expect they’ll be as common as IDEs. Debugging manually is hugely expensive.

Another tool is slowly gaining acceptance: so-called virtualization products (e.g., from Wind River and others). These are not the hypervisors people think about when using the word “virtualization.” Rather, they are complete software models of a target system. You can run all—and I mean all—of your code on the model. The hardware is always late. These tools will permit debugging to start at the beginning of the project. The tools are also expensive and somewhat clumsy, but will get better over time.

A modern smartphone has more than 10 million lines of code. Automobiles often have more. One thing is certain: Firmware will continue to grow in size and complexity. The current techniques we use to develop code will change as well.

Distributor: Antaira Technologies, LLC +1 (877) 229-3665 [email protected]

● Atmel/Freescale ARM SoC

● SoM/SBC/Box Computer/Automation Controller

● LAN/Serial/CAN/USB/LCD/AIO/DIO

● Compact DIN Rail and wall mount● Linux 2.6 and WinCE 6.0 support

● Ultra low power and wide temperature

Box ComputerSoM SBC Automation Controller

Embed ARM in Automation

www.artila.com

Page 16: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27814CO

MM

UNI

TY

MEMBER PROFILE

Dean Boman Retired Systems Engineer • Chandler, AZ

MEMBER STATUS:Dean has been a subscriber for about 20 years.

TECH INTERESTS: Dean enjoys designing and building home automation systems. His current system’s functions include: security system monitoring, irrigation control, water leak detection, temperature and electrical usage monitoring, fire detection, access control, weather and water usage monitoring,

solar hot water system control, and security video recording.

MOST RECENT EMBEDDED TECH ACQUISITION:A Microchip Technology debugger.

CURRENT PROJECTS:Dean is currently designing a hybrid solar power system to power his home automation system. “The power system will use a processor-controlled dual-input power converter design to harvest the maximum energy possible from the photovoltaic cells and then augment that with utility power as necessary to support the load,” he explained. “The system will be a hybrid between an on-grid and an off-grid system. The hybrid

approach was chosen to avoid the regulatory issues with an on-grid system and the cost of batteries in an off-grid system.”

THOUGHTS ON THE FUTURE OF EMBEDDED TECH:“As more and more capability is being made available to the embedded world, the design opportunities are endless. I particularly find it exciting that network connectivity can now be so easily added to an embedded system so various embedded systems can communicate with each other and with the outside world via the Internet. I am concerned that so many of the new embedded parts are designed with extremely fine pitch leads, which makes DIY assembly with hand soldering a challenge,” he said.

You've got intermittent pulse bursts being generated when they shouldn't be. You can see them on a scope. How often and when are they occurring? Or you just want to know what is happening in a longer time period.

Use a Cleverscope! Capture a day's worth of samples at 1.5 MSPS. Pan and zoom, really quickly. Accurately identify when events happened. See even very short µs events in a day's recording. Check out http://youtu.be/

Page 17: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 15IND

USTRY &

ENTERPRISE

PRODUCT NEWS

ACCURATE MEASUREMENT POWER ANALYZERThe PA4000 power analyzer provides

accurate power measurements. It offers one to four input modules, built-in test modes, and standard PC interfaces.

The analyzer features innovative Spiral Shunt technology that enables you to lock onto complex signals. The technology ensures a stable, linear response over a range of variables (e.g., input current levels, ambient temperatures, and crest factors). The spiral construction minimizes stray inductance for optimum high-frequency performance and provides high overload capability and improved thermal stability.

The PA4000’s additional features include 0.04% basic voltage and current accuracy, dual internal current shunts for optimal resolution, frequency-detection algorithms for noisy waveform tracking, and application-specific test modes to simplify setup.

The analyzer easily exports data to a USB flash drive or PC software. Harmonic analysis and communications ports are included as standard features.

Contact Tektronix for pricing.

LED DRIVERS FOR DIMMABLE BULBSThe iW3606 and the iW3608 are single-

stage, solid-state lighting (SSL) LED drivers. The iW3606 (8-W output power) and the iW3608 (15-W output power) feature configurable over-temperature protection (OTP) and derating functionality to provide predictability and reliability of bulb operating life.

Designed for all retrofit bulbs, including candle and GU10 lamp replacements used in existing phase-cut dimmer installations, the LED drivers manage poor dimming performance (e.g., pop-on, popcorning, dead travel, drop-out, and flicker) and short bulb lifetime or failure. Both drivers meet or exceed global regulations for power quality and efficiency with less than 0.92 power factor (PF) and less than 20% total harmonic distortion (THD).

The LED drivers’ OTP and derating feature addresses the thermal issues caused by the high and unpredictable operating temperatures in dimmable SSL applications. iWatt’s OTP derating monitors the temperature inside sealed SSL bulbs. When thermal conditions reach a point set by the system designer, the LED drivers automatically reduce the current drive to the LEDs, lowering the power dissipation and resulting in a cooler overall operation.

The iW3606 and the iW3608 feature a wide, flicker-free dimming range from 100% to 1% of measured light to closely match incandescent bulbs’ dimming performance. This enables smooth “natural” dimming

with no light drop-out at the low end of the dimming range and virtually no dead travel where the light turns off before the dimmer control reaches the bottom of its travel.

The LED drivers’ low internal power consumption enables them to start at less than 5% of light output, which is a very low dimming level. This virtually eliminates pop-on, in which the light does not turn on at low dimmer levels and, as the dimmer level is raised, the light suddenly turns on. The low power consumption also helps eliminate popcorning effects, in which various bulbs in multiple-light installations on the same dimmer circuit can turn on at different dimmer-setting thresholds.

The iW3606 costs $0.46 and the iW3608

Tektronix, Inc.www.tek.com

costs $0.51, both in 1,000-unit quantities.

iWatt, Inc.www.iwatt.com

Page 18: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Circuit Cellar Reboots! If you’ve made it this far, you’ve noticed that your favorite embedded

electronics magazine received a facelift. We’ve been working hard

creating a new, modern logo, and a magazine layout that delivers

readers with bigger and better project photos, new features, and

rich media content. Within the articles, you’ll notice larger photos,

new layouts, and an updated resource box.

Now referred to as “CC Materials,” you can

access code and project files directly on your

mobile device, using the QR code provided,

or by visiting circuitcellar.com/ccmaterials.

Some articles have supplemental videos, so

look for the icon highlighting those features!

Content is also growing and expanding with the addition

of a new columnist, Ayse Coskun, an electrical engineering

professor at Boston University. CC’s first female columnist,

Ayse’s bi-monthly column will focus on energy-efficient

hardware and software design strategies. Also check out

the new CC World section, which highlights happenings

and important info relating to CC’s international community

of engineers, academics, and students.

As we move forward, CC’s mission remains the same: we’ll provide electrical engineers relevant and timely content to help them excel in the field embedded design. We hope you enjoy the new package and continue to share the brilliance that is Circuit Cellar with colleagues and peers.

Best Regards, The Circuit Cellar Team

On the cover, and throughout the issue, you’ll see the new company logo. Designed

to highlight the two “Cs” in Circuit and Cellar, it’s a modern twist on an old classic. The dark

covers have been replaced by a bright, open design that highlights feature content.

Page 19: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Circuit Cellar Reboots! If you’ve made it this far, you’ve noticed that your favorite embedded

electronics magazine received a facelift. We’ve been working hard

creating a new, modern logo, and a magazine layout that delivers

readers with bigger and better project photos, new features, and

rich media content. Within the articles, you’ll notice larger photos,

new layouts, and an updated resource box.

Now referred to as “CC Materials,” you can

access code and project files directly on your

mobile device, using the QR code provided,

or by visiting circuitcellar.com/ccmaterials.

Some articles have supplemental videos, so

look for the icon highlighting those features!

Content is also growing and expanding with the addition

of a new columnist, Ayse Coskun, an electrical engineering

professor at Boston University. CC’s first female columnist,

Ayse’s bi-monthly column will focus on energy-efficient

hardware and software design strategies. Also check out

the new CC World section, which highlights happenings

and important info relating to CC’s international community

of engineers, academics, and students.

As we move forward, CC’s mission remains the same: we’ll provide electrical engineers relevant and timely content to help them excel in the field embedded design. We hope you enjoy the new package and continue to share the brilliance that is Circuit Cellar with colleagues and peers.

Best Regards, The Circuit Cellar Team

On the cover, and throughout the issue, you’ll see the new company logo. Designed

to highlight the two “Cs” in Circuit and Cellar, it’s a modern twist on an old classic. The dark

covers have been replaced by a bright, open design that highlights feature content.

Page 20: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27818IN

DU

STRY

& E

NTER

PRIS

E

PRODUCT NEWS

DUAL-CHANNEL 3G-SDI VIDEO/AUDIO CAPTURE CARDThe PCIe-2602 is an SDI video/audio

capture card that supports all SD/HD/3G-SDI signals and operates at six times the resolution of regular VGA connections. The card also provides video quality with lossless

full color YUV 4:4:4 images for sharp, clean images.

The PCIe-2602 is well suited for medical imaging and intelligent video surveillance and analytics. With up to 12-bit pixel depth, the card provides extreme image clarity and smoother transitions from color-to-color enhance image detail to support critical medical imaging applications, including picture archiving and communication system (PACS) endoscopy and broadcasting.

The card’s features include low latency uncompressed video streaming, CPU offloading, and

support for high-quality live viewing for video analytics of real-time image acquisition, as required in casino and defense environments. PCIe-2602 signals can be transmitted over 100 m when combined with a 75-Ω coaxial cable.

The PCIe-2602 is equipped with RS-485 and digital I/O. It accommodates external devices (e.g., PTZ cameras and sensors) and supports Windows 7/XP OSes. The card comes with ADLINK’s ViewCreator Pro utility to enable setup, configuration, testing, and system debugging without any software programming. All ADLINK drivers are compatible with Microsoft DirectShow.

Contact ADLINK for pricing.

ADLINK Technology, Inc.www.adlink.com

LINEAR REGULATOR WITH CURRENT AND TEMPERATURE MONITOR OUTPUTSThe LT3081 is a rugged 1.5-A wide input voltage range

linear regulator with key usability, monitoring, and protection features. The device has an extended safe operating area (SOA) compared to existing regulators, making it well suited for high input-to-output voltage and high output current applications where older regulators limit the output.

The LT3081 uses a current source reference for single-resistor output voltage settings and output adjustability down to ”0.” A single resistor can be used to set the output current limit. This regulator architecture, combined with low-millivolt regulation, enables multiple ICs to be easily paralleled for heat spreading and higher output current. The current from the device’s current monitor can be summed with the set current for line-drop compensation, where the LT3081’s output increases with current to compensate for line drops.

The LT3081 achieves line and load regulation below 2 mV

independent of output voltage and features a 1.2-to-40-V input voltage range. The device is well suited for applications requiring multiple rails. The output voltage is programmable with a single resistor from 0 to 38.5 V with a 1.2-V dropout. The on-chip trimmed 50-µA current reference is ±1% accurate. The regulation, transient response, and output noise (30 µVRMS) are independent of output voltage due to the device’s voltage follower architecture.

Two resistors are used to configure the LT3081 as a two-terminal current source. Input or output capacitors for stability are optional in either linear regulator or current-source operation mode. The LT3081 provides several monitoring and protection functions. A single resistor is used to program the current limit, which is accurate to ±10%. Monitor outputs provide a current output proportional to temperature (1 µA/°C) and output current (200 µA/A), enabling easy ground-based measurement. The current monitor can compensate for cable drops. The LT3081’s internal protection circuitry includes reverse-input protection, reverse-current protection, internal current limiting, and thermal shutdown.

A variety of grades/temperature ranges are offered including: the E and I grades (–40°C to 125°C), the H grade (–40°C to 150°C), and the high-reliability MP grade (–55°C to 50°C). Pricing for the E-grade starts at $2.60 each in 1,000-piece quantities.

Linear Technology Corp.www.linear.com

Page 21: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 19IND

USTRY &

ENTERPRISE

PRODUCT NEWS

LOW-POWER, HIGH-EFFICIENCY BOOST REGULATORThe TS3300 is an ultra-low-power, load-

independent, high-efficiency boost regulator. It operates from 0.6 to 4.5 V and can deliver at least 75 mA of continuous output current.

The TS3300 can be powered from a variety of power sources including single- or multiple-cell alkaline or single Li-chemistry batteries. The boost regulator’s output voltage range can be user-specified from 1.8 to 5.25 V to simultaneously power a range of low-power analog circuits, microcontrollers, and low-energy Bluetooth radios.

The TS3300 produces a 3-V output from a 1.2-V input source. Its efficiency performance is constant over a 100:1 span in output current. To power low-energy radios, the TS3300’s internal, low-dropout linear regulator can deliver up to 100-mA output current while reducing boost-converter-generated output voltage ripple.

Drawing only a 3.5-µA no-load supply current, the TS3300 is ideal for “always on” and other battery-powered or portable applications requiring an extended battery run-time. The boost regulator operates from low power sources (e.g., photovoltaic cells to three alkaline cells) and is ideally suited for handheld/portable applications (e.g., wireless

remote sensors, RFID tags, wireless microphones, solar cell post-regulator/chargers, post-regulators for energy harvesting, blood glucose meters, and personal health-monitoring devices).

The TS3300 is fully specified over a –40°C-to-85°C temperature range and is available in a low-profile, thermally enhanced 16-pin 3-mm × 3-mm TQFN package with an exposed backside paddle. The TS3300 costs $0.85 in 1,000-unit quantities.

Touchstone Semiconductor, Inc.http://touchstonesemi.com

PARALLAX DEBUTS THREE NEW PRODUCTSParallax, which designs and manufactures

microcontroller development tools and small single-board computers, recently introduced three new products, the Single Relay Board, the SCP1000 Pressure Sensor Module, and the Propeller Mini.

You can use the Single Relay Board to turn lights, fans, and other devices on or off while keeping them isolated from your microcontroller. The Single Relay Board’s on-board relay enables you to control high-power devices (up to 10 A). The relay’s control is provided via a 1 x 3 header that works well with servomotor cables and conveniently connects to many development boards.

The SCP1000 Pressure Sensor Module is an absolute pressure sensor capable of detecting atmospheric pressure from 30 to 120 kPa. The sensor also provides temperature data. A single multiplication operation using constants obtains pressure data in kilopascals or temperature in degrees Celsius. The pressure data is internally calibrated and temperature compensated. The SCP1000 features four

measurement modes in addition to Standby and Power Down mode. A SPI bus handles the sensor’s communication and provides additional control lines (e.g., interrupt line and trigger input).

The Propeller Mini can embed a multi-core microcontroller system in small-sized projects where a full-sized development board is impractical. With its small size and component count, the Propeller enables you to have a complete prototyping system or project while maintaining a small footprint.

The Propeller features many options. For breadboarding, you can solder the included header onto the board. To keep your project’s control system small, you could solder your project’s wire leads directly to the board’s through holes. You can also solder sockets onto the Propeller Mini, enabling it to plug into a prototyping board

containing your sensors and other components.

The Single Relay Board costs $9.99. The SCP1000 Pressure Sensor Module and the Propeller Mini cost $24.99.

Parallax, Inc.www.parallax.com

Page 22: Circuit Cellar Sept 2013 153198-Issue 278 Sept

ADVERTISEMENT

The previous DesignSpark Tips and Tricks arti-cles have discussed how to set up and configure DesignSpark from a new installation perspective. In this installment, we will look at how to use libraries to create a schematic and PCB design in DesignSpark.

What are libraries?When we created schematic title blocks, we started by creating a schematic symbol in the schematic symbol library and then created a com-ponent in the component library that referenced that schematic symbol. That was an example of a schematic documentation component that didn’t need any PCB design information associated with it. But normally you would probably want to create components that would incorporate the information as shown in Figure 1.

The schematic symbol is stored in a schematic symbol library file (*.ssl), the PCB footprint is stored in a PCB symbol library and the 3D CAD model is stored in a 3D view library file (*.pkg). The top level component is stored in a component library (*.cml) along with the part number and all the technical information. The component library also stores the references to the other libraries needed to complete the component.

DesignSpark uses different files for the different types of library data so that it’s easy to reuse the design information in multiple components. For example, you could make multiple resistor com-ponents by creating one schematic symbol and then reusing it in the other components. Because all the components refer to the same symbol, any changes to it automatically propagate to the components that use it. The same is also true for PCB footprints and the 3D CAD models. The DesignSpark website has a good tutorial about libraries and how they’re used, see [1].

Organizing themThe libraries that come with DesignSpark are usu-ally installed into “C:\Users\Public\Documents\DesignSpark PCB 5.0\Library” and are a good example of how to organize a large component library organized by manufacturer. I prefer to organize my libraries by component type because I also use the libraries as a component part num-ber database. For example, I have a 2N3904 in my transistor library, but I have multiple man-ufacturer part numbers associated with it so I don’t have to remember which transistor man-ufacturers I’ve used previously. I also try and reuse schematic symbols and PCB footprints so those go into generic libraries, which make my library structure look like this:

• Grouped component libraries (transistors, resistors, capacitors, etc.)

• A generic schematic symbol library (resistor symbol, capacitor symbol, etc.)

• A generic surface-mount PCB footprint library (0603 footprint, LQFP footprints, etc)

• A generic through-hole PCB footprint library (DIP footprint, 1/4W resistor footprint, etc.)

So now that we’ve talked about libraries, let’s learn how to use them starting with ModelSource.

ModelSourceIf you haven’t heard, ModelSource is an online database of components that’s available to use in many different PCB software packages includ-ing DesignSpark. I like that DesignSpark directly connects to ModelSource, so you can find compo-

By Neil Gruending (Canada)

Using Libraries

Figure 1. Properties of a component the design software needs.

Schematic Symbol

PCB Footprint

Part Numbers andTechnical Data

3D CAD Model

Component

Page 23: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Tips & Tricks

ADVERTISEMENT

nents without leaving the application (a tutorial is available at [2]). It’s also a great resource to find IPC compliant PCB footprints that meet stan-dard manufacturing guidelines. To open Model-Source in DesignSpark, click on the ModelSource button or go into the “View->ModelSource Bar” and you will see the ModelSource screen shown in Figure 2.

Let’s search for a surface mount MMBT3904 NPN transistor using the parametric search engine. Click on “CLICK TO CHOOSE” and log in if nec-essary. Find a list of the available bipolar tran-sistors by choosing “Semiconductors->Discrete Semiconductors->Bipolar Transistors,” which lists 740 different transistors such as those in Figure 3.

Now let’s narrow down the search results by adding some filters to the columns of data. For “Transistor Type” select “NPN,” “Mounting Type” to “Surface Mount,” “Package Type” to “SOT-23” and “Maximum Collector Emitter Voltage” to “ 40 V.” The second transistor listed is a MMBT3904, which is exactly what we were looking for. After pressing the “Load Preview” button you will get the following screen, where ModelSource will show you the schematic symbol, PCB footprint and some key component design parameters (see Figure 4).

You can also find components using the “Part Number Quick Search” field if you already know a portion of the part number. Now that we’ve found our transistor, click on “Use Component” to use the component in your design and DesignSpark will download the component to a library in the downloaded libraries directory (you can find the full path in the Folders tab in the Library Man-ager). DesignSpark will tell you the name of the library after the component is downloaded. You can now add the transistor to your design by dragging it from the ModelSource window into your design or you can use the usual “Add Com-ponent” toolbar button.

But what do you do when ModelSource doesn’t have the part you want or you want to change something about the component? For example, I would change the MMBT3904 component we found to have a more conventional schematic symbol that shows the emitter. That’s when it’s time to use your own custom libraries.

Custom librariesI always like to create my own set of libraries but that can be a lot of work. So I like to copy com-ponents from other sources when possible and then modify them. For our MMBT3904 example, that would mean copying the downloaded com-ponent information into our own libraries using the Library Manager and then editing the com-ponent as required. This is also a good time to double check everything in case there’s an error.

Figure 2. The ModelSource screen just after opening it.

Figure 3. The ModelSource screen displaying search results.

Page 24: Circuit Cellar Sept 2013 153198-Issue 278 Sept

ADVERTISEMENT

tional manufacturer part numbers. Note that the other attributes are required if you want to use the DesignSpark BOM quoting function.

ConclusionModelSource and DesignSpark’s libraries are a great resource when creating our own set of libraries and they can save a significant amount of time. At this point we can create a schematic. Next time, I will talk about some tricks when editing a schematic and how to generate a bill of materials.

(130207)

Internet References

[1] www.designspark.com/tutorial/components-library-structure-library-manager

[2] www.designspark.com/eng/tutorial/ components-downloading-from-modelsource-building-up-libraries

The most important part of setting up your own libraries is to use common attributes for every component, so that it’s possible to generate reports such as bills of material (BOM). For exam-ple, I prefer to store all of a component’s manu-facturing information in the component library. This means that I usually have multiple manu-facturer part numbers, so I use the attributes as shown in Figure 5 where I’ve added three addi-

Figure 4. Detailed information of a transistor in ModelSource.

Figure 5. Useful attributes of a component.

Page 25: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 23

CLIENT PROFILE

INDU

STRY & ENTERPRISE

NetBurner, Inc. www.netburner.com

5405 Morehouse Drive, San Diego, CA 92121

CONTACT: [email protected]

EMBEDDED PRODUCTS/SERVICES: The NetBurner solution provides hardware, software, and tools to network enable new and existing products. All components are integrated and fully functional, so you can immediately begin working on your application.

PRODUCT CATEGORIES: Serial to Ethernet: Modules can be used out of the box with no programming, or you can use a development kit to create your own custom applications. Hardware ranges from a single chip to small modules with many features.

Core Modules: Typically used as the core processing module in a design, core modules include the processor, flash, RAM, and on-

board network capability. The processor pins are brought out to connectors and include functions such as SPI, I2C, address/data bus, ADC, DAC, UARTs, digital I/O, PWM, and CAN.

Development Kits: Development kits can be used to customize any of NetBurner’s Serial-to-Ethernet or Core Modules. Kits include the Eclipse IDE, a C/C++ compiler/linker, a debugger, a RTOS, a TCP/IP stack, and board support packages.

PRODUCT INFORMATION: The MOD54415 and the NANO54415 modules provide 250-MHz processor, up to 32-MB flash, 64-MB DDR, ADC, DAC, eight UARTs, four I2C, three SPI, 1-wire, microSD flash socket, five PWM, and up to 44 digital I/O.

EXCLUSIVE OFFER: Receive 1 5 % o f f o n s e l e c t development kits. Promo code: CIRCUITCELLAR

Circuit Cellar prides itself on presenting readers with information about innovative companies, organizations, prod-ucts, and services relating to embedded technologies. This space is where Circuit Cellar enables clients to present readers useful information, special deals, and more.

2.6 KERNEL

ARM System on Module

Manufactured in the USA the SoM-9x25 uses the same small SODIMM form-factor utilized by other EMAC SoM modules and is the ideal processor engine for your next design. All of the ARM processor core is included on this tiny board including: Flash, Memory, Serial Ports, Ethernet, SPI, I2C, I2S Audio, CAN 2.0B, PWMs, Timer/Counters, A/D, Digital I/O lines, Clock/Calendar, and more. The SoM-9x25 is designed to plug into a custom or off-the-shelf carrier board containing all the connectors and any additional I/O components that may be required. The System on Module approach provides the flexibility of a fully customized product at a greatly reduced cost. Quantity 1 price begins at $180.

OVER

28YEARS OF

SINGLE BOARDSOLUTIONS

Since 1985

Phone: ( 618) 529-4525 · Fax: (618) 457-0110 · Web: www.emacinc.com

http://www.emacinc.com/som/som9x25.htm

SoM-9x25

Ÿ Atmel ARM9 400 MHZ Fanless ProcessorŸ Up to 128 MB of DDR2 SDRAMŸ Up to 4GB eMMC FlashŸ Up to 16MB Serial Data FlashŸ 6 Serial Ports, 2 I2C and 2 SPI ports Ÿ 1 High Speed USB 2.0 Host portŸ 1 Full Speed USB 2.0 Host portŸ 1 High Speed USB 2.0 Device portŸ CAN 2.0 B Controller, I2S Audio PortŸ 10/100 BaseT Fast Ethernet with PHYŸ Access to Processor BusŸ 4 Channels of 10-Bit A/D & 32 GPIO LinesŸ SD/MMC Flash Card InterfaceŸ System Reset, Real Time ClockŸ Timers/Counters, PWM controllerŸ Small, 144 pin SODIMM form factor (2.66” x 1.50”)

EQUIPMENT MONITOR AND CONTROL

Wide Temperature

PCB-

POOL®

is a

reg

iste

red

trad

emar

k of

Bet

a LA

YOUT

Gm

bH

& present

www.pcb-pool.com

www.magic-pcb.com

www.pcb-pool.com

www.magic-pcb.comwww.magic-pcb.com

Embedded RFID • Authenticating • Tracking • Protecting • Tracking • Protecting • Protecting • Protecting

NOW available

- with antenna connection

- for all quantities

Get your UHF RFID Kit at www.beta-eSTORE.com

Page 26: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27824FE

ATU

RES

The Rubik’s Cube 3-D sequential-move puzzle was a 1980s sensation. I’m not sure

when I got my first one, but I do remember never being able to solve the puzzle, even after I’d purchased a book that guaranteed my success.

When the 25th anniversary Rubik’s Cubes appeared, I was determined that I would rectify this particular childhood deficiency. While researching solution methods online, I came across several interesting robotic cube solvers and decided to build one (see Photo 1).

I chose a Parallax Propeller microcontroller because I thought the platform’s multiple-cog structure might be beneficial when executing a search algorithm. However, the multiple cogs were most useful in letting my cube solver search for a solution while trying to

physically solve the puzzle.

CUBE STRUCTURE AND NOTATIONThe Rubik’s Cube apparently consists of 3

× 3 × 3 equally sized cubes, which are called cubies. The six cube faces appear as a 3 × 3 array of colored tiles or stickers, which are called facelets. The standard facelet colors are red, orange, blue, green, white, and yellow.

Standard Rubik’s Cubes actually consist of 12 edge cubies, eight corner cubies, and one center piece. The center piece has three axes, each of which is capped with two colored facelets. Each of the 12 edge cubies has two colored facelets and sits between the facelets at each end of the three axes. Each of the eight corner cubies has three colored facelets and sits at the cube’s corners.

The six cube faces can be independently rotated. The center facelets will rotate, but they do not move in the sense that the cube can always be reoriented so the center facelets return to any predefined orientation. As the cube faces are rotated, the cubies move between positions, which are called cubicles. In addition, the corner cubies can twist clockwise or counterclockwise and the edge cubies can flip.

A. H. Frey and D. Singmaster’s Handbook of Cubik Math includes a standard notation that describes the cube, its components, and permutation.[1] Figure 1 shows an annotated “unfolded” cube using common Rubik’s Cube face colors and conventional labels (U)p, (D)own, (F)ront, (B)ack, (L)eft, and (R)ight.

When referring to cube moves, I will use both lowercase and uppercase non-italicized letters. For the front face, F indicates rotating the face a one-quarter turn clockwise, f indicates rotating the face a one-quarter turn counterclockwise, and F2 indicates rotating

Rubik’s Cube-Solving RobotThe Rubik’s Cube 3-D sequential-move puzzle achieved popularity more than 25 years ago. You can use modern technology to more easily solve the puzzle. This article describes a microcontroller-based robot that turns the Rubik’s Cube’s faces and uses a 52-move algorithm.

By Nelson Epp (Canada)

PHOTO 1The completed robot turns a Rubik’s Cube’s face. The robot uses Thistlethwaite’s table-based algorithm and a Parallax Propeller microcontroller to solve the puzzle. (Visit circuitcellar.com/ccmaterials to see a video of the robot at work.)

Page 27: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 25FEATU

RES

the face one-half turn. A similar pattern is followed to move all the cube faces.

I will use italics when referring to cubicles and cubies. Uppercase letters refer to cubies. Lowercase letters refer to the cubicles. I will use two letters to refer to edge cubies and cubicles (e.g., UF refers to the cubie shared by the Up and the Front face, while uf refers to the cubie’s home location when the cube is solved). I will use three letters to refer to corner cubies and cubicles (e.g., UFR refers to the cubie shared by the Up, Front, and Right faces, while ufr refers to the cubie’s home location when the cube is solved). There is significance to the letter order used to refer to edge and corner cubies and cubicles, but is beyond this article’s scope.

The cube has certain logical structures that orient it and provide a consistent method to describe the solution. Figure 1 shows all the cubies in their home cubicles with all the pieces in their unflipped and untwisted orientations. Every cubie has a chief facelet and every cubicle has a chief position.

An edge cubie is unflipped if its chief facelet is in a chief position. A corner is untwisted if the chief facelet is in the cubicle’s chief position. A corner is twisted if the cubie’s chief facelet is positioned clockwise or counterclockwise with respect to the cubicle’s chief position. Chief positions are marked with crosses. The chief facelets are marked with circles. The chief positions do not change with face moves but the chief facelets will change.

Figure 2 shows the result of a single R turn. Notice how the edges moved from their home positions and no longer have their chief facelets in the chief cubicle position. Therefore, edge cubies in ur, rb, rd, and fr are now flipped. In addition, cubicles ufr and dbr are rotated counterclockwise and cubicles ubr and dfr are rotated clockwise.

Another important logical structure used in the solution algorithm is the tetrad, which is a logical grouping of four non-touching cubies. Figure 3 shows the five tetrads.

SOLUTION ALGORITHMMy cube solver uses a solution method

developed by mathematician Morwen Thistlethwaite. The method uses the mathematical concepts of a group, a subgroup, and generator and coset representatives. A group is a set of objects and an operation. A subgroup is just a group with the same operation as the group, but with a subset of the group’s objects. Generators enclosed within angle brackets (< >) express a group. The generators are the moves (e.g., a single clockwise or counterclockwise face turn or

a double face turn) that are combined to form all the possible permutations within the group. The permutation resulting from a finite combination of the generators is an object of the group. The operation “do this move next” is shared with all the groups. A coset representative is a set of moves specifically chosen to transition from a group to a subgroup of that group.

In Thislethwaite’s method, the cube is moved through a series of nested subgroups. Each successive subgroup uses a more restrictive set of generators, which reduces the possible cube permutations until the cube is solved.

There are five groups/subgroups for this method: G0, G1, G2, G3, and G4. The goal in going from G0 to G1 is to use any combination of the moves from the group <L, R, F, B, U, D, l, r, f, b, u, d> to unflip any flipped edges. All other aspects of the cube (e.g., corner or edge cubie positions) can be ignored. G1 consists of all the cube permutations in which none of the edges are flipped. All moves permitted in G2, G3, and G4 will leave the edges cubies unflipped.

For the transition to G2, the method uses information about the corners’ twistedness and the location of the edge cubies whose home position is in the cube’s middle slice (i.e., fl, bl, fr, and br). In G2, all edges with home positions in the middle slice should be in that slice. Their positions within the four possible edge cubicles don’t matter. In addition, all corners should be untwisted. The moves <L2, R2, F, B, U, D, f, b, u, d> used in G1 will not flip edge cubies.

FIGURE 1This “unfolded” cube uses common colors, which are mapped to the R, L, F, B, U, and D faces described in this article. Chief positions are marked with crosses. Chief facelets are marked with circles. Face turns will move the chief facelets but they will not move the chief positions.

FIGURE 2After a single right face turn, the chief facelets move away from chief positions, which results in flipped and twisted cubies.

Page 28: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27826FE

ATU

RES

The transition to G3 is different from the other three transitions. To get to G3, you are limited to the moves <L2, R2, F2, B2, U, D, u, d>. Using these moves, you cannot flip or twist any edge or corner, nor can you remove the middle slice edges from their tetrad. The goal is to place the eight edge cubies—those outside the middle slice—and the eight corners into their correct tetrads. The complication with getting to G3 is that, while both edge tetrads and one corner tetrad can exist in any permutation, the second corner tetrad is limited, for each permutation of corner tetrad, to one of four permutations.

To reach the solved position, the moves are limited to only half-face turns <L2, R2,

F2, B2, U2, D2>. Using these moves, the cube solver must return all edges and corners to their home locations. You don’t have to worry about flipping edges, twisting corners, or removing cubies from their tetrads as the permitted moves can’t do this.

COSET AND LOOKUP FILESA complete set of coset representatives

is required for each group-to-subgroup transition G0 to G1, G1 to G2, G2 to G3, and G3 to G4. I used an algorithm that calculates a list of all the coset representatives that will take any permutation from one group into its subgroup. The resulting list is written to a text file the Propeller uses to compare the scrambled cube’s permutation with all the listed permutations. Once a match is found, it reads off the associated coset representative.

The coset lists for G1 to G2, G2 to G3, and G3 to G4 are very large. For these transitions, a second algorithm uses an encoded permutation to sort the list and creates an index or lookup file based on the encoded permutation. A PC-based Windows console program written in C++ is used to generate these coset lists and lookup files.

FIGURE 3These are the five tetrads. A tetrad is a logical group of four non-touching cubies.

B1

153

454

3L2

254

353

4F1

153

454

3

U1

124

323

4

D1

124

323

4

R2

254

353

4

FIGURE 4The circuit is centered around a 40-pin Parallax Propeller micro-controller. The 3.3-V regulator powers most of the digital devices including the RS-232 interface, EEPROM, oscillator, and SD card. The 5-V regulator powers the camera board and is used as the signaling level to the servomotors. A separate supply powers the servomotors.

Page 29: Circuit Cellar Sept 2013 153198-Issue 278 Sept

XCM-019 seriesSpartan-6 FGG484 FPGA board

XC6SLX45-2FGG484CXC6SLX75-2FGG484CCredit card size (86 x 54 mm)RoHS compliant

XC5VLX30-1FFG676CXC5VLX50-1FFG676CXC5VLX85-1FFG676CXC5VLX110-1FFG676CCompact size (43 x 54 mm)

RoHS compliant

XCM-109 seriesVirtex-5 FFG676 FPGA board

XC6SLX100-2FGG676CXC6SLX150-2FGG676CCredit card size (86 x 54 mm)

RoHS compliant

XCM-206 seriesSpartan-6 FGG676 FPGA board

XCM-020 seriesSpartan-6 LXT FGG484 FPGA board

XC6SLX45T-2FGG484CXC6SLX75T-2FGG484CXC6SLX100T-2FGG484CXC6SLX150T-2FGG484CCredit card size (86 x 54 mm)RoHS compliant

www.hdl.co.jp/CC/

ww

w.h

dl.

co.j

p/C

C/

SAVING COST=TIME with readily available FPGA boards■ Basic and simple features, single power supply operation■ Quality and reliability is provided by years of sales■ Same board size and connector layout – ACM/XCM series■ All stocked items are ready to be shipped immediately■ Over 100 varieties of FPGA/CPLD boards are available■ Customizing speed grade and/or any features are possible■ Free download technical documents before purchasing■ High quality and highly reliable FPGA /CPLD boards from Japan■ Almost all products are RoHS compliance

E-m

ail :

s2@

hd

l.co

.jp

Fax

: +81

-72-

620-

2003

Spartan-6 PLCC68 FPGA Module

XILINX PLCC68 Series

FPGA/CPLD Stamp ModulePLCC68 SeriesFPGA/CPLD Stamp ModulePLCC68 SeriesEasy and Quickly Mountable Module

FPGA Module IC socket mountable• 50 I/Os (External clock inputs

are available)• 3.3V single power supply

operation (Voltage converters for auxiliary power supply are built-in)

• Separated supply-inputs: Core, I/O drivers• JTAG signal • All PLCC68 series have common pin

assignment• Very small size (25.3 x 25.3 [mm])• RoHS compliance• MADE IN JAPAN

XP68-03

XC6SLX45-2CSG324C3.3V single power supply operationOn-board oscillator, 50MHzRoHS compliant

Cyclone III PLCC68 FPGA Module

ALTERA PLCC68 Series

AP68-04

EP3C25U256C8N3.3V single power supply operationOn-board oscillator, 50MHzRoHS compliant

See all our products, A/D D/A conversion board, boards with USB chip from FTDI and accessories at :

FPGA / CPLD Boards from JAPAN

XILINX FPGA BoardCyclone IV E F780 FPGA board

ALTERA FPGA Board

EP4CE30F29C8NEP4CE40F29C8NEP4CE115F29C8NCredit card size (86 x 54 mm)

RoHS compliant

ACM-204 series

EP3C55F780C8NEP3C80F780C8NEP3C120F780C8NCredit card size (86 x 54 mm)

RoHS compliant

ACM-202 seriesCyclone III F780 FPGA board

■ One for general power(3.3V 3A max) and the Two variable outputs for Vccio(0.8V to 3.3, 3A max) ■ For ACM/XCM-2 series FPGA boards■ Power Switch and LED■ Power input:DC5V/2.1[mm] Jack/ Terminal Block (option)■ Board size : 156x184 [mm]■ 4 Layers PCB, Thru-hole

Universal Board (Type2)

ZKB-106Cyclone IV USB-FPGA Board

USB- FPGA Board

EP4CE15F17C8NCompact size (54 x 53 mm)

RoHS compliant

EDA-301Spartan-6 USB-FPGA board

XC6SLX16-2CSG225CCompact size (54 x 53 mm)

RoHS compliant

EDX-301

5" LCD Touch Panel Module5 inch TFT full color LCD displaywith WVGA(800x480) resolution resistive touch panel

UTL-021

EPM1270T144C5NCompact size (54 x 53 mm)

RoHS compliant

ACM-302-1270MAX II T144 CPLD board

ACM-108 seriesCyclone IV GX F484 FPGA board

EP4CGX50CF23C8NEP4CGX110CF23C8NEP4CGX150CF23C7NCompact size (43 x 54 mm)RoHS compliant

• 3.3 V single power supply operation• Piezo buzzer to beep• Useful plastic bezel is included to assemble• LTM-compatible pin assignment

Page 30: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27828FE

ATU

RES

There are seven of these programs in total. Four programs are used to calculate the coset representatives for the transitions G0 to G1, G1 to G2, G2 to G3, and G3 to G4. The other three programs are used to reorder the coset representatives generated for the G1 to G2, G2 to G3, and G3 to G4 transitions and generate the lookup files. The outputs from all of these programs are human-readable text files.

The SD card stores eight files that hold all the coset information required by the cube solver. There are four coset representative and four lookup files. The files are named G0toG1LU.txt, G0toG1.txt, G1toG2LU.txt, G1toG2a.txt, G2toG3LU.txt, G2toG3a.txt, G3toG4LU.txt, and G3toG4a.txt. The file names indicate the group-to-subgroup transition. A post-fixed “LU” indicates a lookup table while an “a” signifies a sorted coset representative file. The coset list from G0 to G1 is relatively small, so G0toG1LU.txt is simply an empty file that is only kept for consistency.

HARDWARE COMPONENTSThe cube solver hardware uses two external

power supplies: 5 VDC for the servomotors and 12 VDC for the remaining circuits. The 12-VDC power supply feeds a Texas Instruments (TI) UA78M33 and a UA78M05 linear regulator. The UA78M05 regulator powers an Electronics123 C3088 camera board. The UA78M33 regulator

powers a Maxim Integrated MAX3232 ECPE RS-232 transceiver, a Microchip Technology 24LC256 CMOS serial EEPROM, remote reset circuitry, the Propeller, a SD/MMC card, the camera board’s digital output circuitry, and an ECS ECS-300C-160 oscillator. Figure 4 shows a complete schematic. Photo 2 shows my cube solver and circuit board.

The ECS-300C-160 is a self-contained dual-output oscillator that can produce clock signals that are binary fractions of the 16-MHz base signal. My application uses the 8- and 16-MHz clock taps. The Propeller is clocked with the 8-MHz signal and then internally multiplied up to 64 MHz. The 16-MHz signal is fed to the camera.

I used a MAX3232 transceiver to communicate to the host’s RS-232 port. The Propeller’s serial input pin and serial output pin are only required at startup. After the Propeller starts up, these pins can be used to exchange commands with the host. The Propeller also has pins for serial communication to an EEPROM, which are used during power up when a host is not sending a program.

The cube-solving algorithm uses the coset representative file stored on an SD card, which is read by the Propeller via a SparkFun Electronics Breakout Board for SD-MMC cards. The Propeller interface to the SD card consists of a chip select, data in, data out, data clock, and power. The chip select is fixed into the active state. The three lines associated with data are wired to the Propeller.

The Propeller uses a camera to determine the cube’s starting permutation. The C3088 uses an Electronics123 OV6630 color sensor module. I chose the camera because its data format and clocking speed was within the range of the Propeller’s capabilities. The C3088 has jumpers for external or internal clocking.

To make the board work, I had to remove the on-board clock and install a jumper for the external clock. The camera board interfaces to the Propeller via vertical sync, horizontal reference, pixel clock, luminosity (Y) data bus, and the color (UV) data bus. Both of these data buses are powered from the 3.3-VDC source to meet the Propeller’s voltage levels. The camera also has an I2C interface, which is wired but not used for the cube solver. Because of the Propeller’s limited pin count, I only used the UV data bus’s seven most significant bits (MSBs).

For debugging purposes, the Propeller generates a small monochrome image on a NTSC-compatible TV. Four dedicated pins are used to make the Propeller’s NTSC interface. One of these pins is for the aural carrier and is not used in this project. The other three

FIGURE 5a—A single face turn is shown. The grippers at the end of ARM1 and ARM2 hold the cube while the SERVO1 gripper turns the face. b—This action is used to turn the whole cube. With grippers at the end of ARM1 and ARM2 fully retracted, SERVO1 is free to turn the entire cube. c—A cube flip requires two steps. In Step 1, ARM1 overextends to tilt the cube. d—In Step 2, ARM1 retracts and ARM2 extends pushing the flipped cube back into the cup.

b)a)

d)c)

Page 31: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 29FEATU

RES

make a simple DAC, which is connected to my TV’s RCA input.

The RobotShop JoinMax Mini-Servomotor (SERVO1) is a rotational servomotor. The two RobotShop Firgelli Technologies L12 Actuators are servomotors (ARM1 and ARM2) with a linear actuation. All three servomotors use a standard RC-type interface where a 1-ms pulse moves the servomotor to its 0% position and a 2-ms pulse moves the servomotor to its 100% position. The pulse is updated every 20 ms. Transistors interface the 3.3-VDC Propeller I/O to the 5-V logic level required by the servomotors.

ARM1 and ARM2 flip the cube in the color-scanning process and hold the cube during a face twist. ARM1 and ARM2’s “grippers” are a 3” section of a paint stir stick with two plastic L brackets. The SERVO1 “gripper” is a shallow (with a depth of about two thirds the length of one side of the cubie facelet) cup that is just slightly larger than the whole cube. The L brackets are bent outward from the cube to handle the slop in the cube cup. During an orientation move, the slop in the cup size enables a little cube movement within the cup but not enough to put it out of alignment with the ARM1 and ARM2 grippers. ARM1 has a rotational degree of freedom enabling it to swing up and down but not side to side while ARM2 is fixed.

With ARM1 and ARM2 extended and gripping the cube, SERVO1 turns the face sitting in the cup (see Figure 5a). During a face turn, SERVO1 slightly extends its turn angle to ensure that the face is completely turned. With ARM1 and ARM2 retracted, SERVO1 is responsible for turning the whole cube (see Figure 5b). Figure 5c and Figure 5d demonstrate how the cube is flipped. ARM2 is completely retracted and ARM1 overextends until the cube is tipped, sitting on only one edge of one face. ARM2 then begins to extend and will rotate the cube by forcing it to slide back into the cup until it reseats. Partway through ARM1’s motion, ARM2 starts to return to its home position. This prevents the cube from being pulled back when ARM1 retracts.

FIRMWAREI used Parallax Propeller Tool 1.2.7 (R2)

programming software to write the cube solver firmware in Assembly language. The Propeller has eight small independent processors or cogs that have local memory for both program and data but also have access to global RAM and ROM. The cube solver’s firmware is divided into 10 routines that are loaded into the cogs as required by the ST_CONT routine that runs in cog 0.

When the cube solver powers up, a low-resolution video image is captured from

the camera and displayed on the TV. The CAM_CAP routine captures Y or luminosity data from camera. In its startup mode, the camera generates 352 × 288 pixels of Y, U, and V color data. CAM_CAP grabs every fourth pixel (for a total of 88 pixels) from a single line and stores this data locally in the cog.

Once a data line is complete, CAM_CAP transfers pixel data to global memory. CAM_CAP grabs 72 lines (every fourth line) of the video image in this manner. This data is stored in global memory with 8 bits of resolution.

Page 32: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27830FE

ATU

RES

The PRO4_OP routine transfers one screen worth of data to a global memory location shared with VID_OP, which is the video output routine. VID_OP uses the cog’s video hardware to generate the NTSC signal. The cube solver only uses a bit depth of 2, so only the top 2 bits of each pixel are used.

To make the 88 × 72 pixel image fill the video screen, the VID_OP and PRO4_OP routines double each pixel’s width and height. The image was useful during debugging, but under normal conditions, the image is helpful to confirm that the cube is centered in the camera.

Before starting, the cube must be oriented with the F face directly up and the L face closest to ARM2. Once the start signal is received from the host, the ACTU routine controls the servomotors to reorient the cube and start each face’s color analysis. ACTU determines the required turns and flips to orient the cube by starting from a known orientation and then keeping track of where each face is moved to as the commands are executed. When a face turn command is received, the ACTU routine uses a specific sequence of flips and spins to orient the cube and then executes a face or inverse face turn.

Color analysis consists of scanning pixel data from each of the nine facelets seen by the camera. The CLR_CAP and CAM_CAP routines capture small 6 × 4 pixel samples of the Y, U, and V images around each facelet’s center. For the center facelet, all pixel data is stored in global memory. For the other eight facelets, only the color data’s average value from the pixels is stored. After each face is scanned, the ACTU routine reorients the cube to scan the next face. Once all the faces are captured, the cube is reoriented to the starting position for solving. During this reorientation, the FC routine is started to determine each facelet’s color.

When a standard cube is scrambled, the center facelets rotate but otherwise remain unchanged. The center face color information is used as the basis for determining the other facelets’ color. In the FC routine, the average value of the center facelet’s color is calculated then each facelet’s average color, in turn, is compared to these six colors. The comparison is done by calculating the sum of the squares of the difference between each component Y, U, and V with each facelet color’s Y, U, and V. The smallest sum is considered the matching color.

Once all the facelet colors are determined, the STCB, VIRT_CT, and SPI routines are started. The STCB routine drives the process of determining the moves that will solve the cube. At each stage, transitioning from one group to the next subgroup of the cube solution, the STCB routine encodes the cube’s permutation.

PROJECT FILES

circuitcellar.com/ccmaterials

REFERENCE

[1] A. H. Frey and D. Singmas-ter, Handbook of Cubik Math, Lutterworth Press, 2010.

RESOURCES

N. Epp, “Rubik’s Cube-Solving Robot,” video, www.youtube. com

Morwen Thistlethwaite, Depart-ment of Mathematics, University of Tennesee.

SOURCES

ECS-300C-160 Oscillator

ECS, Inc. | www.ecsdav.com

C3088 Camera board and OV6630 color sensor module

Electronics123, Inc. | www.electronics123.com

MAX3232 ECPE RS-232 Transceiver

Maxim Integrated, Inc. | www.maximintegrated.com

24LC256 CMOS Serial EEPROM

Microchip Technology, Inc. | www.microchip.com

Propeller microcontroller and Propeller Tool 1.2.7 (R2) programming software

Parallax, Inc. | www.parallax.com

Firgelli Technologies L12 Actuators and JoinMax Mini-Servomotor

RobotShop Distribution, Inc. | www.robotshop.com

Breakout board for SD-MMC cards

SparkFun Electronics | www.sparkfun.com

UA78M33 and UA78M05 Linear regulator

Texas Instruments, Inc. | www.ti.com

PHOTO 2a—The cube solver has three servomotors: one servomotor is a standard rotational device, while the other two drive linear actuators. The cube sits in the cup controlled by the rotational servomotor and is used to turn the whole cube or twist one face. The servomotors with the linear actuators are used to hold the cube during a face turn or flip the cube. A camera is mounted upside down above the cube with the Parallax Propeller microcontroller and supporting hardware. b—The cube solver uses a camera module to scan the cube, the Propeller for the computations, a Maxim MAX3232 transceiver to communicate to the host, EEPROM for program storage, an SD card to store the lookup files, regulators, an oscillator to drive the Propeller and the camera, and transistors to drive the servomotors.

a)

b)

Page 33: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 31FEATU

RES

The permutation is encoded in up to three permutation words, which are stored in an ASCII human-readable format. These words are encoded in the same format as the tables on the SD card. Global memory is used to pass them to the SPI routine, which uses the words to look up the permutation in the files stored on the SD card and returns the associated moves required to move the cube to the next subgroup. These moves are copied to a global memory space so the ACTU and VIRT_CT routines start executing the moves on the physical cube as well as a virtual cube stored in VIRT_CT local memory.

I used a Windows XP PC to format the SD card to FAT16. The coset and lookup files are stored in the order in which they will be read. Upon initialization, the SPI routine locates the start of the file allocation table (FAT) using information stored

in the master and primary boot records. The FAT is used to calculate the offset into the location of the one and only directory. The offsets to each lookup and coset file are sequentially stored in the file entries related to the directory.

It takes a relatively long time to execute the solution on the physical cube and look up solutions on the SD card. To enable the calculation of the

solution to advance while the ACTU routine completes its actions, the VIRT_CT routine holds a virtual cube in local memory and executes any moves on that virtual cube. At startup, VIRT_CT is initialized with the initial permutation of the scanned cube. When the SPI routine finds a combination of moves to transition from the existing group to the next subgroup, the VIRT_CT routine will execute the determined moves on the virtual cube. The ST_CONT routine can then use the STCB routine to encode the virtual cube permutation and get SPI to find the next solution to the next subgroup. Meanwhile, the ACTU routine drives the physical actuators, transitioning the cube to the next subgroup.

WRITER and READER routines handle the RS-232 communications from any cog to the host PC shared buffers in global memory. Under normal conditions, the initial start command—the only command sent by the host—is received from the host via READER. WRITER is used to update the host when a solution is found for each group.

UNEXPECTED RESULTSWhen I started this project, I suspected that the Propeller’s

multiple-cog feature would be most useful in executing a large search algorithm. But, in practice, the multiple cogs were most beneficial in enabling the relatively quick solution to be found while the slow physical solution followed.

ABOUT THE AUTHORNelson Epp ([email protected]) is the Quality Manager for the Oil and Gas group at Stantec Consulting in Edmonton, Alberta, Canada. His main technical interest is “using microcontrollers to do fun but basically useless things.” Nelson has degrees in Physics and Electrical Engineering.

Finding the right parts for your robot can be difficult, but you also don’t want to spend all your time reinventing the wheel (or motor controller). That’s where we come in: Pololu has the unique products — from actuators to wireless modules — that can help you take your robot from idea to reality.

Find out more at: www.pololu.com

3pi RobotITEM #975

$9995 User-programmable in C/C++

(sample programs available)

Designed to excel at mazesolving and line following

Ships fully assembled with motors, LCD,buzzer, and five reflectance sensors

Zumo Robot for Arduino(Assembled with 75:1 HP Motors)

ITEM #2506

$9995

buzzer, and five reflectance sensors

Includes six IR reflectance sensors for line following or edge detection

Individual parts and kit version also available — build your ownconfiguration!

Arduino-controllable with library support and example sketches

Small enough for mini-sumo (less than 10 cm × 10 cm)

Arduino-controllable with library support and example sketches

Get a little pushy!

170-PointBreadboard

$295ITEM #1488

Other colorsavailable

17 rows of tie points for up to two 14- or 16-pin DIP ICs

Tabs allow multiple units to be connected for larger projects

Breadboard

Other colorsavailable

ITEM #955

$299

Our ball casters make a great thirdcontact point for small two-wheeledrobots.

Ball Caster with 3/4"Metal Ball

Our ball casters make a great third

Other sizesavailable

38 kHz IR Proximity Sensor

ITEM #2460

$595

Fixed-gain modulated IR detector

Small size (0.4" × 0.6")

Typical sensing range up to 24"(60 cm)

38 kHz IR Proximity

Stepper MotorDriver

$795ITEM #2134

DRV8834 driver

4-layer PCB

1/32 microstepping

Low voltage (2.5 V - 10.8 V)

Stepper Motor

ITEM #2134

Dual MC33926 Motor Driver Shield

for ArduinoITEM #2503

$2995

Control two brushed DC motors withan Arduino or Arduino-compatibleboard. Operates between 5 V and28 V and can deliver a continuous 3 Aper motor.

NEMA 23 HybridStepper Motor

$4995

Other sizesavailable

1 A/phase @ 8.6 V

1.8° step angle 190 oz in

56.4 mm × 56.4 mm × 76 mm

ITEM #1477

NEMA 23 Hybrid

·

(qty. 5)

To watch Epp’s robot solve the Rubik’s Cube, go to bit.ly/ccmaterials

Page 34: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27832FE

ATU

RES

In Part 1 of this article series, I introduced the Raspberry Pi single-board computer

(SBC) and explained its initial setup. In the conclusion of this series, I’ll fully describe the circuitry for my multipurpose I/O board, which I call the Iso-Pi. I will also outline the firmware contained in the Atmel ATmega328 microcontroller, which acts as an I/O co-processor for the Raspberry Pi. Photo 1 shows a view of the populated PC board. Figure 1 shows a schematic diagram of the Iso-Pi.

THE VALUE OF ISOLATIONAll the I/O lines on the Raspberry Pi’s

26-pin I/O header are directly connected to a Broadcom BCM2835 processor’s CPU/GPU system on a chip (SoC). They are unbuffered 3.3-V logic signals and are not 5-V logic-tolerant.

In the 25 years I have spent hand-building electronic instruments, I’ve used care and common sense, but I admit that I have not implemented all the typical electrostatic

discharge (ESD) precautions. Fortunately, I’ve never burnt out any IC devices, even when I was using early CMOS devices that were sensitive to ESD. That is until recently, when I managed to destroy two Roving Networks Wi-Fi modules while diagnosing communication problems between these modules and the microcontroller in my circuit. While I implemented level-shifting between the 3.3-V Roving Network modules and the 5-V microcontroller, two separate modules died after I hooked up my oscilloscope probe to monitor the communications lines. Therefore, when I saw numerous “how-to” articles online with pictures of the Raspberry Pi’s I/O ports being connected to breadboards with wires going all over the place, I was somewhat skeptical.

In some instances, 5-V chips were being connected to the Raspberry Pi’s 3.3-V logic lines with little attention given to this logic-level mismatch. I decided to err on the side of caution and design for safety and full Raspberry Pi protection. Admittedly, the fact that I had only one Raspberry Pi board, and the distributors were out of stock of them at the time, played a part in my decision.

I decided to design a multipurpose I/O board that would be completely galvanically isolated from the Raspberry Pi board. This means sensors connected to the board do not share the same ground reference with the Raspberry Pi and any electromagnetic fields (EMFs) generated by larger inductive loads (e.g., motors) can’t work their way back to the sensitive Raspberry Pi circuitry.

Because of shortcomings reported with the 5-V adapters that plug directly into the Raspberry Pi’s tiny microUSB power socket, I decided to use the Raspberry Pi’s 26-pin I/O header’s power pins to run the Raspberry Pi.

Raspberry Pi I/O Board (Part 2)Iso-Pi Circuit Description and FirmwareYou can build an I/O board to interface with the Raspberry Pi single-board computer. The first part of this article series walked you through the computer setup. This article describes the I/O board and explains its configuration.

By Brian Millier (Canada)

PHOTO 1A fully populated Iso-Pi PCB is shown.

Page 35: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 33FEATU

RES

This enabled me to use a single, higher-current power adapter for the Raspberry Pi and the I/O board. Since the Raspberry Pi’s 26-pin I/O header contained two 5-V pins and more than two ground pins, I felt this would be a better power connection than that provided by a microUSB socket.

Two criteria needed to be met to maintain

full galvanic isolation between the Raspberry Pi and the I/O board. First, there had to be some form of isolator device used on all I/O lines. Second, the I/O board needed its own isolated power supply.

The Raspberry Pi I/O header has 17 GPIO pins (nine of which are shared by several serial I/O protocols). That’s not a large number of

FIGURE 1This is the Iso-Pi board’s schematic. All I/O devices are controlled by the Atmel ATmega328 coprocessor, which is controlled by the Raspberry Pi.

Page 36: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27834FE

ATU

RES

GPIOs. And, it would be difficult to decide in advance which ones to use for input and output. Therefore, if you wished to introduce some form of isolation device for these lines, you would need a lot of jumpers on board to configure each isolator for the right signal direction. While the commercially available Gertboard uses a level-shifter IC for the GPIO lines, it does not provide galvanic isolation. It also needs a lot of jumpers to handle pin direction configuration.

I decided to ignore the Raspberry Pi’s GPIO lines and instead use two different serial communications links to the Raspberry Pi. All but one of my Iso-Pi board’s peripheral devices are controlled by an ATmega328 microcontroller (the same chip used on most Arduino boards). The Raspberry Pi uses a 115,200-bps serial link to control the ATmega328. The RxD and TxD lines are galvanically isolated by a Silicon Laboratories Si8421 dual-channel isolator.

Like many of you, I’ve used optoisolators in numerous projects in the past, but they have many disadvantages compared to modern isolators (e.g., the Si4821 dual-channel isolator), notably speed and cost. For about $1, the Si4821 provides one isolated signal path in each direction with transmission speeds up to 150 Mbps (much faster than needed for a 115,200-bps serial link). On both sides of the isolation barrier, the Si4821 will operate with 2.7-to-5.5-V logic levels/power supplies, which will satisfy the requirement to shift the 3.3-V Raspberry Pi signals to the 5-V ATmega328 microcontroller logic levels.

In addition to all the I/O functions contained on the Iso-Pi board, I decided to include a real-time clock (RTC) circuit, as the Raspberry Pi has no hardware-based, battery-backed RTC. I used the ubiquitous Maxim Integrated DS1307 RTC, which has an I2C interface.

Although I prefer the NXP Semiconductors (formerly Philips Semiconductor) PCF8564A RTC, there are Wheezy Linux drivers available for the DS1307 and I don’t have any experience writing Linux drivers for different RTC chips. In “Adding a Real-Time Clock to Raspberry Pi,” AdaFruit Industries provides information about how to interface the DS1307 RTC on the Iso-Pi to Linux.

In keeping with my isolation policy, I also decided to galvanically isolate the Raspberry Pi’s I2C bus. This may have been overkill, but I wanted to provide an isolated I2C bus for other external I2C devices, in addition to the on-board DS1307.

Unlike the serial port with its two unidirectional signal lines, the I2C bus has one bidirectional line (SDA) and one unidirectional line (SCL). The SCL line is technically bidirectional as well, but only in a multi-master bus configuration, which is not what I needed.

Making an isolator work bidirectionally is a bit of a design challenge. I used the Silicon Labs SI8602 isolator, which is specifically designed to handle the I2C bus. The only downside to using the Silicon Laboratories SI8421 and SI8602 isolators is that they were not available in DIP packages. I tried to employ all DIP packages in this design for ease of assembly.

The final piece in the isolation puzzle concerned the power supply for the Iso-Pi board’s I/O devices. It wouldn’t make sense to provide galvanic isolation on the logic signal lines and then power the Iso-Pi’s circuitry from the same power source used to power the Raspberry Pi. Therefore, I incorporated a tiny RECOM Power RI-0505S isolated DC-DC converter on the board. The 5 V from the external power adapter directly powers the Raspberry Pi and also powers the RI-0505S module. The RI-0505S is a 2-W module and can provide 400 mA of current, which is more than enough to power all the Iso-Pi circuitry. Its output is regulated, so no additional three-terminal regulator is needed. If you use an external 5-V, 1.5-A power adapter, there will be more than 1 A available for the Raspberry Pi, as the Iso-Pi’s circuitry draws less than the RI-5050S’s 400-mA output capacity (which is 80% efficient).

ATMEGA328 I/O CO-PROCESSORI chose an ATmega328 microcontroller for

the I/O co-processor because it has plenty of I/O capability in a small 28-PDIP package. I have a lot of experience programming it with a MCS Electronics BASCOM-AVR BASIC compiler, but since it is also the microcontroller used on many Arduino

P1

TxD

3.3 VSDASCL

GND

2468

101214161820222426

135791113151719212325GND

5 V5 VGND

RxDTxD

GND

GND

FutureTechnology

DevicesInternational

TTL-223R-3V3

RCA Compositevideo out

I/O Header

RxD

FIGURE 2This shows how to connect a Future Technology Devices International USB-TTL adapter to the Raspberry Pi’s I/O header.

Page 37: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Now Boarding.Now Boarding.

It’s easy to fi nd all your development boards & accessories at our dev kit headquarters. newark.com/devkits

Newark_Now Boarding_Circuit Cellar.indd 1 3/15/13 2:38 PM

Page 38: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27836FE

ATU

RES

boards, it would also be easy for Arduino fans to program their own custom firmware “sketches.” To make I/O operations as fast as possible, I chose a 115,200-bps rate for the serial link to the Raspberry Pi. I used BASCOM-AVR’s interrupt-driven buffered I/O drivers to support this high data rate. I also used an 18.432-MHz crystal, which is the highest clock rate within the ATmega328’s 20-MHz maximum clock specification that would also provide a 0.0% bps error. The Iso-Pi board contains a standard six-pin AVR ISP header to program the ATmega328. Since the ATmega328’s serial port is used for the Raspberry Pi serial link, it isn’t available for use by the Arduino serial bootloader facility (and there was no room on the PCB to add the jumpers and interface chip necessary to enable that). However, the ATmega328 is in a socket, so it can be programmed on an Arduino board and moved if an Atmel standard ISP is not available.

DIGITAL I/O PORTSI wanted to provide at least as many GPIO

port pins as those I was ignoring on the Raspberry Pi. I used a Microchip Technology 16-bit Port Expander device, which is available in both SPI (MCP23S17) and I2C versions (MCP23017). I chose the MCP23S17 SPI version since it is capable of much faster data transfer rates than the I2C version. The MCP23S17 is a versatile device capable of sourcing or sinking 20 mA, which is more than enough current for LEDs, and so forth. It has four input modes with internal pull-ups enabled or not. Polarity inversion is also available.

The MCP23S17 has a versatile interrupt sensing/reporting capability, but I did not implement this in firmware since the serial link between the ATmega328 and the Raspberry Pi does not lend itself to interrupt recognition. Configuring the device is a bit of a chore, but that is all transparently handled in the ATmega328’s firmware. I simplified the configuration options by limiting the I/O direction programming versatility (i.e., you

can’t program individual port pins as inputs/outputs, just the entire A or B port).

Both Port A and Port B outputs are wired to 10-pin ribbon cable headers. They have the extra pins assigned to ground and the isolated 5-V power source.

For high-current digital output, I included a Micrel MIC5821 serial-input latched driver. This device is also interfaced to the ATmega328 via the SPI bus, which provides a reasonably high data rate. This output-only Port C is capable of sinking up to 500 mA on each of its pins (subject to some limitations regarding duty cycle if more than four of them are simultaneously used). You can use the firmware to write any 8-bit value to the port, which enables independent pin control. Alternatively, there is a stepper motor command set, which assumes that the eight port lines are connected in four groups of two paralleled pins to drive a single unipolar stepper motor at up to 1 A per phase.

DATA CONVERSION DEVICESI wanted to include a set of high-

resolution data conversion devices on the Iso-Pi. I decided the 10-bit ADC/multiplexer contained on the ATmega328 would not be versatile nor accurate enough for many sensor applications. Instead, I used Microchip’s MCP3424 18-bit delta-sigma ADC, which is a low-cost four-channel device with differential inputs and a programmable gain amplifier (with 1, 2, 4, and 8 gains). Unlike many of the new ADCs currently available, it is available in a relatively easy-to-handle SOIC14 package.

The MCP3424 is an I2C device and has a reasonable samples per second (SPS) data conversion rate ranging from 240 SPS (at a 12-bit resolution) down to 3.75 SPS (at an 18-bit resolution). It has a 2.048-V internal voltage reference yielding a ±2.048 V/(PGA gain setting) FS differential input range. The ATmega328 firmware handles all the available sample rates, PGA gains, and channels available on the MCP3424.

Each ADC differential input is routed to a three-pin socket (+, —, and ground). Channel 2 contains footprints for four optional resistors that can be used for a bridge configuration. If such a high-resolution delta-sigma ADC is not needed, it could be left off the PCB, in which case two of the ATmega328’s 10-bit ADCs (ADC4,5) are available for use on J14. In this case, R5 and R6 (the I2C pull-up resistors) should also be omitted from the PCB.

The second data conversion function block is a Microchip MCP4822 dual 12-bit DAC, which I chose because it is low-cost for a 12-bit device and is available in an eight-pin DIP package. It is a SPI device, which enables

PHOTO 2This screenshot shows the Python program I wrote to test and exercise the Iso-Pi board.

Page 39: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 37FEATU

RES

a faster data throughput than the I2C bus (although I acknowledge that the 115,200-bps serial link is the main factor affecting data throughput).

MOTOR CONTROLIn addition to the MIC5821’s stepper motor

configuration option I mentioned earlier, I allowed for a few other motor control circuits. To control reasonably large DC motors, I incorporated a STMicroelectronics L298 dual H-bridge driver. There are several sophisticated new motor drivers on the market, but this device has been around for many years. However, I chose it because it handled a moderate amount of power (2 A per section and power supplies up to 46 V) and was available in the Multiwatt 15 package, which is easily mounted on a PCB and fits readily available heatsinks.

The L298 has two input lines per H-bridge section (four in total) to control whether the motor is activated, its direction, and its braking. These four lines are directly controlled by the ATmega328’s Port C0 through C3, enabling individual control of two motors.

There is also an Enable line per H-bridge section: each of these two lines is connected to its own 8-bit PWM signal (OC0A,B of the ATmega328’s Timer0). The Timer0 prescaler does not feature many prescale ratios that would work well in this application. With an 18.432-MHz system clock, the only choice that worked well with the motors I had on hand was CLK/64, which yielded a 562.5-Hz PWM frequency.

While I thought that CLK/8 (4,500 Hz) would be ideal, the two motors I tried (one small and another large) had little torque at the higher frequency and whined a lot. The L298 is rated for typical 25-kHz commutation speeds, so I am unsure of the limiting factor.

The L298 requires four external high-speed diodes per H-bridge to route motor counter-EMFs away from the H-bridge transistors and into the power supply/filter capacitor. I used 1N4935 diodes for this purpose.

The L298 also contains one pin per H-bridge, which is either directly grounded or may optionally have a small current-sense resistor added. This can be used to protect against motor overcurrent if the voltage across the current-sense resistor is monitored and the drive signal is adjusted accordingly. I did not implement this protection, as the board is designed more for development/educational purposes rather than as an end-use application.

Obviously the motor cannot be powered from the low-current 5-V supply that powers the rest of the I/O circuitry, so a separate

power supply connector is provided for this purpose.

The third motor control circuit implemented on the board is an R/C servomotor output. All R/C servomotors use a standard pulsed-logic control signal to control the servomotor position. This signal is pretty simple. A 1-ms wide pulse defines the most counterclockwise position of the servomotor while a 2-ms pulse defines the most clockwise position. All other positions are linearly located within those two extremes (i.e., the center position is 1.5 ms). This pulse must be constantly sent to the servomotor—at least once every 20 ms—but the exact repetition rate is not critical.

On the Iso-Pi, the ATmega328’s 16-bit Timer1 in a PWM generation mode is used to generate the R/C pulse signal. Specifically, Timer1’s clock is SYSCLK/8 (2.304 MHz). I set the period as 23,040 counts. With the specific PWM mode I used, this results in a 50-Hz pulse repetition rate (i.e., the 20-ms period specified earlier). With this configuration, a fully counterclockwise position (1-ms pulse) requires a 2,304 counter value and a fully clockwise position requires a 4,608 counter value. This results in a servomotor position resolution of a little more than 11 bits, which is greater than the servomotor’s mechanical resolution. In firmware, the user-specified position (0.0% to 100.0%) is converted to this 2,304-to-4,608 count range.

While I provide a standard three-pin connector for the servomotor output (ground, control pulse, and 5 V), it should be noted that the Iso-Pi’s 5-V power supply would not be able to supply enough current for anything more than a tiny R/C servomotor. Therefore, a separate 5-V power source would likely be needed for normal R/C servomotors.

MANUAL USER INPUT INTERFACES

While the Iso-Pi’s 16 GPIO lines can be used to read switches, drive LEDs, and so forth, I decided to include a few more manual user input options. I added a driver in the ATmega328’s firmware to enable a 4 × 4 keypad to be connected to Port A. This driver will scan the keypad and return a code for whatever key is pressed.

This routine could, of course, be done by manipulating/monitoring the MCP23S17’s GPIO pins directly by sending numerous commands from a program running on the Raspberry Pi. However, that would be quite inefficient, particularly since I only allow I/O port direction to be set on a full port basis, not a pin-by-pin basis. Therefore, this would require four pins each from Port A and Port B.

Page 40: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27838FE

ATU

RES

The second manual user interface is a rotary encoder circuit. This circuit uses one of the ATmega328’s external interrupt pins and one conventional I/O pin. The ATmega328 provides the necessary pull-up resistors needed for the encoder’s switch signals. The ATmega328’s firmware constantly monitors the rotary encoder’s position, regardless of what other functions may be occurring, triggered by Raspberry Pi commands.

There are three subcommands associated with the rotary encoder circuitry. One subcommand will zero the rotary encoder reading at the position at which it was sitting when the subcommand was sent. Another will return a signed integer representing the number of positions/direction the encoder has moved since receiving the zero subcommand. The third subcommand merely returns a 1 if the encoder has moved since its position was last read. Otherwise, it will return a 0.

Rotary encoders come in many varieties. Basically they produce a 2-bit quadrature signal, or Gray codes. Some of them produce two static signal levels on their A,B output pins when at rest, while others produce short (staggered) pulses on their output pins only during the time they are actually being moved. The latter style has fixed detents while the former style may or may not.

I wrote the Iso-Pi’s firmware routines to work with Bourns ECW1D-B24-BC0024 encoders, which are of the second type described earlier. Whether or not other encoders will work depends on if they use the same switching configuration as the stated Bourns model.

CONFIGURING THE RASPBERRY PI’S SERIAL PORT

The Raspberry Pi’s I/O header is directly connected to a UART port on the BCM2835. It operates at 3.3-V (3V3) logic levels so you definitely can’t connect it to an RS-232 port on a PC and so forth. Nor can you directly connect it to a microcontroller’s UART port, which operates at 5-V logic levels. As mentioned earlier, the Iso-Pi board contains a Si8421 isolator device to handle the logic level conversion.

However, if you wish to configure and test the Raspberry Pi’s serial communications link independent of a board (e.g., the Iso-Pi), there is one way to do so. To start, the Raspberry Pi’s serial port is identified in Linux as ttyAMA0. In the early 1970s, when I started building my own PCs, the only computer terminal inexpensive enough for a hobby computer enthusiast was a used Teletype Model 33. I remember buying one for $400, which was a lot of money at the time. Such machines were serial devices and were called tty machines.

It’s interesting to see that the tty term is still used by both Unix and Linux.

The ttyAMA0 serial port is configured early in the boot-up sequence as a secondary terminal device with the USB keyboard and video monitor as the primary user terminal. It is configured for 115,200 bps, 8 data bits, no parity. Therefore, during boot up, the same stream of commands and status messages you see going by on your monitor will also spill out of this port. This is a mixed blessing. If you connect a PC to the ttyAMA0 port (via some sort of adapter) you will immediately know the port is working and you can login at the Linux command line prompt, thus verifying communications in both directions. The downside of this is that if you plan to use ttyAMA0 to communicate with an I/O board (e.g., the Iso-Pi), you’ll have to suppress all of this boot-up data traffic. Otherwise your I/O board will receive so many “foreign” messages it will likely choke on the data.

When I got my Raspberry Pi, I happened to have some Future Technology Devices International (FTDI) TTL-232R USB-to-TTL adapter cables in the 5-V and 3V3 versions. These adapters contain a USB-to-UART chip with a USB connector for the PC end and either a five-pin header or just plain wire ends on the logic-level end. I added a three-pin header connector to the wires on the 3V3 adapter and hooked up the RxD, TxD, and ground lines so the connector could be plugged into the Raspberry Pi’s 26-pin I/O header. Figure 2 shows how to wire the Raspberry Pi I/O header to the FTDI adapter. While only the I/O pins that are actually used by the Iso-Pi board are labeled here, you can access a comprehensive article about the Raspberry Pi’s I/O capabilities at the Embedded Linux Wiki website (see the Resources section at the end of this article).

If you run a terminal program on your PC (with the correct COM port chosen and the communications parameters set as mentioned earlier), you will see the boot-up commands stream by and you can log in to the Raspberry Pi’s command line at the end of the boot up.

The next thing is to disable all of these boot-up messages being sent during boot up. Because of the boot-up process, two different files must be edited. Each one will remove a part, but not all of the datastream. First, you should enter the following at the command line prompt:

$ sudo nano /etc/inittab

(nano is a text editor program preloaded in Wheezy Linux distro.) Look toward the end of this file for a line containing:

Page 41: Circuit Cellar Sept 2013 153198-Issue 278 Sept

8-bit Microcontrollers with Integrated Configurable Logic

The Microchip name and logo, the Microchip logo, dsPIC, MPLAB and PIC are registered trademarks of Microchip Technology Incorporated in the U.S.A. and other countries. All other trademarks are the property of their registered owners. ©2013 Microchip Technology Inc. All rights reserved. 03/13

PICDEM™ Lab Development Kit (DM163045)

FAST START DEVELOPMENT TOOLS

PIC10F32X Development Board (AC103011)

PICkit™ Low Pin Count Demo Board (DM164120-1)

Free CLC Configuration Tool:www.microchip.com/CLC

Microchip’s PIC10F/LF32X and PIC12/16F/LF150X 8-bit MCUs let you add functionality, reduce size, and cut the cost and power consumption in your designs for low-cost or disposable products, with on-board Configurable Logic Cells (CLCs), Complementary Waveform Generator (CWG) and Numerically Controlled Oscillator (NCO).The Configurable Logic Cells (CLCs) give you software control of combinational and sequential logic to let you add functionality, cut your external component count and save code space. Then the Complementary Waveform Generator (CWG) helps you to improve switching efficiencies across multiple peripherals; whilst the Numerically Controlled Oscillator (NCO) provides linear frequency control and higher resolution for applications like tone generators, lighting and ballast control.

PIC10F/LF32X and PIC12/16F/LF150X MCUs combine low current consumption with an on-board 16MHz internal oscillator, ADC, temperature-indicator module, and up to four PWM peripherals. All packed into compact 6- to 20-pin packages.

Go to www.microchip.com/cip to find out more about low pin count PIC® MCUs with core independent peripherals

Page 42: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27840FE

ATU

RES

respawn /sbin/getty -L ttyAMA0 115200 vt100

and comment out this line by prefixing the line with a #. Then hit Ctrl-X to exit and save the change.

Second, use the nano editor (prefixed with sudo) to load the “/boot/cmdline.txt” file. Edit this file to remove the occur-rences of “console=ttyAMA0,115200” and “kgdboc=ttyAMA0,115,200” and save this ed-ited file.

After this is done, try rebooting the Raspberry Pi with the FTDI cable/PC still attached. There should not be a stream of boot-up commands/status messages.

The easiest method of testing the Iso-Pi, or any other board connected to the Raspberry Pi via the ttyAMA0 serial port, is to use the “minicom” terminal program. This may now come preinstalled in the latest Wheezy distro, but if not, you can install it by typing the following in a terminal window:

$ sudo apt-get install minicom

You can enter communications parameters on the command line every time you open minicom, but it’s better to just type:

$ sudo minicom -s

This will bring up a configuration menu. Set the required parameters to match the unit to which you are connecting and specify that the port you are using is ttyAMA0. In the case of the Iso-Pi board, the firmware is set up for 115,200 bps, 8 data bits, no parity.

You have to save this configuration when you’re done, which is why you need the sudo prefix. Without it, you don’t have write access to the configuration file. At this point, you should be able to communicate to the Iso-Pi or other serially connected board.

Since I was completely new to the Raspberry Pi and Linux in general, I had to choose a programming language. I have a lot of experience using Microsoft’s Visual Basic 6 on the PC. I also found a few BASIC interpreter/compilers for the Raspberry Pi (e.g., Tiny BASIC and Bywater BASIC). I have a limited knowledge of C, and a version of C comes preinstalled in Wheezy. However, it appeared that Python was the most popular programming language for the Raspberry Pi/Linux. Versions 2.7.3 and 3.2.3 are both

preinstalled in Wheezy and can be invoked by clicking on the “idle” and “idle3” icons found on the desktop.

I chose Python as my programming language for the Raspberry Pi. It is popular and features a lot of support forums. It turns out that Python 3.2.3 is not backward-compatible with Python 2.7.3. Some of the readily available Python libraries I determined would be useful to me were written for Python 2.7. Therefore, I decided to use the Python 2.7.3 included in the Wheezy distro.

To access the ttyAMA0 serial port from Python 2.7.3, you need a library called pyserial. This library may now be part of the newest Wheezy distro, but I installed it on my Raspberry Pi by typing the following into the terminal window:

$ sudo apt-get install python-serial

After this library is installed, you include it in your Python program by entering the following line at the beginning of your program:

import serial

A full description of the pyserial library is available at the PySerial website. (Refer to the Resources section at the end of this article.)

To open the ttyAMA0 serial port with the communications parameters mentioned earlier, use the following lines:

COMM= serial.Serial(‘/dev/ttyAMA0’,115200, timeout=5) COMM.open

(You can set the error timeout to a different amount of seconds other than 5.) To send a string out from the Raspberry Pi’s ttyAMA0 port, use:

s=”text to send”s=s + ‘\r’COMM.write(s)

Notice that I am appending a <CR> terminator at the end of the string, by adding the \r <CR> designator to the end of the string before transmitting it. In this case, the Iso-Pi’s ATmega328 microcontroller is running a BASCOM-AVR program and its serial input routines expect a <CR> as a line terminator. However, the <LF> character is

ABOUT THE AUTHORBrian Millier ([email protected]) runs Computer Interface Consultants. He was an instrumentation engineer in the Department of Chemistry at Dalhousie University (Halifax, NS, Canada) for 29 years.

Page 43: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 41FEATU

RES

the standard Linux line terminator. Therefore, when I return data to the Raspberry Pi, I append both an <LF> character and a <CR> character as line termination. This satisfies the Linux <LF> termination standard. It also means that if you are using “minicom” to communicate with the Iso-Pi, you will get a display that contains one command string per line, left justified. Otherwise you will either get command strings overwriting each other or “snaking” across the terminal window.

I decided to write a Python program to test the Iso-Pi board. What I wanted was a GUI for this program that is similar to the GUIs I could easily implement using Visual Basic 6 on a PC.

I discovered the Tk/tcl graphics library is a cross-platform library that has been in existence for a while. I liked its functionality and decided to use the Tkinter library, which is derived from Tk/tcl. While I used the sudo apt-get method to install it on my first Raspberry Pi, on the last Raspberry Pi I loaded, the Tkinter library was already preinstalled on the newest Wheezy distro I downloaded. I learned how to use this library with the excellent Tkinter introduction by Fredrik Lundh of Secret Labs (see the Resources section at the end of this article).

Photo 2 shows a screenshot of my Iso-Pi test program. It contains drop-down menus, push buttons, check boxes, sliders, and a status line, just like my Visual Basic 6 programs do. The Python code for this program, as well as the ATmega328 firmware files, is available on Circuit Cellar’s FTP site. The site also contains a PDF document fully describing the command syntax used for the various peripheral devices on the Iso-Pi board, as that is too much information to include in this article. The ExpressPCB file for the PCB is also available at the FTP site. Incidentally, I used a free command-line screen capturing program called scrot (SCReen shOT) to generate the Raspberry Pi screenshots.

PLENTY OF SUPPORT FOR RASPBERRY PI

I hope you enjoyed this two-part introduction to the Raspberry Pi and my isolated I/O board design. I must admit I “cheated” a bit by letting an Atmel AVR microcontroller (which I have years of experience using) do all of the “heavy lifting” with regard to the firmware drivers that were necessary for the numerous I/O devices used on the Iso-Pi. However, I did manage to learn Linux and Python well enough to write a pretty sophisticated “exercise” program for the Iso-Pi board, which was completely new ground for me.

It was surprising and gratifying to see the

wealth of user-generated support that exists for the Raspberry Pi, a board that was less than a year old at the time I wrote this article series. I’ve been familiar and satisfied with the AVR microcontroller/BASCOM Basic Compiler combination, which I’ve used for 10 years now. But the amount of information that is readily available for the Raspberry Pi/Linux is quite outstanding.

PROJECT FILES

circuitcellar.com/ccmaterials

RESOURCES

AdaFruit Industries, “Adding a Real-Time Clock to Raspberry Pi,” 2013.

Embedded Linux Wiki, “Rpi Low-Level Periph-erals,” 2012.

PySerial, http://pyserial.sourceforge.net

Python Software Foundation, Python Program-ming Language, www.python.org

G. Richard, “How to Take Screenshots with Scrot,” Free Software Magazine, 2007.

Roving Networks, Inc. www.rovingnetworks. com

Secret Labs, AB, Tkinter Introduction.

SOURCES

ATmega328 and AVR MicrocontrollersAtmel Corp. | www.atmel.com

ECW1D-B24-BC0024 EncodersBourns, Inc. | www.bourns.com

BCM2835 Applications processorBroadcom Corp. | www.broadcom.com

TTL-232R USB-to-TTL adapter cablesFuture Technology Devices International, Ltd. | www.ftdichip.com

DS1307 Real-time clock circuitMaxim Integrated | www.maximintegrated.com

BASCOM-AVR BASIC compilerMCS Electronics | www. mcselec.com

MIC5821 Serial-input latched driversMicrel, Inc. | www.micrel.com

MCP23017/MCP23S17 I/O Expander and MCP3424 ADCMicrochip Technology, Inc. | www.microchip.com

Visual Basic 6 programming languageMicrosoft Corp. | www.micro soft.com

PCF8564A Real-time clock circuitNXP Semiconductors | www.nxp.com

RI-0505S Isolated DC-DC converterRECOM Power, Inc. | www.recom-power.com

Si8421 and Si8602 IsolatorsSilicon Laboratories, Inc. | www.silabs.com

L298 Dual H-bridge driverSTMicroelectronics | www.st.com

Page 44: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27842FE

ATU

RES

T his two-part article discusses an architecture that enables a robot to “grow”

from a naive individual with no knowledge of itself (i.e., no notion of what its sensors are reporting or what its outputs actually do) to one that can operate in an environment. This architecture will consist of an evolving neural network (ENN), a short-term memory (STM), and simple instincts and reflexes.

Despite a minimal set of instincts, which provide penalties and rewards for certain actions (e.g., crashing into a wall), the robots described in this article sometimes develop complicated and unexpected behaviors. Such behaviors range from following walls (despite the robots’ binary proximity sensors) to games of “follow the leader.” (The environment does not directly reward either behavior, yet the robots still develop these strategies.) The work presented here is based on a paper published in the proceedings of the 13th International Artificial Life Conference.[1]

This article explores basic artificial neural network (ANN) concepts and outlines the ENN I’m using in this project. This is a

neural network that, over time, learns not only by adjusting synaptic weights but also by growing new neurons and new connections (generally resulting in a recurrent neural network). Finally, I’ll discuss the STM system and how it is used to evaluate a network’s fitness.

In Part 2, I’ll examine the reflex and instinct system, which feeds reward information to an ENN and the “decision path” system, which rewards or penalizes chains of actions. Finally, I’ll discuss experiments conducted to demonstrate this architecture in a simulated environment. In particular, I’ll describe some interesting behaviors that robots have developed in trial runs.

DESIGN OVERVIEW AND GOALBefore going into the “nitty-gritty” of

how to implement everything, let’s take a bird’s-eye view of the project. The goal is to enable a robot to learn on its own without any required human intervention (though a human “teacher” is permitted to interact with the robot). An ENN is used to accomplish this. This network will be capable of growing and learning in real time as the robot operates.

Of course, a robot needs motivation to learn. The robot is equipped with a minimal set of instincts and reflexes. When triggered, an instinct will “guide” the ENN’s learning. A reflex will help the robot out of potentially dangerous states. For example, if a robot crashes, an instinct will trigger―telling the ENN that a mistake was made somewhere. Following this, a “repulse” reflex will trigger the robot to back up while turning 180°.

ARTIFICIAL NEURAL NETWORKSI’ll begin with a brief introduction to ANNs.

Obviously, a single article cannot describe

Experiments in Developmental Robotics (Part 1)Artificial and Evolving Neural NetworksThis article provides an introduction to artificial neural networks and describes an evolving neural network used in a robot development project. It also explains how a short-term memory system evaluates a network’s condition.

By Walter O. Krawec (USA)

FIGURE 1This graph shows one of the most common activation functions (and the one used in my project).

Page 45: Circuit Cellar Sept 2013 153198-Issue 278 Sept

THE GLOBAL STAGE FOR INNOVATION

Page 46: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27844FE

ATU

RES

such a large topic in detail (readers should refer to the many online sources). But I’ll discuss the rudiments, which include basic neuron construction and feed-forward neural networks (readers familiar with these topics may prefer to skip this section).

An ANN’s first and most basic element is the neuron (sometimes referred to as a “node”). This device takes in a series of inputs (numerical inputs, which I’ll denote x1, x2, ... , xn) and outputs a single value (I’ll call it “y”). For every neuron input a “weight” (I’ll call them w1, w2, … ,wn) exists with values that usually aren’t too far from zero (“too far” being a very loose description). The final output value “y” of

a single neuron then is provided by:

y = a w xi ii = 1

n∑( ) [1]

where “a” is the activation function used by the network. There are many choices for this function. For example, it can be linear (i.e., a(x) = cx for some non-zero constant “c”). However, one of the most common activation functions (and the one I’ll be using in this project) is of the form:

a x = 1 + e

( ) −1 z [2]

If you were to graph this equation, it would look like Figure 1. You will notice that its output is between 0 and 1. Also notice that as “x” gets large, the change in “a(x)” is minuscule. This is why the weights of each input (wi) are typically not too far from zero.

So a neuron is pretty easy to understand. Given a set of inputs (either from the world or from another neuron), it simply takes a weighted sum and plugs that sum into the activation function. The result is the output, which can be fed into another neuron or into the world.

Now that I have that out of the way, let’s build a network. An ANN consists of several of these neurons (each neuron having its own independent set of weights) connected to each other in some fashion. How they’re connected to each other (often called the “network topology”) is very important.

Classically, a feed-forward neural network is the first type of neural network typically considered. In this architecture, a network consists of an input layer, an output layer, and at least one hidden layer. Each world input into the network (e.g., a sensor value on a robot) feeds into one neuron in the input layer. Each neuron in the input layer is connected to every neuron in the first hidden layer. Every neuron in the first hidden layer is connected to every neuron in the second hidden layer, and so on. Finally, every neuron in the last hidden layer is connected to each neuron in the output layer. There are as many output layer neurons as there are network outputs (e.g., there may be two outputs―one for each drive motor on your robot). Figure 2 shows a sample feed-forward network.

This architecture is straightforward. To operate such a network, you first feed the world inputs into the input layer. Each of these neurons is run using Equation 1, and their output is fed into the next layer. Each layer’s neurons are then run in order until eventually you get an output from the output-layer neurons and the process is done.

FIGURE 2This simple feed-forward neural network has two inputs, one output, and three hidden neurons.

Page 47: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 45FEATU

RES

I have to talk a little about these weights. If the network topology never changes, the network’s output only depends on each neuron’s weights. Changing even a single neuron’s weight can drastically change the entire network’s output. When a network is first constructed, you typically begin by assigning random weights to every synapse (hence, the output of the network is completely random). Using a learning algorithm, you can then slowly, over time, shift the weights to produce the desired output.

A common learning algorithm used for this type of network is the “backpropagation” algorithm (i.e., backward propagation of errors). This algorithm takes in a set of desired responses to certain inputs and slowly adjusts the weights (a process called “training” the network) to minimize the network’s total error (or deviation from the given responses). The great thing about this setup is that, after training, it enables the ANN to “guess” at the correct answer if it is provided with a new set of inputs that aren’t available in the training set.

The unfortunate thing about this learning technique is that it requires the user to know what it wants from the network. Also, the training must be completed before the network can be applied (which can take a long time, depending on the size of the network and training set). This form of learning is known as supervised learning. Many other forms of learning algorithms can be used. Readers can find information about them online.

EVOLVING NEURAL NETWORKUnlike a fixed topology network, such as

the one described in the previous section (i.e., a network where the synaptic links do not change but only the weights vary), this article involves work with an ENN. Such a network not only adjusts synaptic weights to facilitate learning but also is able to grow new neurons and new synapses. Additionally, the architecture I’ll be using enables the network to grow and learn in real time (as the robot is in operation).

The basic process is as follows. Start with one neuron (where each neuron uses Equation 1 to calculate its output) for every world input (e.g., sensor) and one neuron for every desired output (e.g., motor). Connect every input neuron to every output neuron and assign a random weight to every connection (so far, this is the same as a feed-forward network without the hidden layers).

For now, assume there is some way to “evaluate” a network. That is, assume a “fitness function” exists that, given an ENN as input, outputs a single number. The larger this number, the more “fit” (i.e., the

FIGURE 3These simulation images show a network evolving, starting with three inputs and two outputs and later adding and removing neurons and synapses. Black squares are input neurons, red squares are output neurons, and blue squares are hidden neurons. In this simulation, a robot was running, so darker lines represent a higher signal flowing through particular synapses while lighter lines represent low signals. a—The algorithm starts with three fully connected input neurons and two output neurons. b—Sometime later, a new neuron was randomly added and connected. c—Two synapses were removed. d―Several iterations later, more neurons were added. e―More iterations later, neurons and synapses were added. f—Here is an evolved network after 30 min of run time (several hundred evolution iterations).

b)

a)

d)

c)

f)

e)

Page 48: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27846FE

ATU

RES

more desirable) the network. This article’s Short-Term Memory section will explain how to construct this fitness function. For now, simply assume it exists.

The goal is to maximize the fitness function, which is accomplished by “evolving” the ENN. When called, this evolve function will take the current network in question and construct “N” new networks. (The larger the “N,” the better, but also the slower the function. In Part 2, I’ll show that it’s possible to run the evolution in a separate thread.)

For every new network created, one of five things will randomly happen: A new node will be created and randomly attached to the existing network (2% probability); an existing node will be destroyed, but not

an input or output node (2% probability); a new connection (synapse) will be made between two previously unconnected nodes, possibly a connection from an output neuron to an “inner” neuron (2% probability); a connection (synapse) between two nodes will be destroyed (2% probability); or an existing synaptic weight (or several if the network is large) will be changed slightly, either adding or subtracting a small amount (92% probability).

After creating these “N” new networks, a small subset is chosen (typically the best members along with some random ones) and the process begins a second time (with the recursion repeating a total of “K” times and each recursion level taking a smaller-sized subset than the last).

Finally, a single network, which has the largest fitness value, is chosen and this network is returned. The former network is

forgotten and the new one takes its place (this new network is the old network with at most “K” changes).

Notice that synapses can form between any two neurons (even connecting output to input neurons or connecting neurons to themselves). This creates a “recurrent neural network,” which is important because it enables a robot’s past actions to influence its future actions. This capacity develops some of the more interesting behaviors described in Part 2 of this article series.

SHORT-TERM MEMORYIn the previous section, I described how

an ENN evolves by assuming the existence of a “fitness function.” Here I explain how this function is constructed. Every robot is equipped with a STM, which holds a limited amount of “possibly useful” information. The information is possibly useful since it may be (and is quite likely) the case that some incorrect information is added to the STM. Because of this, the memory mechanism must be able to “guide” an ENN’s evolution but not maintain its contents indefinitely. Two methods are proposed for this project. I’ll briefly discuss both.

The first mechanism is called U-Learning (i.e., utility learning). This method stores a mapping of state/action pairs (in this case, a “state” is the actual input to an ENN and an “action” is the output of the ENN) to rewards or penalties (the “utility” value). Storing such reward information in a matrix is similar to Q-Learning.[2] However, U-Learning is different in that its goal is only to store these utility values in the short term and these values may be incorrect (whereas Q-Learning’s goal is to construct a matrix that fully and accurately describes every reward).

If U-Learning is used, a robot begins with a zero matrix (i.e., all elements are 0) of size 2m rows by 2n columns, where “m” is the number of inputs to the ENN and “n” is the number of outputs. Note that for this mechanism, we assume that all I/O lines are binary. This enables you to convert between an arbitrary input vector consisting of 1s and 0s into a number between 0 and 2m − 1 (likewise for outputs). That is to say, an input state of <0, 1, 1> will be indexed to row 3 of the U matrix; <1, 0, 1> is row 5.

If U’s elements are of the form u(i, j), where “i” is the row number (or state) and “j” is the column number (or action), then u(i, j) represents the reward/penalty for applying action “j” given state “i.”

While a robot is operating (e.g., exploring its environment), it should receive reward/penalty information (Part 2 of this article series will describe how this is accomplished).

PROJECT FILES

circuitcellar.com/ccmaterials

REFERENCES

[1] W. O. Krawec, “On the Emergent Behaviors of a

Robot Controlled by a Real-Time Evolving Neu-ral Network,” Proceedings of Artificial Life, 13th International Conference on the Simulation and Synthesis of Living Systems, 2012.

[2] C. Watkins and P. Dayan, “Q-Learning,” Machine Learning, 1992.

RESOURCE

Walter O. Krawec, www.walterkrawec.org.

To see videos of Krawec’s ENN experiments, go to bit.ly/ccmaterials

Page 49: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 47FEATU

RES

Say a robot received a reward “r” (just a number, a negative number implies a penalty) for performing action A at state S. Then you simply take u(S, A) += r. Furthermore, since this is a “short-term” memory, every so often U is multiplied by a scalar less than 1. This multiplication decreases the reward/penalty value. If a matrix entry becomes small enough (for example, less than 0.001), it is completely disregarded (setting the entry back to 0). From this U matrix, it is fairly straightforward to compute a fitness value for an ENN. You can see the algorithm in the source file ULearn.cpp in the function fitness(), which is available along with the other source code on Circuit Cellar’s FTP site.

The second mechanism is called EL-Learning (i.e., evolution list learning). For this method, you begin with an empty list. Whenever reward information is received, you simply append the I/O values and reward to the end of the list. Every so often, old elements of this list are discarded. From this list, you can easily compute an ENN’s fitness value, which is just the usual sum of the errors squared (see the EL.cpp source file on Circuit Cellar’s FTP site).

Each method has its own advantages. U-Learning seems to be the most stable (i.e., a robot using U-Learning typically learns faster and more reliably, and remembers longer). However, EL-Learning requires less memory to store and enables analog I/O (U-Learning by itself requires binary I/O, although there are ways around that). EL-Learning also has the advantage of an ENN learning the patterns of data received from STM.

So, for example, if an EL-Learning list has three elements―each with a different I/O mapping―an ENN will typically learn to output the correct values in that order. If a different order is presented to the network, a different response is generated. This causes a robot to sometimes learn “plans” or to expect certain events in a certain order and to produce different actions if it experiences events in a different order.

NEXT TIMEIn Part 2, I’ll consider how data is added

to STM. In particular, I’ll describe how each robot is equipped with minimalistic “instincts” and “reflexes,” which are used by the ENN to

guide its evolution. I’ll also cover “decision paths,” which reward or penalize chains of actions/decisions that a robot makes while in operation. Finally, I’ll discuss the experiments I ran demonstrating this architecture in a simulated environment. I’ll also share some of the interesting behaviors I’ve observed (for example, close wall following despite binary proximity sensors and no direct reward for doing so, only a penalty for physically touching a wall). In the meantime, I encourage you to take a look at my website, www.walterkrawec.org, where you can find the software used and view videos of some of my experiments.

ABOUT THE AUTHORWalter O. Krawec ([email protected]) is a PhD student studying Computer Science at the Ste-vens Institute of Technology in Hoboken, NJ, where he also works as a research assistant. He earned his MA in Mathematics from the University at Albany-SUNY and has published several articles and pa-pers in a variety of subjects including robotics, artificial intelligence, game theory, and graph theory. He has been a member of the Connecticut Robotics Society and has been building robots since 1999.

Page 50: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27848CO

LUM

NS

Battery usage has increased due to the proliferation of mobile and cordless

devices. This article describes battery types generally available in retail stores. I’ll discuss their features, operation, and usages. While many exotic batteries and custom packages are available, this article focuses on standard batteries, which are the type you are most likely to encounter.

BATTERIES VS. CELLSTo start with, I’d like to clarify the

terminology. Although we tend to use the words “battery” and “cell” interchangeably, there is a difference. Batteries comprise cells (e.g., the well-known 9-V battery contains six 1.5-V cells, while the omnipresent AA “battery” and many others are just single cells). I will use the common terminology, even though at times it may be technically incorrect.

Batteries store chemical energy. When activated, the chemical process occurring internally converts the chemical energy into

electrical energy. Alessandro Volta, an Italian physicist, is credited with inventing the “voltaic pile” in the early 19th century. However, archaeological discoveries suggest that some form of an electrical battery was known in ancient Babylon. National Carbon Company, known today as Eveready, began marketing a precursor of the ubiquitous carbon-zinc battery in 1896. Figure 1 shows a simplified cross-section of a typical carbon-zinc cell. Most batteries today comprise cells structurally similar to the one shown in Figure 1, but the chemical content may be different.

COMMON BATTERY PACKAGESAccording to Wikipedia, the most common

battery packages available today include AA, AAA, C, D, 9-V pack, and different types of “button cells” (see Photo 1). There is also a plethora of custom-made battery packs for power tools, cordless telephones, and so forth. No matter what kind of packaging, the battery principles for the given type remain the same.

There are two battery categories: primary (i.e., single use) and rechargeable. Carbon-zinc is the oldest—and at one point the most common—primary battery. They are inexpensive and available in standard packages. Consequently, carbon-zinc batteries are often included by original equipment manufacturers (OEMs) with devices such as TV remote controls, portable radios, and so forth. Although they have been improved over the years, some significant shortcomings remain, so I avoid using them.

CARBON-ZINC BATTERIESCompared with alkaline batteries, carbon-

zinc batteries have the same nominal 1.5 V per cell, but their capacity is significantly

FIGURE 1A carbon-zinc cell cross-section is shown.

Positive terminal

Carbon anode

Electrolyte

Cathode mix

Zinc cannegativeterminal

+

Battery Basics (Part 1)Battery TypesThis article provides an introduction to common battery types and describes their characteristics, performance, and benefits. The difference between batteries and cells is also explained.

By George Novacek (Canada)

THE CONSUMMATE ENGINEER

Page 51: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 49CO

LUM

NS

lower. Their shelf life is also shorter, as is the maximum current they can deliver, due to their relatively high internal resistance. Carbon-zinc batteries’ shelf life has been improved, allegedly to three or perhaps five years, but I have seen the batteries leaking electrolyte after less than a year, causing damaging corrosion to the equipment in which they are contained. They have poor low-temperature performance.

ALKALINE BATTERIESAlkaline batteries replaced carbon-zinc

batteries, but without their shortcomings. Alkaline batteries’ nominal cell voltage is also 1.5 V. They are available in AA, AAA, C, D, and 9-V packages and as button cells, all with a minimum 10-year shelf life. Alkaline batteries are not recommended for low-temperature usage. But I haven’t had any problems using them in temperature, humidity, and barometric pressure sensors while they were exposed to temperatures ranging from –40°F (–40°C) to more than 110°F (43.3°C).

Alkaline batteries are slightly more expensive than carbon-zinc batteries, but considering their longer shelf life and greater capacity, they are likely less expensive in the long run. Alkaline batteries can also be

PHOTO 1These are some common battery packages. (Photo courtesy of Wikipedia)

FIGURE 2This graph compares battery power and energy density. (Image courtesy of ExtremeTech)

Page 52: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27850CO

LUM

NS

rechargeable. I will return to that later when discussing rechargeable batteries.

OTHER COMMON BATTERY TYPESLithium (Li) batteries also come in standard

packages. They weigh less than their alkaline counterparts, feature a 10-to-15-year shelf life, and work well in low temperatures. Since they have a nominal 3-V cell voltage, you must be careful not to substitute them for 1.5-V alkaline or carbon-zinc cells. Li batteries have low internal resistance. Therefore, if they are used improperly, they can cause a lot of damage to the equipment. Unlike lithium-ion (Li-ion), Li batteries are not rechargeable.

Mercury (i.e., mercuric oxide batteries) were produced as button cells and used mainly in watches, hearing aids, and similar applications. They were discontinued in the early 1990s and banned in many countries due to their mercury content.

Silver oxide button cells are nominally 1.55 V per cell and are often mutually interchangeable with alkaline button cells. They have a 50% to 100% greater capacity and flatter voltage discharge curve than the corresponding alkaline cells, but they are more expensive.

RECHARGEABLE BATTERIESLead-acid batteries were the first

commercially available rechargeable batteries. Each cell is nominally 2 V. The battery was invented by Gaston Planté in 1859 and continues to be the most commonly used power source in automobiles, cordless equipment, and back-up storage systems. Originally, a cell contained lead (Pb) plates submerged in sulphuric acid (H2SO4). During the 1970s, a sealed battery was developed where the acid was in a gel

form. The lead-acid battery prevails when cost, capacity, availability, and reliable performance are more important than size and weight.

Nickel-cadmium (NiCad) batteries, which have a higher power density than lead-acid batteries and are smaller and lighter, have been popular for hand-held devices. They have also been available in standard AA, C, D, and many custom packages. They have a 1.2-V nominal cell voltage. This fact is often overlooked by those replacing alkaline batteries in their devices with “better,” rechargeable NiCads to save money. Unfortunately, if those devices are sensitive to the battery voltage (e.g., smoke alarms), they may indicate a “discharged” battery within a few days. Ed Nisley presented an exhaustive study of NiCad batteries in “Battery Capacity: Discharge” (Circuit Cellar 199, 2007) and “Battery Capacity: Charge” (Circuit Cellar 201, 2007).

NiCads can be recharged about 1,500 times, but they exhibit a fairly high self discharge of about 20% to 40% per month. In addition, their “memory” effect, which is caused by formation of Cadmium crystals, makes them lose their capacity. High temperature also contributes to their formation. The crystals’ formation can be minimized by recharging the battery only when it has been fully discharged.

The battery can be restored to its full capacity by fully discharging it following with a full charge. However, while 1 V does not represent full discharge, discharging a NiCad cell below 1 V is said to cause irreparable damage. While tricks to restore full capacity are available on the Internet, they seem controversial.

NiCad batteries are being replaced by nickel-metal hydride (NiMH) batteries. These batteries are also available in AA, AAA, C, D, and custom packages. Their nominal cell voltage is also 1.2 V, but they do not suffer from the memory effect. Their power density for the same volume is more than double that of the NiCad, but can be recharged only 150 to 500 times. Their self discharge, which is about 1% per day, is quite high.

NiMH batteries can also be purchased as precharged NiMH. Their advantage is that, unlike other rechargeable batteries, they can be used right out of the package. The price you pay for this convenience is their lower capacity, which is about 80% of the standard NiMH, but the self discharge is very low, only about 3% to 4% per month.

RECHARGING ALKALINE BATTERIES

You can also purchase rechargeable alkaline batteries. Since they do not suffer from self discharge or the memory effect, there were great expectations preceding their introduction. Unfortunately, they seem

circuitcellar.com/ccmaterials

RESOURCESS. Anthony, “New Lithium-Ion Battery Design That’s 2,000 Times More Powerful, Re-charges 1,000 Times Faster,” ExtremeTech, 2013.

General Electric Co. (GE), Nickel-Cadmium Battery:

Application Engineering Handbook, Battery Business Department, GE, 2nd edition, 1975.

E. Nisley, “Battery Capacity: Discharge,” Circuit Cellar 199, 2007.

———, “Battery Capacity: Charge,” Circuit Cellar 201, 2007.

REI, “Quick Reference Guide: Single-Use Batteries.”

———, “Quick Reference Guide: Rechargeable Batteries.”

Wikipedia, “Battery (Electricity).”

———, “Zinc-carbon Battery.”

Page 53: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 51CO

LUM

NS

to suffer a severe shortcoming, namely few recharge cycles compared to their cost.

There are confusing claims regarding alkaline batteries’ recharge cycles. Some state that the rechargeable alkalines can be recharged no more than 10 to 30 times. Others claim that they can be recharged hundreds of times, provided they are never fully discharged. And some claim that even the nonrechargeable alkaline batteries can be successfully recharged.

The recharging process seems problematic. I have been unable to find a description of a proper recharging protocol. One manufacturer prints on its AA cell that it should be recharged for 16 h at 200 mA. Another manufacturer provides only a part number of its proprietary charger (which is expensive and hard to find). My experience with the rechargeable alkaline batteries has been disappointing, so I use NiMHs.

Lithium-ion (Li-ion and Li-ion polymer) batteries’ cell voltage is nominally 3.6 V, while their self discharge is low, less than 2% per month. Today, Li-ion batteries have the highest energy density of commercially available batteries, while new developments keep increasing their power density to compete with other technologies. For this reason, they are useful wherever a lot of power in a small space at a low weight is required (e.g., mobile computers and aerospace applications). But the high power density raises potential safety issues. The public witnessed something like this not long ago onboard a Boeing Dreamliner aircraft, where a battery’s internal defect caused a fire.

Figure 2 shows characteristics of rechargeable power sources in terms of their power and energy density. Recharging batteries is a critical, often underestimated task. I will address this topic in Part 2.

ABOUT THE AUTHORGeorge Novacek ([email protected]) is a professional engineer with a degree in Cybernetics and Closed-Loop Control. Now retired, he was most recently president of a multinational manufac-turer for embedded control systems for aerospace applications. George wrote 26 feature articles for Circuit Cellar between 1999 and 2004.

Page 54: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Bo

oks

Prices and item descriptions subject to change. E. & O.E

The world of electronics at your fi ngertips!

Elektor.STOREBOARDS, BOOKS, DVDs AND MORE AT WWW.ELEKTOR.COM/STORE

Elektor’s RFID BIBLE is now available

RFID – MIFARE and Contactless Cards in ApplicationMIFARE is the most widely used RFID technology, and this book provides a practical and compre-

hensive introduction to it. Among other things, the initial chapters cover physical fundamentals,

relevant standards, RFID antenna design, security considerations and cryptography. The complete

design of a reader’s hardware and software is described in detail. The specially developed PC pro-

gram, “Smart Card Magic.NET”, is a simple development environment that supports sending

commands to a card at the click of a mouse, as well as the ability to create C# scripts. Alternative-

ly, one may follow all of the examples using Visual Studio 2010 Express Edition. Finally, the major

smart card reader API standards are introduced. The focus is on programming contactless smart-

cards using standard PC/SC readers using C/C++, Java and C#.

484 pages • ISBN 978-1-907920-14-1 • $72.50

NEW!

This book and more

are available at

www.elektor.com/store Open Source Hard- and Software

Open Source Electronics on LinuxIf you have ever wanted to take advantage of the

expanding fi eld of open source software for elec-

tronics and everyday applications, this book is

for you. Using the Linux OS, Warwick A. Smith

guides you through the world of open source

hardware and software, teaching readers to use

EDA tools and software that is readily available

online, free to download. The hardware projects

inside can be built using easily obtainable parts,

in the comfort of your own home, on single sided

PCBs, or professionally manufactured with out-

put fi les generated by you.

272 pages • ISBN 978-1-907920-19-6 • $47.60

Learning to fl y with Eagle

Eagle V6 Getting Started Guide

The book is intended for anyone who wants an

introduction to the capabilities of the CadSoft’s

Eagle PCB design software package. The reader

may be a novice at PCB design or a professional

wanting to learn about Eagle , with the inten-

tion of migrating from another CAD package.

After reading this book while practicing some

of the examples, and completing the projects,

you should feel confi dent about taking on more

challenging endeavors. This book is supplied

with a free copy of Eagle on CD-ROM for

MS Windows, Linux and Mac.

208 pages • ISBN 978-1-907920-20-2 • $47.60

aglel

Bestseller!

ELEK US1308 CCshop.indd 80 20-06-13 09:47

Page 55: Circuit Cellar Sept 2013 153198-Issue 278 Sept

Bo

oks

Kits &

Mo

du

les

Elektor US111 Founders Plaza, Suite 300East Hartford, CT 06108USAPhone: 860.289.0800Fax: 860.461.0450E-mail: [email protected]

Elektor is morethan just your favorite electronics magazine.

It’s your one-stop shop for Elektor Books,

CDs, DVDs,Kits & Modules

and much more!

www.elektor.com/store

TAPIR Sniffs it OutAttention boy scouts, professionals and

grandfathers! This ultrasensitive wide-

band E-smog detector offers you two extra

senses to track down noise that’s normally

inaudible. TAPIR - short for Totally Archaic

but Practical Interceptor of Radiation - also

makes a nice project to build: the kit

comprises everything you need - even the

enclosure, ingeniously consisting of the

PCB proper. Using the TAPIR is dead easy.

Connect the headphones and an antenna

and switch it on. Move it around any elec-

trical device and you’ll hear different noises

with each device, depending on the type

and frequency of the emitted fi eld.

Kit of parts

Art.# 120354-71 • $21.50

Theory and Practice

Practical

Digital Signal Processing using Microcontrollers

This text on DSP refl ects the growing impor-

tance of discrete time signals and their use in

everyday microcontroller based systems. The

author presents the basic theory of DSP with

minimum mathematical treatment and teaches

the reader how to design and implement DSP

algorithms using popular PIC microcontrollers.

The author’s approach is practical and the book

is backed with many worked examples and test-

ed and working microcontroller programs

428 pages • ISBN 978-1-907920-21-9 • $72.50

Elektor Linux Board ExtensionThis extension board was developed to further

propel our Embedded Linux series of articles

and the matching GNUblin board. It has a dis-

play, buttons, a real time clock and 16 GPIOs.

Linux devotees, switch on your solder irons.

The Linux extension board includes everything

needed to provide the user interface for a wide

variety of projects!

Module, SMD-populated and tested board,

incl. LCD1, X1, K1-K4, BZ1, BT1 for home assembly

Art.# 120596-91 • $50.20

10 captivating lessons

PIC Microcontroller ProgrammingUsing the lessons in this book you learn how to

program a microcontroller. You’ll be using JAL, a

free but extremely powerful programming lan-

guage for PIC microcontrollers. Starting out from

scratch virtually, you slowly build up the knowl-

edge. Assuming you have absorbed all lessons

— meaning you have actually completed all the

exercises — you should be confi dent to write PIC

microcontroller programs, as well as read and

understand programs written by other people.

284 pages • ISBN 978-1-907920-17-2 • $47.60

0 i i l

Elekkktttttoooorrr LLLiinux Board

TAPIR

Art # 120596-91 • $50 20

TAPIR

Art.# 120596-91 • $50.20

Embedded Linux Made EasyToday Linux can be found running on all sorts

of devices, even coffee machines. Many elec-

tronics enthusiasts will be keen to use Linux as

the basis of a new microcontroller project, but

the apparent comple xity of the operating

system and the high price of development

boards has been a hurdle. Here Elektor solves

both these problems, with a beginners’ course

accom pa nied by a compact and inexpensive

populated and tested circuit board. This board

includes everything necessary for a modern

embedded project: a USB inter face, an SD

card connection and various other expansion

options. It is also easy to hook the board up to

an Ethernet network.

Populated and tested Elektor Linux Board

Art.# 120026-91 • $93.30

New!

ELEK US1308 CCshop.indd 81 20-06-13 09:53

Page 56: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27854CO

LUM

NS

LEDs have an essentially unlimited lifetime, often quoted as 50,000 or 100,000 h or

11 years of continuous illumination. That lifetime applies to a large number of LEDs

operated at normal temperatures, not any given unit, and the usual advertisements don’t mention that the usual end-of-life occurs when the brightness decreases to 70% of its initial value. I wondered how the ordinary 5-mm LEDs I planned to use would survive in a low-duty-cycle pulsed application, so I ran a dozen LEDs through a simplified life test.

I also built a photodiode amplifier to measure LED output as a function of current, so that I could determine how much the LEDs faded with use. It also shows how LED efficiency drops off with increasing current, which puts an upper bound on how much light you can get from a simple LED driver.

For a change, neither of the testers involves any software: all the programming happens with solder and the results are pure analog signals!

PULSED POWERBecause the human eye responds to

the average power of a light source, pulse width modulation provides a simple way to control LED brightness using digital signals and high-efficiency MOSFET switches. If you increase the peak current and reduce the duty cycle in proportion, the average light output should remain approximately the same, but because LED efficiency decreases at high current, PWM can’t perform miracles with more current.

The simple tester in Photo 1 drives a dozen LEDs at 100 mA peak current and a 20% duty cycle, with the average current equal to their nominal 20 mA. The average power dissipation increases, however, because LED forward voltage increases with increasing current. The results in Photo 2, taken with the Arduino-based LED Curve Tracer described in my July column, show that the forward

PHOTO 2Plotting LED forward voltage against current for a selection of 10 high-brightness red LEDs from a lot of 100 shows a 4% variation at 100 mA. I selected LEDs using this data to match the forward drop for three strings of three LEDs in series.

PHOTO 1Although this hand-wired circuit board doesn’t look fancy, it sufficed to exercise a dozen LEDs on a corner of my workbench for five months without any attention. The three amber LEDs in the bottom row don’t look very different from the nine red LEDs in real life, either.

Pulsed LED CharacterizationEd continues his exploration of commodity LED characteristics with a stress tester and an optical output detector. After surviving a simulated year of use, the LEDs reveal some interesting data.

By Ed Nisley (USA)

ABOVE THE GROUND PLANE

Page 57: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 55CO

LUM

NS

voltage increases from 1.98 to 2.14 V, so the average power goes up by about 8%.

Pop Quiz: Why isn’t that 17%?The schematic in Figure 1 is a classic

555 timer circuit with a diode that reduces the pulse duty cycle below 50%. The two trim pots set the period and pulse width, which I adjusted for 10 ms and 20% duty cycle, respectively. Although the 100-Hz PWM frequency lies above the 60 Hz human flicker fusion frequency, the LEDs produce distinct dotted lines as my eyes move across the array, which I think is a useful attribute for a light intended to attract attention; you may have seen the same effect with LED automobile taillights.

I grouped the LEDs by their forward voltages, using the curves in Photo 2, into three strings of three LEDs with similar total forward voltages. Photo 3 shows that the strings match within 88 mV at 100 mA, about half of the worst-case variation. In addition to the three red LED strings, I added three amber LEDs with similar forward voltages, although they turned out to have very nearly the same color as their red cousins.

Photo 4 shows the current through each of the four strings, with the amber LEDs represented by the blue trace. I picked the series resistors (R5 through R8 in Figure 1) to produce about 100 mA, although you can see that the actual current in each string increases by 10 to 20 mA during the pulse. I measured those values with a Tektronix AM503 Hall-effect current probe, which reported the actual current without affecting the circuit.

The forward voltage across each string decreases in a nice exponential curve during each 2-ms pulse, which shows the change in LED die temperature. The exact coefficient for the change in forward voltage with temperature depends on the LED’s chemistry, but –3 mV/K seems typical: a –50 mV change across a single red LED implies a 17-K temperature increase.

A typical 5 mm epoxy LED package has a thermal coefficient of 300 K/W from junction to ambient, which means a die dissipating an average 200 mW will be 62 K above ambient. The air over my workbench is about 18 °C, so the LED die temperature jumps from 80 °C to 97 °C in 2 ms.

The Arduino based LED Curve Tracer steps the current upward during each test, producing more internal heating than these low duty cycle pulses. As a result, the forward voltage values shown here differ by about 100 mV from those earlier results: obviously, lab-grade instruments require better calibration.

I turned that circuit board on in mid-December 2012 and let it run continuously

until late May 2013, about 3,600 h later. The 20% duty cycle means the LEDs have spent 720 h with 100 mA flowing through them.

Now, did that make any difference?

MEASURING LIGHTMeasuring the light produced by an LED

requires a current source driving the LED, a transimpedance amplifier to convert the photodiode current to a voltage, and a mechanical test fixture that positions each LED at a repeatable position in front of the photodiode. Fortunately, I needed only relative measurements between a few dozen LEDs, not lab-grade absolute calibration, so a simple DIY approach would suffice.

The LED current source in the lower left

PHOTO 3The forward voltage of the red LEDs strings differ by only 88 mV at 100 mA. The horizontal part of the traces is the LED supply voltage, so the total forward drop across all three LEDs is about 6.7 V. The exponential drop in forward voltage during the pulses shows the effect of junction temperature.

PHOTO 4The current through each LED string averages about 100 mA during each pulse; the current probe sets the vertical scale at 20 mA/div. The forward voltage variations make an obvious difference in the LED current.

PHOTO 5This 3-D printed test fixture positions a 5-mm LED just over the window of the photodiode, with neutral-density filter disks to reduce the light intensity. The black PLA plastic excludes all external light.

Page 58: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27856CO

LUM

NS

part of Figure 2 converts an input voltage into LED current. IC2A applies enough gate drive to the IRLZ14 MOSFET to produce the current called for by the input signal. IC2B scales the voltage from the 1-Ω current-sense resistor to produce an overall gain of 25 mA/V and closes the feedback loop through IC2A. A function generator supplied 4 V, 100 Hz, 2 % duty cycle pulses that drove the LEDs with the same 100 mA pulses as the tester in Figure 1. Because this is a linear transconductance amplifier, you can apply any waveform or DC voltage, although you may want a better op amp than an LM324.

The heavy black outline around LED1 and D1 represents the 3-D printed test fixture shown in Photo 5 that couples the LED to the photodiode. The LEDs in Photo 1 have a clear epoxy case, but a red diffused LED shows up better against the black PLA plastic. The huge

PIN-10AP silicon photodiode on the left is a surplus find with a green filter matching its response to the CIE human eye sensitivity; that won’t be helpful with red LEDs, but would come in handy for brightness-matching different colors.

The OSI Optoelectronics PIN-10AP datasheet recommends using it in “photovoltaic” mode with zero bias, in contrast to the more familiar “photoconductive” mode with substantial reverse bias. In fact, a reverse bias of more than 3 V will permanently damage the PIN-10AP, so the pair of 1N5819 Schottky diodes clamp the voltage well under 1 V, even if something goes badly wrong.

IC1 converts the photodiode current to an output voltage, with gain set by R1. Because the op amp’s non-inverting input is at 0 V, its feedback will hold the inverting input at 0 V, so the photodiode sees 0 V across its terminals. I used an old-school LF356, but any op amp with low bias and offset currents will work.

Both the LED and photodiode feedback loops have fairly low bandwidths, set by C6 and C1, respectively. You should pick those capacitors to roll off the response as needed by the input signals. The PIN-10AP datasheet suggests using it below 350 kHz, which far exceeds this circuit’s requirement.

The four ND2 neutral-density filter disks in the foreground of Photo 5 provided a simple way to verify that the PIN-10AP output current varied linearly with light intensity. Figure 3 shows the results from a new red LED from the same lot as those shown in Photo 1: each filter layer reduced the intensity by a factor of 4.4. The filter material was intended for stage lighting, so finding it had an actual density of ND2.1 wasn’t too surprising. The first layer has a slightly higher apparent density, probably due to reflections from the uncoated filter surface, but the ratios show the photodiode output remains essentially linear over an intensity range of 256:1.

Because the no-filter output voltage of 8.7 V came close to the LF356 op-amp’s 10.5 V maximum output, I used a single filter layer for the rest of the tests. Obviously, the amount of filtering required will vary depending on the LED, its current, and the photodiode. Note that changing R1 does not change the photodiode current, because that resistor only sets the amplifier’s transconductance: the output voltage for the current controlled by the photodiode.

With one filter in place, I displayed the output of IC1 on an oscilloscope triggered at the rising edge of the LED current pulse and recorded the current just before the trailing edge. The LED output changed slightly as the device heated up in the test fixture, so I let each one warm up for a minute before measuring the current.

FIGURE 1This simple circuit drives the LED strings with 100 mA at a 20% duty cycle. Yes, a microcontroller could do the same job, but a classic 555 timer doesn’t require any programming.

FIGURE 2This circuit applies a known current to an LED coupled to a silicon photodiode and converts the photodiode current to an output voltage. The photodiode operates with zero bias to improve its linearity.

Page 59: Circuit Cellar Sept 2013 153198-Issue 278 Sept

11th International System-on-Chip (SoC) Conference, Exhibit & Workshops

October 23 & 24, 2013 – University of California, Irvine - Calit2

www.SoCconference.comEARLY BIRD REGISTRATION IS NOW OPEN!

Don’t Miss Out! Platinum Sponsors

FinFET Technology & Applications Analog & Mixed-Signal Designs Sub 14nm Designs & Beyond 3-D ICs Designs IC Security & Challenges Terahertz Power in CMOS SoC Design & Verification Biologic Battery SiGe Technology Trends Low-Power Design Techniques Charge-Trap Flash Memory Table-Top Exhibit (Free Passes)

FinFET & Mixed-Signal SoC SOI vs. CMOS & Beyond CMOS Electromagnetic & CKT Co-Design FPGAs –Trends & Designs EDA for High-Speed Interconnects Smarter Mobile Devices Fully Depleted SOI Devices Network-on-Chips (NoCs) Informative Panels IEEE Student Design Contest Networking Opportunities And Much More. . .

Keynote Speakers

Xilinx, Inc.Dr. Kees Vissers

Distinguished Engineer.

Nokia Dr. John Paul Shen,

Nokia Fellow, Founding Head of Nokia Research North

America Lab.

IBM Dr. David Harame Chief

Technical Executive.

University of Pennsylvania Dr. Nader Engheta

H. Nedwill Ramsey Professorof Electrical and Systems

Engineering.

MicrosemiJim Aralis,  

Chief Technology Officer (CTO), 

and Vice President of R&D.

Promote Your Company, Technology, Products & Services at The Most Informative, Targeted & Affordably Priced

Chip Design Conference, Exhibit & Workshops of the Year!

Selected Participating Companies & Universities

For More Information or Questions, Please Contact the SoC Conference Organizing Committee at: [email protected] or (949) 851-1714

www.SavantCompany.com & www.SoCconference.com

Page 60: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27858CO

LUM

NS

The left half of Figure 4 summarizes the results for the “aged” LEDs shown in Photo 1 and the right half for “new” LEDs chosen from the same lot. The LED ID numbers run 1 through 12 from left to right starting in the back row and, quite arbitrarily, from 21 through 32 for the new LEDs.

Three observations stand out:1. No LEDs failed during the test2. New amber LEDs have widely varying

brightness3. Brightness didn’t change much over time

The red LEDs seem essentially unchanged over the course of 720 h and the amber LEDs seem somewhat dimmer, although the tiny sample size certainly doesn’t justify any numeric comparisons. My application for these LEDs might run 2 or 3 h per day, so the test time works out to about a year of actual use.

That’s good news, because it means I need not worry (or, at least, worry less) about early failures or dimming in LEDs used with relatively high currents and short duty cycles.

The graph in Figure 5 shows that the 100-mA current I used for these tests doesn’t produce five times more light than 20 mA and, in fact, increasing the current beyond 80 mA simply heats the LEDs without producing any additional light. That didn’t matter for the stress tests, but it does mean that the maximum pulse current in actual use shouldn’t be much more than 40 mA. The red LED requires 50 mA to double its brightness from its output at 20 mA, so it costs 20% more current to get that additional brightness.

The data points below the nominal 20-mA current level show that the output remains much more linear in that region: PWM dimming works well for LEDs used within their ratings. Of course, chopping a high current into discrete chunks can produce plenty of electronic noise, but that’s a topic for another column!

CONTACT RELEASERamming excessive current through cheap

LEDs isn’t good practice for a commercial product, but it can produce interesting and useful information that helps understand how the devices behave under unusual conditions. A dab of analog circuitry and sometimes even a microcontroller can reveal unexpected behavior and dispel misconceptions.

The downloadable file for this column contains the Eagle schematics for the circuits and the OpenSCAD source code for the LED test fixture.

FIGURE 3Each ND2 neutral-density filter layer reduced the light intensity by a factor of about 4.4, corresponding to an actual ND2.1 attenuation.

FIGURE 4After five months of testing, the group of LEDs on the left don’t seem to differ from the new LEDs on the right. The amber LEDs may suffer more intensity loss, but the sample sizes aren’t large enough for any conclusions.

PROJECT FILES

circuitcellar.com/ccmaterials

RESOURCESS. Keeping, “Determining LED Rated Life: A Tricky Challenge,” Digi-Key Corp.

E. Nisley, “LED Characterization: Arduino-Based Curve Tracer,” Circuit Cellar 276, 2013.

Wikipedia, “Luminosity function.”

SOURCESPIN-10AP Silicon photodiode detector-filterOSI Optoelectronics | www.osioptoelectronics.com

AM503 Current probe amplifierTektronix, Inc. | www.tek.com

ABOUT THE AUTHOREd Nisley is an EE and author in Poughkeepsie, NY. Contact him at [email protected] with “Circuit Cellar” in the subject line to avoid spam filters.

FIGURE 5LED efficiency decreases as current increases, so the 100-mA current used for the life test doesn’t produce five times as much light than the nominal LED rating of 20 mA.

PIN-10AP photodiode response

Neutral density filter – nominal 2 stop/layer Sense R 100 kΩ

Layers V I – µA Ratio 0 8.7 87 -- 1 1.9 19 4.58 2 0.43 4.3 4.42 3 0.097 0.97 4.43 4 0.022 0.22 4.41

Page 61: Circuit Cellar Sept 2013 153198-Issue 278 Sept

www.cc-webshop.com

CC Gold is the complete Circuit Cellar

issue archive! It provides a lifetime of

project articles, design tips, and source

code on a super-small USB drive.

With a digital subscription, you can

download issue PDFs straight to the

drive and keep the archive current.

Get your gold today!

$25 off!

Page 62: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27860CO

LUM

NS

Welcome to my new column, Green Computing. I will be writing about

energy-efficient software and hardware design strategies, opportunities for electricity cost savings and battery-life extension, system-level policies for energy and thermal management, and smart infrastructures for improving efficiency.

Energy is a first-order constraint today for any computing system—from battery-operated mobile computers to large-scale data centers. Most energy management work to date has focused on providing processor capabilities that enable going into low-power states when possible (e.g., by using dynamic voltage and frequency scaling or sleep modes). However, in many modern systems, components other than the processor (e.g., the memory subsystem or the cooling infrastructure) significantly contribute to the total energy. Consequently, a system-level view is needed to effectively optimize for energy.

In data centers, the increase in the electricity use following the performance capacity growth has been motivating many researchers to design green computing strategies at different levels of hardware and software. An important fact to consider in data centers is that cooling is responsible for nearly half of the total energy consumption.[1]

One intuitive approach to address this problem is to let the servers run “hotter” and, as a result, reduce the cooling energy. If the temperatures are too high, hardware reliability problems may arise because many failure mechanisms (e.g., electromigration, negative-bias temperature instability, and dielectric breakdown) accelerate exponentially with increasing temperature.[2]

The idea behind letting servers run hotter relies on the assumption that there is considerable headroom between the typical operating temperatures today and the critical temperatures that will cause reliability problems. Google, for instance, has advocated running data centers hotter by raising the cold aisle temperature to 80°F in its data centers.[3]

An interesting, less-explored trade-off in letting servers run hotter is between the leakage power and the temperature. Leakage power is the static, wasted power circuits consume because of the CMOS devices’ leakage current. Leakage power is exponentially dependent on temperature. So, higher temperatures not only decrease component reliability, but they also may contribute to a larger amount of wasted energy. This

FIGURE 1This photograph and diagram show the experimental setup for enabling customized fan control for a commercial server when changing the built-in controller settings is not straightforward. The logger PC connects to the server’s service processor through the network and uses the Intelligent Platform Management Interface (IPMI) to poll temperature and power sensor data. The logger PC can also read workload utilization information or other workload data from the processor. Depending on the temperature and workload settings, you can then dynamically change the fan speeds by adjusting the power supply settings.

RS-232 Logger and control PC

Power supplies

Six fans

16 cores

Dualin-line

memorymodules(DIMMs)

Harddrives

Serviceprocessor

CPU0

CPU1

Server

Server power supply units (PSUs)

1 2

3 4

5 6

0 1 2 3 4 5 6 7

8 9 10 11 12 13 14 15

Energy-Efficient Cooling Strategies for Servers Analyze and Control Leakage and Fan PowerMany servers are overcooled, partially because of the manufacturers’ safety margins. It’s possible to reduce the cooling energy used by enabling the processor temperatures to rise within safe limits. However, leakage power increases at high temperatures and can cause excessive energy waste. This article discusses how to simultaneously minimize the cooling and leakage energy.

By Ayse K. Coskun (USA)

GREEN COMPUTING

Page 63: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 61CO

LUM

NS

article explores how to experimentally analyze this trade-off between a server’s cooling and leakage and how this analysis can be leveraged to design energy-efficient cooling strategies for servers and computing systems, in general.

EXPERIMENTAL SETUPI will discuss how to set up an experimental

platform that enables you to measure and control a server’s cooling (i.e., fan power) and leakage power. I will not focus on cooling energy management strategies at the data center level (e.g., room air conditioners, etc.), but will leave that discussion for a future article.

Many commercial servers do not enable users to interfere with the cooling controller or they offer limited options to set different cooling control policies. For example, even though a server may have a temperature-aware fan control algorithm implemented, the server’s minimum permitted fan speed may still be overcooling the system. Server vendors often include such safety margins as they expect to sell the server to customers at many different locations and altitudes.

To overcome this issue, we pulled out the original fans from an Oracle SPARC Enterprise server in our lab and replaced them with fans of the same make and model. We hard-wired the replacement fans to external power supplies (Agilent Technologies E3644A), which were in turn connected via RS-232 to a logger and control PC. In this way, we were able to control the power supplies, and thus the fan speeds, according to a custom-designed fan control policy.

An important preprocessing step is to determine which power supply current would amount to which exact fan speed value. It is possible to construct this relationship by testing out different current values and reading out the fan speed (rpm) values. If rpm sensors do not provide sufficient accuracy, you can use vibration sensors to perform the calibration between current and rpm.

Figure 1 shows the experimental setup. The system has two processors, each with 16 cores. We collect power and temperature sensor data by connecting from the logger PC to the server’s service processor and use the Intelligent Platform Management Interface (IPMI) to poll the “sensors of interest” (i.e., we use ipmitool commands).

For the leakage vs. fan power analysis, we poll the following sensors: each processor ‘s current values (to estimate processor power), total system power, and each processor’s temperature values. It is typically possible in similar experimental setups to achieve a

sampling interval up to a few seconds. In our analysis, we used a 10-s sampling interval, which was sufficient to observe the power and temperature changes.

DERIVING AN EMPIRICAL POWER MODEL

The server’s total power consumption is a summation of PACTIVE (the power consumed by the workload), PLEAK (the leakage power), and PFAN (the cooling power). We already isolated the fan power in the setup described earlier, as the fans are connected to external power supplies. We need an empirical power model to separate the PACTIVE and PLEAK components to investigate how PLEAK, PFAN, and temperature values interact.

PACTIVE is a workload function. To create an empirical model, we use a synthetic load generator for the Oracle server that can keep the CPU utilization at a desired value by frequent duty cycling between full utilization (100%) and idle. Similarly, it is possible to use Standard Performance Evaluation Corporation (SPEC) benchmarks (e.g., SPEC_power ssj2008), which can keep utilization at a desired value. Using top or mpstat in Linux, we verify whether the desired utilization level is met. In experiments with the synthetic load generator, utilization is the only workload parameter we are changing. Hence, we can express PACTIVE as a function of utilization (i.e., PACTIVE = c1.U). Leakage, on the other hand, can be expressed in exponential form,

FIGURE 2These plots show the leakage and fan power as a temperature function. a—When the rpm is set at lower values, the average temperature is higher. Fan power is a cubic function of fan speed, so it decreases with lower rpm. Thus, you see a low fan power value at high temperatures. Nevertheless, leakage increases with higher temperatures. The lowest total power consumption for this experiment with 100% CPU utilization is achieved around 70°C. b—Each line shows the sum of fan and leakage power for a given utilization level as the rpm (and thus the temperature) varies. The temperature and, hence, the rpm that achieve the minimum power change depending on the utilization. This observation motivates designing an adaptive, dynamic policy that computes the optimum fan speed setting to minimize total energy.

b)

a)

Page 64: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27862CO

LUM

NS

as follows, where every c is a constant and T is the temperature:

P = c + c × e LEAK 2 3C T4

Using these equations, along with a set of temperature and total power consumption measurements from the server (PACTIVE + PLEAK) under different workload utilization levels and different fan speed settings, we perform simple model fitting in MATLAB to compute the constants’ values and construct the power model.

Figure 2 shows the leakage and fan power as a function of temperature, as computed by our empirical models. In this experiment, we change the rpm between 1,800 and 4,200 at increments of 600. In Figure 2a, the workload utilization is at 100%. In this case, the minimum total power consumption is achieved when the average temperature is around 70°C and the rpm is set at 2,400. In Figure 2b, we see that the temperature (and thus the rpm setting) that minimizes the power consumption changes depending on the utilization.

ENERGY-EFFICIENT COOLING CONTROL

Using the analysis described earlier, a simple control strategy is to create a look-up table that links the utilization level with the rpm setting achieving the lowest total fan and leakage power at that utilization (e.g., the

table has entries for utilization levels from 0% to 100% at 10% increments and each entry provides the corresponding rpm value). In this way, when the workload is running, we can check the processors’ utilization and set the fan speed accordingly. Using this strategy, we have observed up to 9% server energy savings.[4] Note that these savings have not implied any changes to the workload or the performance. Thus, there is a significant potential of monetary savings without user performance trade-off.

An additional benefit to performing leakage-aware cooling control is avoiding the processor’s large temperature swings. For example, if we use a reactive strategy that increments or decrements the fan speed upon reaching various temperature threshold values (i.e., a bang-bang controller), the temperature difference is larger and we end up performing more fan-speed changes. We expect the more stable temperature profiles and fan speed settings achieved by the leakage-aware controller to benefit the overall system health.

How would this strategy work for arbitrary workloads? Can we always rely on measuring utilization to determine the best fan speed setting? The simple answer is no, as the processor utilization may not always provide an accurate estimate of the processor power and temperature dynamics. This is because different applications stress different processor parts. Some may be cache-intensive, some may be floating-point intensive, and some may be control-intensive and perform many branches and jumps. These workload differences become especially significant in determining high-performance processors’ power profiles.

If utilization does not provide sufficiently accurate estimates, we can derive a more sophisticated model that correlates the workload behavior with the power and temperature. For example, an approach we have successfully implemented on a commercial multi-core processor is to write several microbenchmarks, each of which stresses different microarchitectural parts of the CPU.[5] While running the benchmark set, we poll the hardware performance counters (e.g., cache misses, number of instructions, number of floating-point instructions, etc.) through Linux performance-monitoring subsystems (e.g., perf), and at the same time measure the power and temperature. In this way, we construct a model that accurately correlates performance counters with the power consumption.

Using this model, once we estimate the dynamic power consumption resulting from the specific workload behavior and isolate it

circuitcellar.com/ccmaterials

REFERENCES[1] R. Sawyer, “Calculating Total Power Requirements for Data Centers,” White Paper #3, American Power Conver-sion (APC), 2004.

[2] JEDEC Solid State Tech-nology Association, “Fail-ure Mechanisms and Models for Semiconductor Devices,” JEP122c, 2006.

[3] Google, Data Centers (Ef-ficiency), www.google.com

[4] M. Zapater, J. L. Ayala,

J. M. Moya, K. Vaidyanathan, K. Gross, and A. K. Coskun, “Leakage and Temperature-Aware Server Control for Improving Energy Efficiency in Data Centers,” Proceedings of the Confer-ence on Design Automation and Test in Europe, 2013.

[5] Md. A. Khan, C. Hankendi, A. K. Coskun, and M. C. Herbordt, “Software Optimization for Performance, Energy, and Thermal Distribu-tion: Initial Case Studies,” Proceedings of IEEE International Workshop on Thermal Modeling and Management: From Chips to Data Centers in conjunction with the International Green Computing Conference, 2011.

RESOURCEWikipedia, “Intelligent Platform Management Interface.”

SOURCESE3644A DC Power supplyAgilent Technologies, Inc. | www.agilent.com

SPARC Enterprise serverOracle | www.oracle.com

Page 65: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 63CO

LUM

NS

from the leakage power, we can apply the same leakage fan power analysis described earlier. Instead of using a microbenchmark suite, another technique is to run a representative application set on the target system to derive the relationship between workload performance events and the power consumption.

APPLICATIONSToday’s typical server cooling control

algorithms adjust the fan speed to regulate the cooling power while keeping the temperature at safe levels. Some data center operators suggest increasing the server nodes’ operating temperatures within reliable limits to further reduce the cooling energy.

This article has demonstrated the significance of considering leakage as part

of the cooling control loop, as leakage power increases at high temperatures. Without taking the leakage power into account, reducing the fan speeds may increase the computing system’s overall energy. The experimental example I provided in this article has focused on an enterprise server; however, the same principles apply to designing any efficient cooling system.

Leakage power continues to significantly contribute to the processor power consumption in advanced process technology nodes (i.e., 45 nm and above). Thus, determining the empirical relationship between leakage, cooling power, and temperature leads the way for designing practical energy-efficient cooling control methods.

ABOUT THE AUTHORAyse K. Coskun ([email protected]), an assistant professor in the Electrical and Computer Engineering Department at Boston University, writes Green Computing, a new bimonthly Circuit Cellar column. She received MS and PhD degrees in Computer Science and Engineering from the University of California, San Diego. Ayse’s research interests include temperature and energy management, 3-D stack architectures, computer architecture, and embedded systems. She worked at Sun Microsystems (now Oracle) in San Diego, CA, prior to her current position at BU. Ayse serves as an associate editor of the IEEE Embedded Systems Letters.

Page 66: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27864CO

LUM

NS

Character-based LCDs’ low cost and ease of use make them essential to many

interesting projects. They come in many sizes, ranging from single-line, eight-character displays to multi-line, 80-character widths. They have one design flaw that makes them less useful to those who “think outside the character.” All are based on fixed-character placement and have built-in blank areas between characters.

The most common LCDs use a 5 × 7-pixel character matrix. This becomes most obvious when block characters (i.e., all 35 character pixels) are on. Characters are separated by a one-pixel width acting as spacing between characters.

Multiple rows also have a one-pixel spacing between rows. These spacing areas are non-dynamic (i.e., the areas are not manufactured with a controllable crystal structure.) Since the user can control which pixels within a

5 × 7 character block are on, it’s tempting to create larger icons made from multiple character positions. While this is possible, cross-hatching of uncontrollable pixels will always obscure such icons (see Photo 1).

An LCD manufactured without these spaces will not only be more expensive (with more active area), but will also more difficult to control (with more column and row drivers). The resolution isn’t anything to write home about either. So, while reducing the pixel size makes life better, it also boosts the cost. You have a reasonable resolution, but you can still only display in mono-color.

If you add additional colors, cost and complexity increase. This boils down to two choices: the inexpensive character display, which many can afford, or the expensive color-graphic display, which few can afford.

Enter the hand-held video game industry. Huge production runs made graphic displays commonplace, helping to quickly reduce their costs. We can finally take advantage of lower-cost graphic displays with one caveat: While built-in hardware controllers and drivers take charge of the pixels, you are now responsible for more than just sending a character to be printed to the screen. This makes the controllers and drivers not work well with the microcontroller project. That brings us to impetus for this article series.

In Part 1, I began by discussing how to use a graphic display to print text, which, of course, includes character generation. In essence, I showed how to insert some intelligence between a project and the display. This intermediary would interpret

PHOTO 1You can create custom characters on a character LCD to display larger graphics, but you can’t control the blank row and column between each character.

Serial Displays Save Resources (Part 3)BMP FilesThe first two parts of this series introduced a microcontroller-based project that uses a four-wire interface to a graphic LCD with a touchscreen. It also described how to implement button commands for display customization. Part 3 focuses on the BMP graphical file format. Understanding this file format is essential if you want to work with a graphic icon’s data.

By Jeff Bachiochi (USA)

FROM THE BENCH

Page 67: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 65CO

LUM

NS

some simple commands that enable you to easily make use of the display’s flexibility by altering position, screen orientation, color, magnification, and so forth.

Part 2 revealed how touch-sensitive overlays are constructed and used to provide user input. The graphic display/touch overlay combination is a powerful combination that integrates I/O into a single module. Adding more commands to the interface makes it easier to create dynamic buttons on the graphic screen and reports back whenever a button is touched.

Since I am using a graphic screen, it makes sense to investigate graphic files. This article examines the BMP file makeup and how this relates to the graphic screen.

BITMAPPED GRAPHICSBitmap (BMP) files store images. While

photography and other technologies may have started as analog media, quantifying them for storage can require giant file sizes. To make this more manageable, the analog form is converted into a digital form.

The digital form divides the analog media into pieces by defining how many pieces it is broken into (sampled points) and accurately describing each piece (resolution). The resolution (bit size) and samples (number) can be adjusted to get the most compact file size that does not sacrifice any perceptible accuracy in its reproduction.

The pixel is the minimum piece of data. It is an arbitrary area described by its color. While it could take on any shape, it is normally square. Its data describes the displayed area’s color, whether it’s as small as a pinprick or as large as a sheet of paper.

If an analog image is converted to digital, a pixel’s color is an average of all the colors within the area it represents. So while the pixel’s data size is important, so is the sample number (i.e., the pixel size) each pixel’s data is describing.

Matrix printers are responsible for the term “dots per inch” (DPI), which is a measurement of the number of columns (of dots) a printer can print per inch of paper. The more DPI, the

closer together (and smaller) 5 × 7 characters can be printed.

Alternatively, characters can be made from larger matrixes that are perceived as more nicely formed text. Today, DPI is used to describe the vertical and horizontal resolutions of a display in pixels per inch.

National Television System Committee (NTSC) TV, the analog television standard, has a 640 horizontal pixel (columns) × 480 vertical pixel (rows) digital resolution. So a 20″ standard screen may be about 50 DPI. HDTV 1080i, the high-definition television standard, has 1,920 × 1,080 pixels. However, some large HDTV screens can have 50 DPI or less. It’s all relative.

FILE FORMATThe BMP file format2 can store a digital

image of arbitrary size (width × height) and resolution. The file format has three basic parts: the bitmap file (BF) header, the device-independent bitmap (DIB) header, and the image data. The BMP file’s signature is the first two characters of the BF header and should be “BM.” Following this is the actual file size in bytes (double word), two reserved words, and, finally, an offset within the file where the image data starts. The BF header provides assurance that the file is, indeed, a BMP file and what the total file size should be. It also points to the data, but you haven’t yet learned anything about the format itself.

The DIB header supplies information about the image. In the DIB’s core header, you learn about the image’s height and width. The DIB’s information header describes the resolution, compression, and color format. Each pixel’s resolution tells you how many potential colors each image data unit contains. I say “potential” because not every color is necessarily used, but the full palette is available. The standard resolutions are 1, 4, 8, 16, 24, and 32 bits. The number of potential colors for each resolution “n,” is 2n. For instance, 1 bit of resolution can use any two colors.

The color formats can differ depending on the core header information. However, the most widely used format is RGBAX with four

TABLE 1This table shows how each pixel row’s image data is packed into 4-byte units. Zeros are used to pad the data when it does not completely fill each image data row’s last 32-bit unit.

Resolution ColorsPixels Represented by 32 Bits

Number of 32-Bit Units Necessary for a 15-Pixel Row (Bits Used in Unit)

“Zero” Padding Required in Last Unit

1 bit 2 32 1 (15 of 32 bits) 17 bits4 bit 16 8 1 (30 of 32 bits) 2 bits8 bit 256 4 3 (32 of 32 bits) + 1 (8 of 32 bits) 24 bits16 bit 65,536 2 7 (32 of 32 bits) + 1 (16 of 32 bits) 16 bits24 bit 16,777,216 1.3 11 (32 of 32 bits) + 1 (8 of 32 bits) 24 bits32 bit 4,294,967,296 1 15 (32 of 32 bits) 0 bits

Page 68: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27866CO

LUM

NS

individual values, where the most significant byte (MSByte) is the alpha (opacity) value, followed by the blue, green, and red values, all of which are 8-bit.

There are two ways to present image data. While all image data refers to its (pixel) color, the actual data may be direct and contain color data, or it may be indirect and contain a pointer to a color table. This has to do with keeping the file size as small as possible. In

my example of a 1-bit image with only two colors, you can save a lot of space by using a static color table (i.e., a list of available colors) and having the image data point to just one of the two available colors.

One-bit image data pointers (or offsets to the color table) can be packed eight pixels to a byte. That is eight individual pixel colors stored in each image data byte as opposed to using four color byte values of image data for each pixel. The overhead or extra data, which increases the file size, is the color table’s length (in this case, 8 bytes).

Using a color table can greatly reduce the image data requirement for 1-bit resolution files. By contrast, a 32-bit resolution file would require a color table of 17,179,869,184 bytes (i.e., 4,294,967,296 × 4 bytes) of overhead. Using direct data or 4-byte color values per pixel would be a much wiser choice.

At some point, it no longer makes sense to use a color table. In general, a color table is a good choice for up to 8 bits of resolution, which is a 256-entry (i.e., 1,024-byte) table.

The image data format is based on the image’s number of horizontal pixels. Each row’s data is packed into 32-bit (4-byte) units.

I’ll use a 15 × 15-pixel image icon size as an example. Referring to Table 1, you can see that a 15-bit image width of 1-bit resolution data (one of two possible colors) requires only 15 bits of the last, and in this case only, 32-bit unit. This unit’s remaining 17 bits are padded with zeros to fill it. You should note that padding is not always necessary and can be any value. Most images’ height is more than one. The same rules are used to append additional rows.

I’ve found that not all header entries contain data. Some entries hold unnecessary data (or provide no data, e.g., important colors). I presume this may be used to indicate how many colors of a potential color table are actually used in an image. (If a standard color list is included but the picture uses only black and white, you can save memory space by only including references to black and white. Without this information, you would have to scan the picture’s complete pixel data to determine what colors are being used.)

Another entry has to do with compression. While I’m sure this is used to reduce the file size for large files, I did not handle any files that used data compression and, therefore, have not implemented any decompression algorithms. Documentation suggests run-length encoding (RLE) is popular, as it performs lossless data compression and is well suited to palette-based images. Fax machines use RLE, as the scanned image is mostly white with short bursts of black. This compression form adds a repeat count prior to each data

BMP Display file data

Color palette?

N

N

Y

Y

Y

N

File found?

Size OK?

Return

Return

Call Search4File

Call convert and store

color palette

Call get directory entry

Call display file data

Call DoPixels

ImageWindowSize =ImageWidth, ImageHeight

Call enable image skew

Call disable image skew

FIGURE 1The BMP routine searches the SD card’s directory sectors for the requested file. If found, the directory entry holds file information that helps locate the sectors with the file’s data. The BMP file is then read one sector at a time. Once the file’s header information has been digested, you know the image’s size and how each pixel’s color data is stored. Based on this information, you can proceed to transfer pixel (color) information to the graphics display.

PHOTO 2I used Liberty BASIC to write this application, which displays the information found in a BMP file. You can read a BMP file, display header information, and send ASCII commands out the serial port to this project. It will use the “p” (i.e., pixel) command to show a BMP file on the graphics display.

Page 69: Circuit Cellar Sept 2013 153198-Issue 278 Sept

We’re celebrating a new look — and the next 25 years.

25% off CirCuit Cellar Whether it’s programming advice or design applications,

you can rely on Circuit Cellar for solutions to all your

electronics challenges. Raspberry Pi, embedded Linux,

low-power design, memory footprint reduction and

more! Become a member, and see how the hottest new

technologies are put to the test.

www.circuitcellar.com/sepN13J o i n t o d a y !

Page 70: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27868CO

LUM

NS

byte. While it adds overhead (count value), it eliminates multiple identical consecutive data.

TOOLSI find that tools help you gain some

understanding before diving into a project. Sometimes, you have to make your own tools. I often use Shoptalk Systems’s Liberty BASIC to quickly code an application (or tool). For this project, I wrote a BMP file investigator. The application reads in a BMP file and strips off the header information (so I can see what’s there) and builds an image from the image data.

I began by using a small image that is a color test pattern. The image size is only 50 × 50 pixels and contains image data formatted 4 bits per pixel using a 16-color palette (see Photo 2). Check boxes enable the verbose display of varied header information. Fifty pixels pack into 25 image data bytes. Remember that a row’s data must be fitted to an even 4-byte unit and 25/4 = 6.25. That means the seventh unit must be padded for a total of 28 bytes per row. Note that 50 rows × 28 bytes = 1,400 bytes for the image data. Referring to Photo 2, you can see that the application has reported that it has read 1,400 bytes of image data.

The BMP tool also contains an area where the screen displays image data. For whatever reason, the image data stored in the BMP file begins with the bottom left instead of the top left, which means that if the image data is displayed from the top down, as stored, it will be upside down. If I read and hold the data

in memory by row, I can easily start with the last row so it is displayed right-side up. I found a note suggesting that if the height is a negative number, the image data is top to bottom, but I did not see this with any of my files. This application is a work in progress because there are many possible options (e.g., compression) I haven’t encountered. So I haven’t written any algorithms for them yet. Feel free to use and improve this application for its educational value.

Once I was getting results and had gained some understanding of the BMP file format, I was ready to add the ability to show image data on the graphics display project I presented in Parts 1 and 2 of this article series. Since my project simplifies using the display by offering a command set, I needed to add a couple commands specific to images.

The first command bitmap=row,column defines an image window’s size by width and height. The second command p=hhhh is used to display a colored pixel. To use these commands, you would want to position the cursor to where you want the image to be displayed (the image’s upper left corner), send the bitmap command to establish a window, and then send the image (pixel) data to fill the window. You don’t need to worry about an upside-down image here, as the PC’s application has already reversed the row data.

When using this graphic display with your project, you could have image data in a table to send to the display. However, even an image such as this one (50 × 50 pixels) uses 1,400 bytes for its image file. That’s a lot of storage space for some microcontroller’s projects. In reality, it’s less than 1,000 bytes, since the graphic display uses only 16 bits for color information. This means that while the BMP’s color data is in a 4-byte RGBAX format and the tool display requires 24-bit color data for its display, the data the tool sends out to its serial port (simulating your microcontroller’s data to the display) must be further compressed into just 16 bits per pixel.

The format for the graphic display’s pixel color is the most-significant 5 bits of red, the most-significant 6 bits of green, and the most-significant 5 bits of blue. With communications running at approximately 115,200 bps, the tool records the time it takes to send all the commands necessary to the display and you can see the pixels being painted on the screen. It takes about 2 s. This is probably acceptable for small images but would take a long time for large images—and those may require more storage space than you have available. Enter the SD card.

SD STORAGEIn 2009, I presented a two-part article

series on solid-state storage using SD cards

PHOTO 3A BMP file has image data storage beginning with the image’s last row. a—Displaying this data as stored will result in an upside-down image. b—Using the upsidedown=1 command will rotate the display 180°. c—The mirror=1 command flips the image horizontally. d—Finally, an origin change is necessary to shift the image to the desired location. These commands are all issued prior to transferring the pixels, to correct for the way the image data is stored.

Page 71: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 69CO

LUM

NS

TABLE 2With a single display buffer, you are forced to update the screen in real time. When you are writing the same pixel data to each location, there are no decisions to be made between pixels. This results in the fastest possible screen update.

Full-Screen Transfers

Time (s) in Seconds

Display image using “p” (i.e., pixel) commands (115,200 bps)

85

Display image from the SD card

5

Clear screen 0.5

PHOTO 4The prototype PCB I used for this project mounts to the reverse side of the thin-film transistor (TFT) LCD. The black connector holds the serial and power connections to your project. The populated header is for the Microchip Technology MPLAB ICD 3 debugger/programmer.

(“Access SD Memory Cards,” Circuit Cellar 222–223). These articles provide a complete reference on using such devices. Here, I will just note that early on I added SPI to this project in case I wanted to look into using an SD card to locally store BMP files. Having sent small image data over the serial interface, it was clear that local storage would be a good thing. Since the BMP files can be preloaded onto an SD card, I wouldn’t ever need to write anything to a device, which simplifies things a bit.

The first new command I added to this project test=3 is a test routine to dump the file names to the serial port. This assured me that I could read sectors from an SD card, find where the directory resides, and extract active file names. A PC’s terminal program showed me a list of the files and gave me the confidence to proceed.

While obtaining a directory listing from an SD card is no small task, the second command bmp=filename was the real challenge. Previously using Liberty BASIC to write the task was a real confidence builder and provided me with a task list for the job. I had almost infinite resources on the PC, but now I was stuck with rather limited resources. My code and data spaces were approaching the half-full mark (16,000 and 1,000 bytes, respectively). Reading an SD card sector requires 516 bytes and an 8-bit color table requires 512 bytes. Yikes! This would be close.

Figure 1 shows a flow chart of the

Page 72: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27870CO

LUM

NS

BMP command. Remember when I discussed the fact that the image data is stored last row first? This creates a problem here, as there is not room to read in the total file to get to the last row of data and transfer it first. It is certainly possible to read through the whole file multiple times and grab the rows in reverse order. But this seems time-consuming, as you can only handle one sector at a time.

There is another approach. If you display the data as it comes from the file, you get an upside-down image on the screen. You have access to a few routines that can manipulate the way data is presented on the screen. The two commands you can use here are upsidedown and mirror. The upsidedown command is a bit of a misnomer, as it means rotated 180° and reflection along the horizontal axis; whereas mirror means reflection along the vertical axis. Originally, I began with a rotation command, which has four possible 90° formats. This became a bit confusing, so I changed the command to orientation with a “p” (portrait) and “l” (landscape) format. Using the orientation command is less confusing with the upsidedown and mirror commands.

Photo 3 shows the result of displaying an image without any adjustments. If you use the upsidedown=1 command prior to the transferring image data, the display is reconfigured and you will see the image as shown in Photo 3b, which is displaying right-side up in the opposite corner and is a mirror

image of what you want. If the mirror=1 command is added before transferring image data, the display is again reconfigured and you will see the image as it appears in Photo 3c. This time, it’s right-side up, in the lower left corner and not mirrored. All you need do now is adjust the origin prior to transferring the image data (see Photo 3d). Before leaving, you must use the upsidedown=0 and mirror=0 commands to undo the skewing added to get the image to properly display. All this is handled “under the hood,” so you never have to know the contortions necessary to display an image.

TAKE IT AWAYI’d wanted to do this project for a while,

but either display prices were too high, touch was not integrated, or the display was not user-friendly. The only drawback I found to this display was insufficient memory for a dual-display buffer. A double buffer enables you to write a screen in the background and then exchange active buffers or transfer data all at once. This eliminates painting, which is a slower way of visually updating of the screen due to intensive computations for each pixel transferred.

Obviously, any work that has to be done for every pixel will add overhead to the pixel-transfer process. I placed an oscilloscope on the microSD card and enabled output to get a feel for the amount of time being spent on SD card vs. display functions. I was surprised to find that about 83% of the time spent on a full screen image was spent on SD card transfers. A sector read (516 bytes) takes about 10 ms. Table 2 provides some timing data for three full-screen functions (writing 76,800 pixels).

There are certainly many project areas to be explored. Ninety days is hardly enough time to thoroughly develop a product. I look forward to seeing the graphic display become a bubble-gum part in the near future as its ancestor, the character display, is today. Until then, you can experiment with my approach and use it to improve your next project’s user interface. The four-pin interface connector can be seen in the upper left corner of my prototype PCB, which is piggybacked to the thin-film transistor (TFT) LCD (see Photo 4).

PROJECT FILES

circuitcellar.com/ccmaterials

RESOURCESJ. Bachiochi, “Access SD Memory Cards (Part 1): Solid- State Storage Media in Embedded Apps,” Circuit Cellar 222, 2009.

———, “Access SD Memory Cards (Part 2): Use the FAT

File Format to Move Data,” Circuit Cellar 223, 2009.

Wikipedia, “BMP File Format.”

SOURCESILI9325 TFT LCD Single-chip driverILI Technology Corp. | www.ilitek.com

Liberty BASICShoptalk Systems | www.libertybasic.com

PIC24FV32KA302 MicrocontrollerMicrochip Technology, Inc. | www.microchip.com

ABOUT THE AUTHORJeff Bachiochi (pronounced BAH-key-AH-key) has been writing for Circuit Cellar since 1988. His background includes product design and manufacturing. You can reach him at jeff.bachiochi@ imaginethatnow.com or at www.imaginethatnow.com.

Page 73: Circuit Cellar Sept 2013 153198-Issue 278 Sept

June 21 - September 21, 2013

SAVEUP TO

50%!

Books Kits

MembershipsCD/DVDs

Modules And more...

Register for our FREE Elektor.POST newsletter to receive our weekly Summer Deals*

www.elektor.com/newsletter*If you already receive Elektor.POST you don’t have to act. You’ll automatically receive our Summer Deals.

www.facebook.com/elektorim www.twitter.com/elektor

An Exclusive Offer in your Email Inbox each Tuesday

Connect with us!

TAKE ADVANTAGE OF OUR WEEKLY SUMMER DEALS!

CRAZY WEEKS @ ELEKTOR!

www.elektor.com/newsletterwww.elektor.com/newsletter

Summer ad CC 130621.indd 1 21-06-13 12:02

Page 74: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27872TE

STS

& C

HALL

ENG

ES

ACROSS4. Heat is neither gained nor lost5. Made of resistors and transistors; not integrated [two

words]8. Two-way communication [two words]10. Muppet-inspired protocol12. Unix-like OS14. Conveys information16. Others like it include BASIC and Pascal18. Contains a minute amount of code capable of executing

in the hardware’s privileged mode19. Current regulator

DOWN1. There are two types: NPN and PNP [two words]2. 1970s communication system for Zilog and Intel

microprocessors [two words]3. Used to control a robot’s motions [two words]4. 10–18 of a second6. This small, light, high-power type is commonly used in

hand-held devices [two words]7. Place where hackers annually assemble9. Bidirectional data transmission11. Programming language for rhinos13. Netherlands-based foundation that provides information

about and access to free software [two words]15. An inexpensive SBC [two words]17. Laser-based measurement technique

CROSSWORD The answers will be available in the next issue and are posted at circuitcellar.com/crossword

SEPTEMBER 2013

1 2 3 4

5

6

7

8 9

10

11 12

13

14 15

16

17

18

19

EclipseCrossword.com

Page 75: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 73TESTS &

CHALLENGES

PROBLEM 1Tom, an FPGA designer, is helping out on a system that handles standard-definition digital video at 27 MHz and stores it into an SDRAM that runs at 200 MHz. He discovered the following logic in the FPGA (see figure).Let’s see if we can work out what it does. To start with, what is the output of the XOR gate in?

PROBLEM 2Why is this necessary?

PROBLEM 3What is the AND gate’s output?

PROBLEM 4Tom decided to verify the circuit’s operation in his logic simulator, but immediately ran into a problem. What was the problem and what could be added to the circuit to make simulation possible?

TEST YOUR EQ Contributed by David Tweed

SEPTEMBER 2013

What’s your EQ? The answers are posted at www.circuitcellar.com/eq. You can contact the quizmasters at [email protected].

Page 76: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27874

CC SHOP

1 CC GOLD

It’s the ultimate archive for all things Circuit Cellar: project articles, tutorials, source code, project files, and more! The USB includes every Circuit Cellar issue in PDF format and article code from the beginning through your date of purchase. Keep your CC Gold archive up to date with a Circuit Cellar digital subscription. The archive is loaded with everything you need to know about: embedded applications and develop-ment, signal processing, wireless com-munications, programmable logic, em-bedded programming, measurement and sensors, analog techniques, data acquisition, Internet and connectivity, communications, robotics, graphics and video, and more.

Item #: CCGOLD • $250

2 CC 2012 ARCHIVE CDA top-selling item, the CC 2012 Ar-

chive CD puts an entire year of embed-ded design solutions at your fingertips. With quick links to the all projects, source code, and schematics, CC ar-chive CDs will become a staple in your prototyping artillery. Articles cover

everything from energy-harvesting applications and environmental data logger construction, to developments in microelectromechanical systems and Arduino survival guides. The content on these CDs will help you master the evolving world of embedded design and development.

Item #: CD-017-CC2012$34

3 EMBEDDED LINUX BOARDLinux is available on many devices,

but the OS’s complexity and high de-velopment costs can be challenging at times. Not the case with this board! The beginner’s course that accompanies this development board makes it an ideal kit for Linux experts and enthusi-asts alike. Features include a two-layer board with readily available compo-nents, compatibility with standard de-bugging and programming software, 180 MHz, 32-MB RAM, and 64-MB swap.

Item #: EPS-ELNL-120026-91$93

4 MICROPROCESSOR DESIGN USING VERILOG HDL

With the right tools, designing a mi-croprocessor can be easy. Monte Dal-rymple has taken his years of experi-ence designing embedded architecture and microprocessors, and compiled his knowledge into one comprehensive guide to processor design in the real world. This book demonstrates how Verilog hardware description language (HDL) enables you to depict, simulate, and synthesize an electronic design, therefore increasing productivity by reducing workload with any given proj-ect. The book features Verilog HDL re-view and coding style, debugging, test-ing, and more.

Author: Monte DalrympleItem #: CC-BK-9780963013354$45

5 CC CLOUD TAG T-SHIRTFor a limited time, you can have

an exclusive Circuit Cellar Tag Cloud T-Shirt. Designed for electronics en-gineers, the T-shirt features “Circuit

1

2

3 4

Page 77: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 75

CC SHOP

Cellar” on the front and an embedded electronics tag cloud on the back. It is 100% loose-fit cotton and currently available in large and extra-large sizes.

Item #: CC-SHIRT-001$20

6 EAGLE V6 GETTING STARTED GUIDE

EAGLE is a user-friendly, powerful, and affordable software package for efficient PCB design. It can be used on most main computing platforms in-cluding: Microsoft Windows (XP, Vista, or Windows 7); Linux (based on ker-nel 2.6 or above), and Apple Mac OS X (Version 10.6 or higher). This book will benefit novices and professionals who are eager to learn about EAGLE or may be migrating from another CAD pack-age. From schematic and layout editing tools to project completion, EAGLE V6 will help you achieve your PCB fabrica-tion goals.

Item #: BK-ELNL-978-1-907920-20-2 $47.60

7 TAPIR

The TAPIR—which stands for Totally Archaic but Practical Interceptor of Ra-diation—is a fun and expensive kit that detects frequency levels in electronic devices. Once assembled, connect the headphones and antenna and switch it on. Move the TAPIR around any elec-trical device and you’ll hear different noises, depending on the emitted field’s type and frequency.

Item #: EPS-ELNL-120354-71$21

8 ADUC841 MICROCONTROLLER DESIGN MANUAL

This manual presents a compre-hensive guide to designing and programming with the Analog Devices. ADuC841 microcontroller and other microcontrollers in the 8051 family. It includes a set of introductory labs that detail how to use these microcontrollers’ most standard features, and includes a set of more advanced labs, many of which make use of features available only on the ADuC841 microcontroller.

The more advanced labs include several projects that introduce you to ADCs, DACs, and their applications. Other projects demonstrate some of the many ways you can use a microcontroller to solve practical problems. The Keil μVision4 IDE is introduced early on, and it is used throughout the book. This book is perfect for a university classroom setting or for independent study.

Author: Shlomo EngelbergItem #: CC-BK-9780963013347$35

5

6

7 8

Further information and ordering www.cc-webshop.comCONTACT US: Circuit Cellar, Inc.111 Founders Plaza Suite 300East Hartford, CT 06108USAPhone: 860.289.0800Fax: 860.461.0450E-mail: [email protected]

Page 78: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27876

IDEA BOX the directory ofPRODUCTS & SERVICES

AD FORMAT:

Advertisers must furnish digital files that meet our specifications (circuitcellar.com/mediakit).

ALL TEXT AND OTHER ELEMENTS MUST FIT WITHIN A 2” x 3” FORMAT. E-mail [email protected] with your file.

For current rates, deadlines, and more information contact Peter Wostrel at 978.281.7708 or [email protected].

The Vendor Directory at circuitcellar.com/vendor is your guide to a variety of engineering products and services.

LOW cost with HIGH quality

PCB, PCBA and More

INSTANT QUOTE AT:www.myropcb.com

OR CALL:1-888-PCB-MYRO

“Your reliable outsourcing partner”

MyRO

PRINTED CIRCUIT BOARDSRigid PCB SMT Stencil Aluminium board Flexible PCB

PCBMAIN

PCBMAIN TECHNOLOGY CO., LTDwww.pcbmain.com

Competitive price, high quality

Quick turn, prototype through productionOnline quote & order system

Page 79: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 77

Ultrasonic Distance Sensing Made EZ

HRUSB-MaxSonar®-EZ™ - Multi-Sensor operation - USB interface - Easy integration - 1 mm resolution - Calibrated beam pattern - Starting at $49.95

I2CXL-MaxSonar®-EZ™ - Great for UAV’s and robotics - Incredible noise immunity - I2C interface - 1cm resolution - Automatic calibration - Starting at $39.95

www.maxbotix.com

HRXL-MaxSonar®-WR™ - Incredible noise tolerance - IP67 rated - 1 mm resolution - Multi-Sensor operation - Calibrated beam pattern - Starting at $109.95

http://www.mosaic-industries.comMosaic Industries, Inc. (510) 790-1255

Mosaic Industries Inc. tel: 510-790-1255 fax: 510-790-0925 www.mosaic-industries.com

Tiny 2.5”x4” C-programmable SBC 16 lines of 10-bit resolution analog inputs 24 lines digital I/O with counter/timer and PWM 1 I2C communications port with onboard pull-ups

2 RS232 serial communications ports, 2 SPI ports Full featured development environment with device

drivers for all I/OPrototyping area for custom circuitry

Fast, Powerful, Low CostSingle Board Computer

Only$84/100s

RESEARCHINTERNATIONAL

TRIANGLE

$229 and $295 before OEM Qty Discount

tel : 1 877 TRI-PLCSweb : www.tri-plc.com/cci.htm

Integrated Features : - ETHERNET / Modbus TCP/IP- 16 or 32 digital I/Os- 10 analog I/Os- RS232 and RS485- LCD Display Port- I/O Expansion Port- Ladder + BASIC Programming

LISTENTO YOUR MACHINES

Ethernet PLCs for OEMs

FMD88 -10 and FMD1616 -10

microEngineering Labs, Inc.www.melabs.com 888-316-1753

PIC is a registered trademark of Microchip Technology Inc. in the USA and other countries.

Programmers for Microchip PIC® MicrocontrollersPC-Tethered USB Model (shown):

•Standalone software•Command-line operation•Hide GUI for automated use•Override configuration with drop-downs

Stand-Alone Field Programmer:•Power from target device or adapter•Program file stored on SD-CARD•Programming options stored in file•Single-button operation

Program in-circuit or use adapters for unmounted chips.Zero-Insertion-Force Adapters available for DIP, SOIC, SSOP, TQFP, and more.

Starting at $79.95

Page 80: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27878

Connect with engineers seeking your

design solutions.

Strategic Media Marketing, LLC

[email protected]

www.smmarketing.us

Magazine, e-newsletters, website, advertorials, and more.

ReseRve adveRtising space today!

CROSSWORD ANSWERS from Issue 2761

2 3 4

5

6 7

8

9 10

11

12 13

14

15 16

17

18

19

20

J

S

Y

Q

N

P

M

I

C

R

O

S

O

F

T

U

Y

I

T

E

B

N

C

H

A

R

A

C

T

E

R

L

A

R

G

E

O

B

J

E

C

T

L

A

Y

L

R

Y

A

N

G

L

B

E

O

O

O

Y

P

N

R

S

T

F

E

R

R

O

M

A

G

N

E

T

I

C

I

S

E

T

C

T

Y

B

A

U

D

O

T

C

O

D

E

S

H

C

F

H

M

O

V

E

R

C

L

O

C

K

I

N

G

D

M

O

C

E

D

R

O

P

P

E

R

P

K

G

R

C

A

B

E

A

M

W

I

D

T

H

L

U

S

I

S

S

E

S

T

R

I

N

I

T

R

O

N

N

I

O

A

U

T

O

D

Y

N

E

A

C

G

E

N

E

R

A

T

O

R

G

EclipseCrossword.com

Across6. ALGORITHM—Search engines use them to

produce real-time results9. LOSSYCOMPRESSION—Condenses data by

getting rid of some of it [two words]11. YOTTABYTE—Approximately 1,024 bytes14. PETAFLOP—Measures an FPU’s

performance15. JQUERY—JavaScript library popularity

contest winner17. THICKCLIENT—Able to function without a

central server [two words]18. NYBBLE—4 bits19. DEGAUSSING—Gets rid of magnetism20. SPINTRONICS—aka, magnetoelectronics

Down1. YANG—Co-founded a multinational

Internet company in 19942. MICROSOFT—Originally created and sold

BASIC computer programs for the Altair 8800 microcomputer

3. CHARACTERLARGEOBJECT—Used to store large amounts of text [three words]

4. ACGENERATOR—Changes mechanical energy into electrical energy [two words]

5. DROPPER—Installs malicious code onto computers

7. TRINITRON—Sony Corp.’s CRT technology8. BEAMWIDTH—Commonly specified at –6,

–10, and –20 dB10. OVERCLOCKING—Makes the time go by

more quickly12. FERROMAGNETIC—e.g., iron, cobalt, and

nickel13. BAUDOTCODE—An early digital

communication method [two words]16. AUTODYNE—Invented in 1914 by

electrical engineer Edwin Armstrong, who is also credited with creating FM radio transmission

Page 81: Circuit Cellar Sept 2013 153198-Issue 278 Sept

circuitcellar.com 79

ORDERING INFORMATIONTo order contact customer service:Phone: 860.289.0800Fax: 860.461.0450

Mail: Circuit Cellar Inc., 111 Founders Plaza, Suite 300East Hartford, CT 06108 USA

Customer service hours: 8:30 AM–3:00 PM EST Monday–Friday. Voice mail available at other times. When leaving a message please be sure to leave a daytime telephone number where we can return your call.

Please Note: While we strive to provide the best possible information in this issue, pricing and availability are subject to change without notice. To find out about current pricing and stock, please call or e-mail customer service.

COMPONENTSComponents for projects appearing in Elektor International Media (EIM) publications are usually available from certain advertisers in the magazine. If difficulties in obtaining components are suspected, a source will normally be identified in the article. However, please note that the source(s) given is (are) not exclusive.

PAYMENTOrders must be prepaid. We accept VISA, Mastercard, Discover, and American Express credit cards (in US $ drawn on a US bank only), as well as PayPal. We do not accept C.O.D. orders.

TERMS OF BUSINESSShipping Note: Some orders will be shipped from Europe. Please allow 3–4 weeks for delivery.

MEMBERSHIPSOrder memberships online at circuitcellar.com/subscription. CIRCUIT CELLAR® (ISSN 1528-0608) is published monthly.

One-year (12 issues) subscription rate USA and possessions $50, Canada $65, Foreign/ROW $75. All subscription orders payable in US funds only via Visa, MasterCard, international postal money order, or check drawn on US bank.

Circuit Cellar, Inc.P.O. Box 462256Escondido, CA 92046E-mail: [email protected]: 800.269.6301Internet: circuitcellar.comAddress Changes/Problems: [email protected]: Send address changes to Circuit Cellar, Inc., P.O. Box 462256, Escondido, CA 92046

RETURNSDamaged or misshipped goods may be returned for replacement or refund. All returns must have an RA#. Call or email customer service to receive an RA# before returning the merchandise and be sure to put the RA# on the outside of the package. Please save shipping materials for possible carrier inspection. Requests for RA# must be received 30 days from invoice.

PATENTSPatent protection may exist with respect to circuits, devices, components, and items described in our books and magazines. EIM accepts no responsibility or liability for failing to identify such patent or other protection.

COPYRIGHTAll drawing, photographs, articles, PCBs, programmed ICs, diskettes, and software carriers published in our books and magazines (other than in third-party advertisements) are copyrighted and may not be reproduced (or stored in any sort of retrieval system) without written permission from EIM/Circuit Cellar. Notwithstanding, PCBs may be produced for private and personal use without prior permission.

LIMITATION OF LIABILITYEIM/Circuit Cellar shall not be liable in contract, tort, or otherwise, for any loss or damage suffered by the purchaser whatsoever or howsoever arising out of, or in connection with, the supply of goods or services by EIM other than to supply goods as described or, at the option of EIM, to refund the purchaser any money paid with respect to the goods.

Page 82: Circuit Cellar Sept 2013 153198-Issue 278 Sept

CIRCUIT CELLAR • SEPTEMBER 2013 #27880TE

CH T

HE F

UTU

RE

A ccess to personal electronic devices, such as laptops and mobile phones,

has revolutionized the way we work and live. This fundamental transformation to an ever more connected and mobile society was made possible by the optimization and miniaturization of electronic devices composed of silicon, which is at the heart of traditional modern electronics.

However, silicon’s processing relies on high temperatures and vacuum environments, which makes its applications expensive and compatible only with rigid substrates (e.g., glass). These limitations are motivating the development of the next generation of electronics. The vast array of applications predicted to emerge from organic electronics includes flexible and rollable displays, electronic newspapers, smart bandages, conformal solar cells and batteries, disposable single-use sensors, and electronics embedded into clothes.

Such applications are not only new―and unavailable using current materials and technologies―but they come at a fraction of the cost because processing carbon-based (organic) materials is not restricted to complex evaporation processes. On the contrary, processing organic electronic materials takes place from solution inks at high speed and in large volumes using ink-jet printing, roll-to-roll coating, or spray-deposition. Groundbreaking discoveries fueled a spectacular growth in this field and enabled first-generation products. Organic light-emitting diodes (OLEDs) have already grown into a mature technology, which entered the market several years ago. Organic photovoltaics (OPVs) and organic field-effect transistors (OFETs) are rapidly catching up.

The extraordinary versatility of carbon chemistry enables an infinite variety of modifications to generate diverse optical and electronic properties: organic materials range from conductors such as Tetrathiafulvalene 7,7,8,8-Tetracyanoquinodimethane (TTF-TCNQ) to semiconductors (e.g., pentacene and polyhexithiophene) and insulators (e.g.,

benzocyclobutene and CYTOP). Organic semiconductors are available in two primary varieties: conjugated polymers and conjugated small molecules. Several small-molecule organic semiconductors have matched the performance of amorphous silicon (a-Si), yet these materials have low solubility, which precludes their low-cost manufacture.

The first solution-processing of organic small-molecule semiconductors was developed in 1999 by P. Herwig and K. Müllen. The process consisted of spin-coating the solution of a soluble precursor, followed by thermal treatment to convert to an organic semiconductor. This idea was further developed by J. Anthony, who engineered a variety of organic small-molecule semiconductors that were stable not only in air, but also in several solvents. The onset of such materials has led to the viability of fabricating organic devices with electronic properties compatible with many perceived applications, without compromising the ease of processing.

The discovery of materials that are stable in solution brings forth a vast array of deposition techniques. Ink-jet printing, screen printing, spin casting, doctor blading, and spray coating are among the novel deposition techniques available for soluble organic semiconductors.

While the organic semiconductors are in solution, they remain mobile and maintain the ability to reorganize. Recent results have shown that the molecules within solutions can “see” the surface the fluid is in contact with and anchor themselves accordingly. On surfaces that promote certain interactions with the semiconductor, highly ordered films can be developed. In contrast, when deposited on less-compatible surfaces, where interactions are inhibited, films of a mixture of orientations form and the overall performance is less desirable.

This concept has been used to pattern many devices, effectively isolating individual field-effect transistors (FETs) to prevent “cross-talk” between neighboring devices. By comparison, current techniques to accomplish patterning in a-Si devices require numerous steps that include harsh chemicals and vacuum-processing environments, further adding to production costs. The ability to judiciously control the molecules at the nanometer scale during the film formation process is unique to solution deposition and presents opportunities for new techniques for fabrication and miniaturization of organic devices. Through material engineering and a thorough understanding of the impact that processing has on device performance, organic electronics applications will continue to grow and produce many new opportunities, often foreign to silicon-based technologies.

Jeremy Ward is a physics doctoral student at Wake Forest University in Winston-Salem, NC, where he performs research in the Organic Electronics Group. His research focuses on interface interactions within organic devices and understanding their impact on film structure and performance. He has been a Graduate Research Fellow of the National Science Foundation since 2012.

Can anyone deny that we’re on the verge of major breakthroughs in the fields of embedded development, microcomputing, wireless communications, and robot design? Tech the Future is a section devoted to the ideas and stories of innovators who are developing the groundbreaking technologies of tomorrow.

Electronics Beyond SiliconBy Jeremy Ward and Oana Jurchescu

Oana Jurchescu, a Wake Forest University physics professor since 2009, is especially interested in organic materials and devices for nano and macroelectronics. She earned her PhD from the from the University of Groningen, The Netherlands. She received the National Science Foundation CAREER award, ORAU Ralph E. Powe Junior Faculty Enhancement award, and the Reid-Doyle Prize for Excellence in Teaching.