## Lessons Learned from Embedded Code Reviews (Including Some Surprises)

August 16, 20152 comments

My software team recently finished a round of code reviews for some of our motor controller code. I learned a lot from the experience, most notably why you would want to have code reviews in the first place.

My background is originally from the medical device industry. In the United States, software in medical devices gets a lot of scrutiny from the Food and Drug Administration, and for good reason; it’s a place for complexity to hide latent bugs. (Can you say “

## Ten Little Algorithms, Part 4: Topological Sort

July 5, 20151 comment

Other articles in this series:

Today we’re going to take a break from my usual focus on signal processing or numerical algorithms, and focus on...

## Oh Robot My Robot

June 26, 2015

Oh Robot! My Robot! You’ve broken off your nose! Your head is spinning round and round, your eye no longer glows, Each program after program tapped your golden memory, You used to have 12K, now there is none that I can see,  Under smoldering antennae,   Over long forgotten feet,    My sister used your last part:      The chip she tried to eat.

Oh Robot, My Robot, the remote controls—they call, The call—for...

## Important Programming Concepts (Even on Embedded Systems) Part VI : Abstraction

June 16, 20153 comments

Earlier articles:

We have come to the last part of the Important Programming Concepts series, on abstraction. I thought I might also talk about why there isn’t a Part VII, but decided it would distract from this article — so if you want to know the reason, along with what’s next,

## Ten Little Algorithms, Part 3: Welford's Method (and Friends)

May 10, 20156 comments

Other articles in this series:

Last time we talked about a low-pass filter, and we saw that a one-line...

## Python Code from My Articles Now Online in IPython Notebooks

May 1, 20152 comments

Ever since I started using IPython Notebooks to write these articles, I’ve been wanting to publish them in a form such that you can freely use my Python code. One of you (maredsous10) wanted this access as well.

Well, I finally bit the bullet and automated a script that will extract the Python code and create standalone notebooks, that are available publicly under the Apache license on my bitbucket account: https://bitbucket.org/jason_s/embedded-blog-public

This also means they...

## Ten Little Algorithms, Part 2: The Single-Pole Low-Pass Filter

April 27, 201516 comments

Other articles in this series:

I’m writing this article in a room with a bunch of other people talking, and while sometimes I wish they would just SHUT UP, it would be...

## Ten Little Algorithms, Part 1: Russian Peasant Multiplication

March 21, 20156 comments

This blog needs some short posts to balance out the long ones, so I thought I’d cover some of the algorithms I’ve used over the years. Like the Euclidean algorithm and Extended Euclidean algorithm and Newton’s method — except those you should know already, and if not, you should be locked in a room until you do. Someday one of them may save your life. Well, you never know.

Other articles in this series:

• Part 1:

## Two Capacitors Are Better Than One

February 15, 20155 comments

I was looking for a good reference for some ADC-driving circuits, and ran across this diagram in Walt Jung’s Op-Amp Applications Handbook:

And I smiled to myself, because I immediately remembered a circuit I hadn’t used for years. Years! But it’s something you should file away in your bag of tricks.

Take a look at the RC-RC circuit formed by R1, R2, C1, and C2. It’s basically a stacked RC low-pass filter. The question is, why are there two capacitors?

I...

## My Love-Hate Relationship with Stack Overflow: Arthur S., Arthur T., and the Soup Nazi

February 15, 201552 comments

Warning: In the interest of maintaining a coherent stream of consciousness, I’m lowering the setting on my profanity filter for this post. Just wanted to let you know ahead of time.

I’ve been a user of Stack Overflow since December of 2008. And I say “user” both in the software sense, and in the drug-addict sense. I’m Jason S, user #44330, and I’m a programming addict. (Hi, Jason S.) The Gravatar, in case you were wondering, is a screen...

## Important Programming Concepts (Even on Embedded Systems) Part III: Volatility

October 10, 2014

1vol·a·tile adjective \ˈvä-lə-təl, especially British -ˌtī(-ə)l\ : likely to change in a very sudden or extreme way : having or showing extreme or sudden changes of emotion : likely to become dangerous or out of control

Other articles in this series:

## Second-Order Systems, Part I: Boing!!

October 29, 2014

I’ve already written about the unexciting (but useful) 1st-order system, and about slew-rate limiting. So now it’s time to cover second-order systems.

The most common second-order systems are RLC circuits and spring-mass-damper systems.

Spring-mass-damper systems are fairly common; you’ve seen these before, whether you realize it or not. One household example of these is the spring doorstop (BOING!!):

(For what it’s worth: the spring...

## 10 Items of Test Equipment You Should Know

June 22, 20143 comments

When life gets rough and a circuit board is letting you down, it’s time to turn to test equipment. The obvious ones are multimeters and oscilloscopes and power supplies. But you know about those already, right?

Here are some you may not have heard of:

Non-contact current sensors. Oscilloscope probes measure voltage. When you need to measure current, you need a different approach. Especially at high voltages, where maintaining galvanic isolation is important for safety. The usual...

## Someday We’ll Find It, The Kelvin Connection

July 28, 20142 comments

You’d think it wouldn’t be too hard to measure electrical resistance accurately. And it’s really not, at least according to wikiHow.com: you just follow these easy steps:

• Choose the item whose resistance you wish to measure.
• Plug the probes into the correct test sockets.
• Turn on the multimeter.
• Select the best testing range.
• Touch the multimeter probes to the item you wish to measure.
• Set the multimeter to a high voltage range after finishing the...

## Ten Little Algorithms, Part 6: Green’s Theorem and Swept-Area Detection

June 18, 20173 comments

Other articles in this series:

This article is mainly an excuse to scribble down some cryptic-looking mathematics — Don’t panic! Close your eyes and scroll down if you feel nauseous — and...

## How to Include MathJax Equations in SVG With Less Than 100 Lines of JavaScript!

May 23, 20149 comments

Today’s short and tangential note is an account of how I dug myself out of Documentation Despair. I’ve been working on some block diagrams. You know, this sort of thing, to describe feedback control systems:

And I had a problem. How do I draw diagrams like this?

I don’t have Visio and I don’t like Visio. I used to like Visio. But then it got Microsofted.

I can use MATLAB and Simulink, which are great for drawing block diagrams. Normally you use them to create a...

## Jaywalking Around the Compiler

December 9, 20193 comments

Our team had another code review recently. I looked at one of the files, and bolted upright in horror when I saw a function that looked sort of like this:

void some_function(SOMEDATA_T *psomedata) { asm volatile("push CORCON"); CORCON = 0x00E2; do_some_other_stuff(psomedata); asm volatile("pop CORCON"); }

There is a serious bug here — do you see what it is?

## Lost Secrets of the H-Bridge, Part II: Ripple Current in the DC Link Capacitor

July 28, 2013

In my last post, I talked about ripple current in inductive loads.

One of the assumptions we made was that the DC link was, in fact, a DC voltage source. In reality that's an approximation; no DC voltage source is perfect, and current flow will alter the DC link voltage. To analyze this, we need to go back and look at how much current actually is being drawn from the DC link. Below is an example. This is the same kind of graph as last time, except we added two...

## Linear Feedback Shift Registers for the Uninitiated, Part VII: LFSR Implementations, Idiomatic C, and Compiler Explorer

November 13, 2017

The last four articles were on algorithms used to compute with finite fields and shift registers:

Today we’re going to come back down to earth and show how to implement LFSR updates on a microcontroller. We’ll also talk a little bit about something called “idiomatic C” and a neat online tool for experimenting with the C compiler.

## Linear Feedback Shift Registers for the Uninitiated, Part XVIII: Primitive Polynomial Generation

August 6, 20182 comments

Last time we figured out how to reverse-engineer parameters of an unknown CRC computation by providing sample inputs and analyzing the corresponding outputs. One of the things we discovered was that the polynomial $x^{16} + x^{12} + x^5 + 1$ used in the 16-bit X.25 CRC is not primitive — which just means that all the nonzero elements in the corresponding quotient ring can’t be generated by powers of $x$, and therefore the corresponding 16-bit LFSR with taps in bits 0, 5,...