Recent Posts

sort by category

My Embedded Toolbox: Source Code Whitespace Cleanup

In this installment of my "Embedded Toolbox" series, I would like to share with you the free source code cleanup utility called QClean for cleaning whitespace in your source files, header files, makefiles, linker scripts, etc. You probably wonder why you might need such a utility? In fact, the common thinking is that compilers (C, C++, etc.) ignore whitespace anyway, so why bother? But, as a professional software developer you should not ignore whitespace, because it can cause all sorts of pr...

EEPROM Wear Leveling

A problem that occurs from time to time is the need for an embedded system to keep track of the number of doodads it has processed since it was put in to service. Clearly you can't keep this value in RAM as it will be lost when power is removed. Thus the obvious solution is to store the count in EEPROM. However, common EEPROM  specifications are 10^5 guaranteed write cycles, with 10^6 typical write cycles. If you expect to process say 20 million doodads during the life of your product you clear...

My Embedded Toolbox: Programmer's Calculator

Like any craftsman, I have accumulated quite a few tools during my embedded software development career. Some of them proved to me more useful than others. And these generally useful tools ended up in my Embedded Toolbox. In this blog, I'd like to share some of my tools with you. Today, I'd like to start with my cross-platform Programmer's Calculator called QCalc. I'm sure that you already have your favorite calculator online or on your smartphone. But can your calculator accept complete ...

Hamming distances

My guess is that most readers of this blog have at least a vague idea of what "Hamming distance" is.  At the most abstract level it is a measure of how different two equal length "strings" are. In the case where the "strings" are actually binary integers, then the the Hamming distance is simply the number of bit positions that differ. Thus if we are comparing 8-bit integers, then the values 0x00 and 0x01 have a Hamming distance of 1, whereas 0xFF and 0x00 have a Hamming distance of 8. So wha...

Real Men [Still] Program in C

It's hard for me to believe, but it's been nearly 8 years since I wrote the popular "Real Men Program in C" blog post (turned article). That post was prompted by a conversation with a couple of younger programmers who told me: "C is too hard for programmers of our generation to bother mastering." I ended then: If you accept [] that C shall remain important for the foreseeable future and that embedded software is of ever-increasing importance, then you’ll begin to see trouble brewing. Altho...

Beyond the RTOS: A Better Way to Design Real-Time Embedded Software

An RTOS (Real-Time Operating System) is the most universally accepted way of designing and implementing embedded software. It is the most sought after component of any system that outgrows the venerable "superloop". But it is also the design strategy that implies a certain programming paradigm, which leads to particularly brittle designs that often work only by chance. I'm talking about sequential programming based on blocking. Blocking occurs any time you wait explicitly in-line for somethin...

2016 Survey of Embedded Systems Design Trends

According to a recent survey, there are "10" types of people in this world: those who understand binary and those who don't. As you are presumably (by nature of being reading this niche blog) one of the former and also experienced in the art of embedded systems design, won't you please participate in a quick online survey regarding trends in our industry: 2016 Embedded Systems Design Trends Survey It should only take you a couple of minutes to complete the short survey, after whic...

Most Popular Embedded Gurus Blog Posts of 2015

Below are the top 10 most read blog posts from the Embedded Gurus in 2015. #1: A Tutorial on Signed and Unsigned Integers #2: Don't Follow These 5 Dangerous Coding Standard Rules #3: Efficient C Tip #13: Use the Modulus (%) Operator with Caution #4: Embedded C Programming with ARM Cortex-M Video Course #5: A Tutorial on Lookup Tables in C #6: What Belongs in a C .h Header File? #7: Cutting Through the Confusion with ARM Cortex-M Interrupt Priorities #8: Computing Your Sta...

Peak detection of a time series

I've been doing embedded work for so long now that it's rare that I come across a need that I haven't run into before. Well, it happened the other day, so I thought I'd share it with you. Here's the situation. I have a transducer whose role is to determine a binary condition (essentially X is present / absent).  The transducer is AC coupled and pass band filtered such that what I'm looking for is the presence of a noisy AC signal. My first inclination was to take the pass-band filtered signa...

Boeing Dreamliner 'Bug'

There's an all too familiar story in the press today. The headline at the Guardian reads "US aviation authority: Boeing 787 bug could cause 'loss of control'. As usual with these kinds of stories, it's light on technical details other than to reveal that the Dreamliner's generators will fall into a fail safe mode if kept continuously powered for 248 days. In this fail-safe mode, the generator doesn't apparently generate power. Thus if all four of the planes generators were powered on at the same...

