Embedded Notes

Key notes from The Art of Designing Embedded Systems.

Partition projects into as many small, independent pieces as possible to maximize efficiency and reliability. This can mean adding subprocessors to handle smaller tasks.

More people on a team is not better. Higher performing coders perform better on smaller, not larger, tasks.

Code inspections and careful design are more reliable than testing and debugging. Specs are key.
Design with the aid of high level goals, objectives, assumptions (“contracts”) for each function, such as this parameter must not be zero, the result must be smaller than x, this peripheral must be enabled, etc.

Real time tasks must finish before some deadline. Instrument the code with I/O’s that can be measured on an oscilloscope to see margin. Higher loaded processors imply significantly higher effort.

Interrupts and asynchronous code are very dangerous. Hardware based interrupts are typically asynchronous. All code must be re-entrant, where all used data including hardware manipulations are “atomic”, meaning the operation cannot be interrupted and modified by other code.

Be aware of EMI and SI.

Debounce switches in HW or SW. HW debounce requires Schmitt trigger input logic. SW debounce should poll and make sure x number of consecutive values are equal (shift register). For “instant” response to user input, react within 50 to 100 ms.

Developers are most effective when not interrupted, above even experience or skill level.

Use a version control system, use a firmware design standard, do code inspections, create quiet environment for thinking, measure bug and production rates, constantly try to study and improve.

Wave Impedance

Any material has a wave impedance for propagating electromagnetic waves.
This impedance relates the electric and magnetic field magnitudes.

$$\eta = \frac{E}{H}$$

Notice the similarity to Ohm’s law:
$$Z = \frac{V}{I}$$

For a general material:
$$\eta = \sqrt{\frac{j\omega\mu}{\sigma+j\omega\epsilon}} \hspace{5 mm}\Omega$$

Special Cases

The impedance formula simplifies for several special cases described below.

Free space

Free space is primarily air or vacuum. Any lossless dielectric with a dielectric close to 1 can be considered free space.
$$
\epsilon = \epsilon_0=8.854\times 10^{-12} \hspace{5 mm}F/m\\
\mu = \mu_0=4\pi\times 10^{-7} \hspace{5 mm}H/m\\
\sigma = 0\\
\eta = \sqrt{\frac{\mu_0}{\epsilon_0}} = 377 \hspace{5 mm}\Omega
$$

Lossless Dielectric

Any dielectric with low loss, such as teflon, glass, etc.
$$
\epsilon = \epsilon_r\epsilon_0\\
\mu = \mu_r\mu_0\\
\sigma = 0\\
\eta = \sqrt{\frac{\mu_r\mu_0}{\epsilon_r\epsilon_0}} = 377\sqrt{\frac{\mu_r}{\epsilon_r}} \hspace{5 mm}\Omega
$$

Conductor

Any good conductor, primarily metallic materials.
$$
\mu = \mu_r\mu_0\\
\sigma \gg \omega\epsilon\\
\eta = \sqrt{\frac{\omega\mu_r\mu_0}{\sigma}}\angle{-45^{\circ}} \hspace{5 mm}\Omega
$$

Inductance of Loops

These equations are from Inductance: Loop and Partial — Clayton R Paul.

Note that the inductance is fairly similar for either square or circular loops for a given length of wire (circumference/perimeter).

Inductance of a circular loop:

\(L_{circular} = \mu_0a(\ln{\frac{8a}{r_w}}-2)\)

with:
a = radius of loop
r_w = radius of wire
(assumed a >> r_w)

For a 22 AWG wire:
1 cm = 45 nH (wire length 6.3 cm)
10 cm = 740 nH (wire length 63 cm)
100 cm = 10 uH (wire length 630 cm)

Inductance of a square loop:

\(L_{square} = 2\frac{\mu_0}{\pi}l(\ln{\frac{l}{r_w}}-0.774)\)

with:
l = length of side
r_w = radius of wire
(assumed l >> r_w)

For a 22 AWG wire:
1 cm = 22 nH (wire length 4 cm)
10 cm = 400 nH (wire length 40 cm)
100 cm = 6 uH (wire length 400 cm)

Inductance of a rectangular loop:

\(L_{rectangle} = \frac{\mu_0}{\pi}[-l\ln(1+\sqrt{1+(\frac{w}{l})^2})
-w\ln(1+\sqrt{1+(\frac{l}{w})^2})
+l\ln\frac{2w}{r_w}+w\ln\frac{2l}{2w}
+2\sqrt{l^2+w^2} -2w -2l]\)

Parasitic Elements

All conductors always have resistance, inductance and capacitance. As a circuit designer it is important to know how large these so-called parasitics are and when they are significant.

In general parasitics become more important with increasing frequency.
All parasitics end up being proportional to length therefore as a general rule conductors should be kept as short as possible. This typically means that wires and cables are the first to show parasitics.

Continue reading “Parasitic Elements”

Impedance

Capacitors and inductors begin to have influence on circuit behaviour as soon as there is non-zero frequency, which includes switched DC.

