AN-003 application note

Formatting reference: equations, diagrams and code

Everything this blog can render — LaTeX maths, Mermaid flowcharts, draw.io figures, Obsidian callouts, layouts, task lists and tables, and syntax-highlighted C, C++ and Python.

PUBLISHED ~5 minBY Raghul

This page is both documentation and a test. Write in Obsidian or any editor; everything below is plain Markdown. Links like 4-20ma-receiver-front-end and this one are Obsidian wikilinks, and highlighted text uses Obsidian’s ==mark== syntax.

Equations (LaTeX via KaTeX)

Inline maths sits in single dollars: the cut-off of an RC filter is $f_c = \frac{1}{2\pi RC}$, and a $150,\ohm$ burden gives $V = IR$. Display maths uses double dollars:

$$ H(\j\omega) = \frac{1}{1 + \j\omega RC} \qquad |H| = \frac{1}{\sqrt{1 + (\omega RC)^2}} \tag{1} $$

Aligned derivations and matrices work too:

$$ \begin{aligned} V_{out} &= V_{in},\frac{R_2}{R_1 + R_2} \ &= 3.3,\text{V} \cdot \frac{10,\text{k}\Omega}{20,\text{k}\Omega} = 1.65,\text{V} \end{aligned} \qquad \mathbf{A} = \begin{bmatrix} 1 & T_s \ 0 & 1 \end{bmatrix} $$

Custom macros (defined in astro.config.mjs): \ohm → $\ohm$, \degC → $25\degC$, \dB → $-3\dB$.

Diagrams (Mermaid)

```mermaid
flowchart LR
  ...
```
flowchart LR
  S[Sensor] --> AFE[Analog front-end]
  AFE --> ADC[24-bit ΣΔ ADC]
  ADC --> MCU{{MCU firmware}}
  MCU -->|MQTT| GW[(Gateway)]
  MCU -->|Modbus| PLC[PLC]
sequenceDiagram
  participant App
  participant Boot as Bootloader
  App->>App: download image to slot B
  App->>Boot: set TRIAL, reset
  Boot->>Boot: verify signature
  Boot-->>App: jump to slot B
  App->>Boot: CONFIRMED

Click any diagram or image to zoom.

Figures (draw.io, PNG, SVG, JPG)

Draw in diagrams.net (free, open source), then File → Export as → SVG or PNG with Include a copy of my diagram ticked — the file stays editable in draw.io and displays here like any image. Put it in src/content/attachments/ and embed it Obsidian-style:

![[rc-lowpass.svg|First-order RC low-pass filter]]
First-order RC low-pass filter
First-order RC low-pass filter

Standard Markdown works too: ![alt](../../attachments/board.jpg "Caption"). A number after the pipe sets the width: ![[board.jpg|400]].

Callouts (Obsidian)

Note

Plain information.

Rule of thumb

Put the anti-alias corner at least a decade below the sampling rate.

Check the rail

The op-amp output must stay within its swing at full-scale input.

Mains voltage

Isolate before probing.

Click to expand (foldable)

Callouts with - start closed; with + they start open.

Guideline markings

Put a Before you start panel at the top of any article, project or course by adding setup: to the front-matter. Required items get a red ! badge, optional ones a dashed outline, and install commands get a copy button (see 4-20ma-receiver-front-end for a live example):

setup:
  time: "≈ 2 h"
  difficulty: intermediate
  hardware:
    - { name: "STM32 Nucleo-L476RG", required: true }
    - { name: "Logic analyser", required: false }
  software:
    - { name: "OpenOCD", version: ">= 0.12", required: true, install: "sudo apt install openocd" }
  skills: ["C basics"]

Inside the text, use these callouts (they also render in Obsidian):

Mandatory step

Set the BOOT0 jumper before powering the board, or the bootloader will not start.

You need
  • Toolchain installed and on PATH
  • Board connected over ST-LINK
Environment setup

Install the packages below, then run arm-none-eabi-gcc --version to check.

Things needed

1 × PT100 · 1 × 1 kΩ 0.1 % reference resistor · jumper wires