Everywhere you look these days, it is readily apparent that embedded systems of all types are under attack by hackers. In just one example from the last few weeks, researchers at Kaspersky Lab (a Moscow-headquartered maker of anti-virus and other software security products) published a report documenting a specific pernicious and malicious attack against "virtually all hard drive firmware". The Kaspersky researchers deemed this particular data security attack the "most advanced hacking ope...

Freescale customer service

I have to admit to having a soft spot for Freescale microprocessors. The first micro I ever used was a Motorola 6809 and for the first few years of my career I worked exclusively on 6800's, 68HC11's and 68000 processors.  Times changed and I largely moved away from the product range, although I did return periodically as projects dictated. Well such a project has recently come up. The project requires me to make some modifications to an existing code base and as is often the case, the original ...

Firmalware

There's a fascinating story from Reuters (with a far more detailed report from Kaspersky) about how a very sophisticated hacking operation, presumably the NSA, has been targeting computers by reflashing the firmware of hard drives such that the attacker controls what is loaded at boot time. If you think this has shades of Stuxnet about it, then you aren't alone. Why am I posting this? Well I think in the embedded community there's been a certain amount of nonchalance concerning malware attack...

Shifting Styles

To say it's been some time since I last posted is an understatement! I won't bore you with the details other than to note that sometimes there just aren't enough hours in a day. Anyway, today's post is about a stylistic issue I've noticed in just about all code I've ever looked at. Unless you are a closeted BASIC programmer, you probably don't ever write something like this: foo = foo + 6; While there's nothing particularly wrong with this, other than looking rather odd from a mathematical ...

Fast, Deterministic, and Portable Counting Leading Zeros

Counting leading zeros in an integer number is a critical operation in many DSP algorithms, such as normalization of samples in sound or video processing, as well as in real-time schedulers to quickly find the highest-priority task ready-to-run. In most such algorithms, it is important that the count-leading zeros operation be fast and deterministic. For this reason, many modern processors provide the CLZ (count-leading zeros) instruction, sometimes also called LZCNT, BSF (bit scan forward), ...

First Impressions of Google Glass 2.0

Last week I took advantage of Google's special 1-day-only buying opportunity to purchase an "Explorer" edition of Google Glass 2.0. My package arrived over the weekend and I finally found a few hours this morning for the unboxing and first use. Let me begin by saying that the current price is quite high and that the buying process itself is cumbersome. To buy Google Glass you must shell out \$1,500 (plus taxes and any accessories) and you can only pay this entrance fee via a Google Wallet ac...

The engineering - marketing divide

We have all sat in surreal meetings with the sales and marketing folks. This video captures the dynamic perfectly (caution - you won't know whether to laugh or cry): The Expert Video I actually have some sympathy for the marketing people portrayed here, as it must be very hard when you're so far out of your depth. The person I can't stand is the smarmy sales guy who'll promise anything to make a sale, regardless of the consequences. I have to admit to having chewed out a few sales guys in ...

Replacing nested switches with multi-dimensional arrays of pointers to functions

It's been way too long since I've written a blog post. To those kind souls that have written to inquire if I'm still alive and kicking - thank you.  The bottom line is that there simply aren't enough hours in the day. Anyway in an effort to get back in the groove so to speak, I thought I'd answer an email from Francois Alibert who wrote to ask how to replace a nested switch statement with a multi-dimensional array of pointers to functions. Here's a program that illustrates his conundrum: #incl...

A Look Back at the Audi 5000 and Unintended Acceleration

I was in high school in the late 1980's when NHTSA (pronounced "nit-suh"), Transport Canada, and others studied complaints of unintended acceleration in Audi 5000 vehicles. Looking back on the Audi issues, and in light of my own recent role as an expert investigating complaints of unintended acceleration in Toyota vehicles, there appears to be a fundamental contradiction between the way that Audi's problems are remembered now and what NHTSA had to say officially at the time. Here's an exampl...

Lethal Software Defects: Patriot Missile Failure

During the Gulf War, twenty-eight U.S. soldiers were killed and almost one hundred others were wounded when a nearby Patriot missile defense system failed to properly track a Scud missile launched from Iraq. The cause of the failure was later found to be a programming error in the computer embedded in the Patriot's weapons control system. On February 25, 1991, Iraq successfully launched a Scud missile that hit a U.S. Army barracks near Dhahran, Saudi Arabia. The 28 deaths by that one Scud c...