Using the Laplace transform and complex math (i.e. imaginary numbers) one can combine resistors, capacitors and inductors into a single quantity called impedance.

Impedance is made up of resistance (R) and reactance (X), where capacitors and inductors are called reactive components. Note that resistance is mathematically real while reactance is imaginary.
\(Z(f) = R(f) + jX(f)\)

Alternatively, this can be written in exponential form:
\(Z(s) = |Z|e^{j\theta}\)

The magnitude of Z is given as:
\(|Z| = \sqrt{R^2 + X^2}\)
And the angle as:
\(\theta = \arctan{\frac{X}{R}}\)

Reactance

For a capacitor the reactance is :
\(X_C(f) = -\frac{1}{2\pi fC}\)
And for an inductor:
\(X_L(f) = 2\pi fL\)

When in exponential form, capacitors have an angle of -90° and inductors +90°.

Series Combinations

Two element series circuits are very straightforward, just adding the two terms together.
RC circuit:
\(Z_{RC}(f) = R – j\frac{1}{2\pi fC}\)
RL circuit:
\(Z_{RL}(f) = R + j2\pi fL\)

An RLC circuit is a bit more complicated:
\(Z_{RLC} = R + j2\pi f – j\frac{1}{2\pi fC} = R -j\frac{1 + (2\pi f)^2LC}{2\pi fC}\)

Transmission Line Introduction


In reality nothing happens instantaneously, no matter how fast it appears to be.
When it comes to electronics, all signals are electromagnetic waves and they travel at the speed of light.
The wiring, circuit board material, or whatever the medium it is, affects the speed of light.
Wire or conductor structures that guide these waves are called transmission lines.
Continue reading “Transmission Line Introduction”

Voltage Regulators

A voltage regulator is a device or circuit that maintains a constant output voltage. It’s typical job is to convert from one voltage to another. Other common usages are to stabilize a variable supply, such as a battery which discharges over time, or to provide a noise-free supply to a sensitive subcircuit.

Voltage regulators are a good study of an electronic system because they have many identifiable and relatively simple functional blocks.

Continue reading “Voltage Regulators”

Current Division


Analogous to voltage dividers is the current divider.

When there are parallel branches in a circuit they all share the same voltage by definition. The resulting current depends on the ratio of the resistances.

The common saying that current takes the path of least resistance is a misnomer.
Current actually takes all paths simultaneously, with inverse proportion to the branch resistance. It’s definitely not as easy to say!
A saying that would be true would be to say that current takes the path of zero resistance, if zero resistance existed.

Analysis

Parallel branches share a common voltage. In a resistive circuit therefore each branch will carry current:
$$I_n = \frac{V}{R_n}$$
The total current will then be:
$$I = I_1 + … + I_n = \frac{V}{R_1} + … + \frac{V}{R_n}$$
$$I = \frac{V}{R_{parallel}} + \frac{V}{R_k}$$

Each branch can then be written as:
$$I_k = I \frac{1}{1 + \frac{R_k}{R_{parallel}}}$$

Small-signal Approximation


The majority of electronic systems are too complex for convenient hand analysis and of the the most common tools for simplification is the small-signal approximation.

In general, electronic components are non-linear and very quickly become tedious to work with.
In fact, many common terms such as gain or output impedance rely on the small-signal approximation.

Taylor’s Theorem

From calculus we have Taylor’s theorem that lets us approximate almost any function as a sum of terms, near a specific point.
f(x) near x= a can be approximated as:
$$f(x) = f(a) + \frac{df(a)}{dx}(x – a) + \frac{1}{2!}\frac{d^2f(a)}{dx^2}(x – a)^2 + \frac{1}{3!}\frac{d^3f(a)}{3! dx^3}(x – a)^3 + …$$

The individual terms are called first order, second order etc. based on the power of x.

This is a very powerful approximation that is used very frequently but rarely explicitly mentioned.

Operating Point

The first step to the approximation is to define the operating point. In a typical transistor circuit design, this would be the DC bias point.

If f(x) is a transfer function then ‘a’ is the input and f(a) is the output.

This is also frequently called the bias point, or steady state solution.

Gain

The gain, A, of a circuit is the linear multiplication term relating the output to input:
$$v_o(t) = Av_i(t)$$

In general gain varies with the operating point and intuitively it is equal to:
$$A(a) = \frac{df(a)}{dx}$$

This is of course the first-order term from Taylor’s theorem.

Distortion

The typical amplifier or receiver is designed to be linear, therefore the gain is the only desirable term.

The second and third order terms then represent unwanted non-linear distortion.
Typically the second and third order terms are the dominant distortion products and rarely are higher order terms discussed.

A large amount of effort is spent in analog design to minimize these distortion terms.

Small-Signal

Each term in the Taylor expansion has an 1/k!(x-a)^k term. When x is near a, each higher order term is less and less significant. For example:
$$0.9 > 0.9^2 > 0.9^3 …$$

When this assumption is true, we can say it is a small-signal and can calculate the transfer function using just the linear terms.

Typically, electronic circuits are analyzed using the small-signal assumption, with the higher-order effects added in afterwards if required.