Tools (click to expand)

Soldering iron, flush cutters, multimeter.

Mains voltage

The power stage is not isolated. Work through an isolation transformer.

Nice to have

A logic analyser makes the SPI lesson much easier.

Mark single words inline with <mark class="req">required</mark> → required or <mark class="opt">optional</mark> → optional.

Install commands per OS — consecutive code blocks with tab="…" become tabs (the reader’s choice is remembered on every page):

sudo apt install gcc-arm-none-eabi openocd
# with Chocolatey (https://chocolatey.org) in an admin PowerShell
choco install gcc-arm-embedded openocd
brew install --cask gcc-arm-embedded && brew install open-ocd

Obsidian formatting

Inline tags such as #firmware and #signal-conditioning link to their tag pages. End a paragraph with ^my-block and link to it with [[formatting-reference#^my-block]].

Layout callouts have no box, they just arrange content:

Left column

> [!columns|2] puts each nested block side by side (stacked on phones).

Right column

Use [!columns|3] for three.

This paragraph is centred with > [!center]. Also [!right], [!left] and [!justify].

Images take options after the pipe, in any order: alignment (left, right, center, wide, small, noborder), a width in pixels, and a caption:

Floated right, 260 px
Floated right, 260 px

![[rc-lowpass.svg|right|260|Floated right, 260 px]] floats the figure so text wraps around it, which suits a schematic next to its explanation. On phones it drops back to full width. Lorem ipsum filler so the wrap is visible: the burden resistor sets both the full-scale voltage and the compliance the transmitter must supply, so choose it from the ADC range first.

Task lists support Obsidian’s extended states:

  • to do
  • done
  • in progress
  • cancelled
  • deferred
  • important
  • question
  • star

Lists nest with distinct markers:

  1. Power stage
    1. Input protection
      1. TVS diode
  2. Sensor front-end
    • Excitation
      • Ratiometric reference

Tables follow GitHub alignment (:--, :-:, --:) and take a caption from a Table: … line directly above or below:

Burden resistor options for a 4–20 mA input
Burden Full scale @ 20 mA Compliance loss Use with
100 Ω 2.0 V low 2.048 V ADC reference
150 Ω 3.0 V medium 3.3 V MCU ADC
250 Ω 5.0 V high 5 V systems, HART

Code

/* Moving-average filter, power-of-two window. */
#define WIN_LOG2 4
static uint32_t acc;
static uint16_t buf[1u << WIN_LOG2];
static uint8_t  idx;

uint16_t ma_update(uint16_t sample)
{
    acc += sample - buf[idx];
    buf[idx] = sample;
    idx = (idx + 1u) & ((1u << WIN_LOG2) - 1u);
    return (uint16_t)(acc >> WIN_LOG2);
}
template <typename T, std::size_t N>
class RingBuffer {
public:
    bool push(const T& v) noexcept {
        if (full()) return false;
        data_[head_++ % N] = v;
        return true;
    }
    [[nodiscard]] bool full() const noexcept { return head_ - tail_ == N; }
private:
    std::array<T, N> data_{};
    std::size_t head_{0}, tail_{0};
};
import numpy as np
from scipy import signal

fs = 1_000                      # Hz
b, a = signal.butter(2, 50, fs=fs)  # 2nd-order 50 Hz low-pass
w, h = signal.freqz(b, a, fs=fs)
print(f"-3 dB at {w[np.argmin(abs(abs(h) - 0.707))]:.1f} Hz")
arm-none-eabi-gcc -mcpu=cortex-m4 -mthumb -O2 -c main.c -o main.o

For circuits, timing diagrams, TikZ, JSXGraph and Cytoscape see circuits-and-interactive-diagrams.

Any language supported by Shiki works: rust, asm, verilog, vhdl, makefile, cmake, yaml, json, diff… Hover a block and press Copy.

Tables

Signal Range Resolution
Loop 4 – 20 mA 4.9 µA
PT100 −50 … 400 °C 0.01 °C
Rate article

Found a mistake? Let me know.

⌁ Comments & reactions

Comments are not configured yet.