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

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

- multiplicative inverse
- discrete logarithm
- determining characteristic polynomial from the LFSR output

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.

## Lazy Properties in Python Using Descriptors

This is a bit of a side tangent from my normal at-least-vaguely-embedded-related articles, but I wanted to share a moment of enlightenment I had recently about descriptors in Python. The easiest way to explain a descriptor is a way to outsource attribute lookup and modification.

Python has a bunch of “magic” methods that are hooks into various object-oriented mechanisms that let you do all sorts of ridiculously clever things. Whether or not they’re a good idea is another...

## Android for Embedded Devices - 5 Reasons why Android is used in Embedded Devices

The embedded purists are going to hate me for this. How can you even think of using Android on an embedded system ? It’s after all a mobile phone operating system/software.

Sigh !! Yes I did not like Android to begin with, as well - for use on an Embedded System. But sometimes I think the market and needs decide what has to be used and what should not be. This is one such thing. Over the past few years, I have learned to love Android as an embedded operating system....

## Linear Feedback Shift Registers for the Uninitiated, Part VI: Sing Along with the Berlekamp-Massey Algorithm

The last two articles were on discrete logarithms in finite fields — in practical terms, how to take the state \( S \) of an LFSR and its characteristic polynomial \( p(x) \) and figure out how many shift steps are required to go from the state 000...001 to \( S \). If we consider \( S \) as a polynomial bit vector such that \( S = x^k \bmod p(x) \), then this is equivalent to the task of figuring out \( k \) from \( S \) and \( p(x) \).

This time we’re tackling something...

## Linear Feedback Shift Registers for the Uninitiated, Part V: Difficult Discrete Logarithms and Pollard's Kangaroo Method

Last time we talked about discrete logarithms which are easy when the group in question has an order which is a smooth number, namely the product of small prime factors. Just as a reminder, the goal here is to find \( k \) if you are given some finite multiplicative group (or a finite field, since it has a multiplicative group) with elements \( y \) and \( g \), and you know you can express \( y = g^k \) for some unknown integer \( k \). The value \( k \) is the discrete logarithm of \( y \)...

## Introduction to Deep Insight Analysis for RTOS Based Applications

Over the past several years, embedded systems have become extremely complex. As systems become more complex, they become harder and more time consuming to debug. It isn’t uncommon for development teams to spend more than 40% development cycle time just debugging their systems. This is where deep insight analysis has the potential to dramatically decrease costs and time to market.

Defining Deep Insight Analysis

Deep insight analysis is a set of tools and techniques that can be...

## Linear Feedback Shift Registers for the Uninitiated, Part IV: Easy Discrete Logarithms and the Silver-Pohlig-Hellman Algorithm

Last time we talked about the multiplicative inverse in finite fields, which is rather boring and mundane, and has an easy solution with Blankinship’s algorithm.

Discrete logarithms, on the other hand, are much more interesting, and this article covers only the tip of the iceberg.

What is a Discrete Logarithm, Anyway?Regular logarithms are something that you’re probably familiar with: let’s say you have some number \( y = b^x \) and you know \( y \) and \( b \) but...

## Linear Feedback Shift Registers for the Uninitiated, Part III: Multiplicative Inverse, and Blankinship's Algorithm

Last time we talked about basic arithmetic operations in the finite field \( GF(2)[x]/p(x) \) — addition, multiplication, raising to a power, shift-left and shift-right — as well as how to determine whether a polynomial \( p(x) \) is primitive. If a polynomial \( p(x) \) is primitive, it can be used to define an LFSR with coefficients that correspond to the 1 terms in \( p(x) \), that has maximal length of \( 2^N-1 \), covering all bit patterns except the all-zero...

## Continuous Integration for Embedded Systems

It is no secret that anyone who wants to streamline project management, reduce risk and improve the quality needs some form of "automation" in SW development processes. What is commonly used in most companies as a tool for such automation is called Continuous Integration (CI). It is a good practice for embedded systems as well even though it is much harder to use CI for embedded systems compared to pure software development because embedded systems mostly depend on...

## Finally got a drone!

As a reader of my blog, you already know that I have been making videos lately and thoroughly enjoying the process. When I was in Germany early this summer (and went 280 km/h in a porsche!) to produce SEGGER's 25th anniversary video, the company bought a drone so we could get an aerial shot of the party (at about the 1:35 mark in this video). Since then, I have been obsessing on buying a drone for myself and finally made the move a few weeks ago - I acquired a used DJI...

## Wye Delta Tee Pi: Observations on Three-Terminal Networks

Today I’m going to talk a little bit about three-terminal linear passive networks. These generally come in two flavors, wye and delta.

Why Wye?The town of Why, Arizona has a strange name that comes from the shape of the original road junction of Arizona State Highways 85 and 86, which was shaped like the letter Y. This is no longer the case, because the state highway department reconfigured the intersection

## Byte and Switch (Part 1)

Imagine for a minute you have an electromagnet, and a microcontroller, and you want to use the microcontroller to turn the electromagnet on and off. Sounds pretty typical, right?We ask this question on our interviews of entry-level electrical engineers: what do you put between the microcontroller and the electromagnet?We used to think this kind of question was too easy, but there are a surprising number of subtleties here (and maybe a surprising number of job candidates that were missing...

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

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...

## 10 Circuit Components You Should Know

Chefs have their miscellaneous ingredients, like condensed milk, cream of tartar, and xanthan gum. As engineers, we too have quite our pick of circuits, and a good circuit designer should know what's out there. Not just the bread and butter ingredients like resistors, capacitors, op-amps, and comparators, but the miscellaneous "gadget" components as well.

Here are ten circuit components you may not have heard of, but which are occasionally quite useful.

1. Multifunction gate (

## Lost Secrets of the H-Bridge, Part I: Ripple Current in Inductive Loads

So you think you know about H-bridges? They're something I mentioned in my last post about signal processing with Python.

Here we have a typical H-bridge with an inductive load. (Mmmmm ahhh! It's good to draw by hand every once in a while!) There are four power switches: QAH and QAL connecting node A to the DC link, and QBH and QBL connecting node B to the DC link. The load is connected between nodes A and B, and here is represented by an inductive load in series with something else. We...

## An overview of Linux Boot Process for Embedded Systems

This Text provides an insight in to the Embedded Linux Boot Process. Reader should have a basic Knowledge of Boot Process in general and should be familiar with Embedded Linux Boot Process.

.................PART-A................(1) Software components Involved in Embedded Linux Boot Process (a) Bootloader (b) kernel Image (c) root file system - either an initrd image or a NFS location(2) Steps during Booting process of a conventional...## Introduction to Microcontrollers - More On GPIO

Now that we have our LED Blinky program nailed down, it's time to look more closely at outputs, add button/switch inputs, and work with reading inputs and driving outputs based on those inputs.

It's ON - No, It's OFF - No, It's ON...I have to confess, I cheated. Well, let's say I glossed over something very important. In our LED Blinky program, we never cared about whether an output '1' or an output '0' turned on the LED. Since we were just...

## Introduction to Microcontrollers - More On Interrupts

A Little More Detail About The Interrupt MechanismIt's time to look a little closer at what happens in an interrupt request and response. Again this is in general terms, and different microcontroller designs may do things somewhat differently, but the basics remain the same. Most but not all interrupt requests are latched, which means the interrupt event sets a flag that stays set even if the interrupt event then goes away. It is this latched flag...

## Free Goodies from Embedded World - What to Do Next?

I told you I would go on a hunt for free stuff at Embedded World in order to build a bundle for someone to win.

## Lost Secrets of the H-Bridge, Part III: Practical Issues of Inductor and Capacitor Ripple Current

We've been analyzing the ripple current in an H-bridge, both in an inductive load and the DC link capacitor. Here's a really quick recap; if you want to get into more details, go back and read part I and part II until you've got equations coming out of your ears. I promise there will be a lot less grungy math in this post. So let's get most of it out of the way:

Switches QAH and QAL are being turned on and off with pulse-width modulation (PWM), to produce an average voltage DaVdc on...

## Introduction to Microcontrollers - Button Matrix & Auto Repeating

Too Many Buttons, Not Enough InputsAssigning one GPIO input to each button can use up a lot of GPIO pins. Numeric input requires at least 10 buttons, plus however many additional control or function buttons. This can quickly get expensive, GPIO pin-wise, and also connector-wise if the keypad is off the uC PCB as it often would be. A very common response to this expense is to wire buttons (keys, etc) in a matrix. By connecting our buttons in an...

## Byte and Switch (Part 2)

In part 1 we talked about the use of a MOSFET for a power switch. Here's a different circuit that also uses a MOSFET, this time as a switch for signals:

We have a thermistor Rth that is located somewhere in an assembly, that connects to a circuit board. This acts as a variable resistor that changes with temperature. If we use it in a voltage divider, the midpoint of the voltage divider has a voltage that depends on temperature. Resistors R3 and R4 form our reference resistance; when...

## VHDL tutorial - A practical example - part 1 - Hardware

In previous posts I described some simple VHDL examples. This time let's try something a little more complex. This is part one of a multiple part article. This is intended to be a detailed description of one of several initial designs that I developed for a client. This design never made it into a product, but a similar design was used and is currently being produced. As a considerable amount of work was put into this effort, I decided to share this design...

## Ten Little Algorithms, Part 4: Topological Sort

Other articles in this series:

- Part 1: Russian Peasant Multiplication
- Part 2: The Single-Pole Low-Pass Filter
- Part 3: Welford's Method (And Friends)
- Part 5: Quadratic Extremum Interpolation and Chandrupatla's Method
- Part 6: Green’s Theorem and Swept-Area Detection

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

## Round Round Get Around: Why Fixed-Point Right-Shifts Are Just Fine

Today’s topic is rounding in embedded systems, or more specifically, why you don’t need to worry about it in many cases.

One of the issues faced in computer arithmetic is that exact arithmetic requires an ever-increasing bit length to avoid overflow. Adding or subtracting two 16-bit integers produces a 17-bit result; multiplying two 16-bit integers produces a 32-bit result. In fixed-point arithmetic we typically multiply and shift right; for example, if we wanted to multiply some...

## Important Programming Concepts (Even on Embedded Systems) Part II: Immutability

Other articles in this series:

- Part I: Idempotence
- Part III: Volatility
- Part IV: Singletons
- Part V: State Machines
- Part VI: Abstraction

This article will discuss immutability, and some of its variations in the topic of functional programming.

There are a whole series of benefits to using program variables that… well, that aren’t actually variable, but instead are immutable. The impact of...

## From bare-metal to RTOS: 5 Reasons to use an RTOS

Developers can come up with amazing and convoluted reasons to not use an RTOS. I have heard excuses ranging from they are too expensive (despite open source solutions) all the way to they aren’t efficient and use too much memory. In some circumstances some excuses are justified but there are many reasons why a developer should look to an RTOS to help with their real-time scheduling needs.

From bare-metal to RTOS Quick Links## Another 10 Circuit Components You Should Know

It's that time again to review all the oddball goodies available in electronic components. These are things you should have in your bag of tricks when you need to design a circuit board. If you read my previous posts and were looking forward to more, this article's for you!

1. Bus switches

I can't believe I haven't mentioned bus switches before. What is a bus switch?

There are lots of different options for switches:

- mechanical switch / relay: All purpose, two...

## The Least Interesting Circuit in the World

It does nothing, most of the time.

It cannot compute pi. It won’t oscillate. It doesn’t light up.

Often it makes other circuits stop working.

It is… the least interesting circuit in the world.

What is it?

About 25 years ago, I took a digital computer architecture course, and we were each given use of an ugly briefcase containing a bunch of solderless breadboards and a power supply and switches and LEDs — and a bunch of

## C Programming Techniques: Function Call Inlining

IntroductionAbstraction is a key to manage software systems as they increase in size and complexity. As shown in a previous post, abstraction requires a developper to clearly define a software interface for both data and functions, and eventually hide the underlying implementation.When using the C language, the interface is often exposed in a header '.h' file, while the implementation is put in one or more corresponding '.c' files.

First, separating an interface from its...