Hi, I'm Raghul.

Embedded Engineer · Hardware & Firmware

I design sensor front-ends and write the firmware behind them. This is where I keep articles, project logs and a running lab journal, written the way I'd want a datasheet to read.

Signal conditioningfs 1 kHz · fc 25 Hz · Q 0.707
IN: 5 Hz + noise + 180 Hz humOUT: biquad low-passSNR 4.2 dB → 18.2 dB5 Hz -0.0 dB180 Hz -34 dB|H(f)|1 Hz … 1 kHz−3 dB at 25 Hz−40 dB/decadegroup delay ≈ 9 ms(the visible lag)

A 5 Hz sensor signal buried in white noise and 180 Hz mains-harmonic hum, cleaned by a 2nd-order Butterworth biquad, the same five-multiply filter that runs in firmware.

  • The cut-off (25 Hz) sits 5× above the signal, so the signal passes at almost 0 dB while the hum is pushed down by about 34 dB.
  • The inset |H(f)| shows the −3 dB point and the −40 dB/decade roll-off of a 2nd-order filter.
  • Price paid: phase lag. The output trails the input by a few milliseconds, which matters inside a control loop.
Motor vibration analysis1500 rpm · 2.4 mm/s RMS · ISO zone B
accel1500 rpm · 25 Hzlive accelerationspectrum (DFT, 1 Hz bins)1× unbalance2× misalign.3×BPFO bearing−1×+1×050100150200 Hz

An accelerometer on a motor turning at 1500 rpm. The time waveform looks like noise; the spectrum separates every fault by frequency.

  • 1× (25 Hz) = unbalance, 2× = misalignment, 3× = looseness. Each is a multiple of shaft speed.
  • BPFO (107 Hz) is the outer-race bearing defect frequency, from the bearing geometry. Its ±1× sidebands show the defect is modulated by shaft rotation.
  • Overall RMS velocity (mm/s) is graded against the ISO 10816 / 20816 zones A–D.
Predictive maintenanceRUL ≈ 1,200 h · fails at 82 % of rated L10
6205 deep-grooveC 14.8 kN · P 1.6 kN1500 rpmL10 = (C/P)³·10⁶ / (60·n)= 8,800 h ratedrun time 6,000 h≈ 540 M revolutionsalert 2.8 mm/strip 7.1 mm/s (ISO 10816)rated L10nowRUL ≈ 1,200 h0 h10k hvibration velocity RMS vs run hours

A 6205 bearing with a growing outer-race spall. Trending its vibration and fitting a curve gives the remaining useful life (RUL), set against the catalogue L10 rating.

  • L10 = (C/P)³·10⁶/(60·n) hours: the life that 90 % of identical bearings reach under load P at speed n.
  • Real bearings fail early or late. The trend shows this one degrading from about 3,500 h, well before its rating.
  • An exponential fit on the latest data, projected to the ISO trip level, gives the RUL. That is when to plan the replacement.
BMS: state of charge with an EKFSOC error (RMS) · CC 16.5 % · EKF 0.4 %
50%60%70%80%90%- - true SOC— coulomb counting (drifts)— EKF with voltage correction ±2σstarts 15 % wrong → EKF locks on within a minutecell current (A): 2.5 A pulses · 0.8 A · −1 A regen0 … 50 min · 2.5 Ah Li-ion · 1-RC model

A Li-ion cell under pulsed load. Coulomb counting integrates a slightly biased current sensor and drifts. The extended Kalman filter also uses the terminal voltage and stays on the true SOC.

  • Model: OCV(SOC) curve + R0 + one RC pair. The state is [SOC, V_RC]; the EKF linearises the OCV slope at each step.
  • Started 15 % off on purpose. The voltage residual pulls the estimate back within a minute.
  • The shaded band is ±2σ. It narrows as measurements arrive and widens on the flat part of the OCV curve.
IoT condition-monitoring nodenRF71 · Sub-GHz 868 MHz · MQTT
SensorIMU 3-axis+ temperatureMCU nRF71Cortex-M33256 MHzSub-GHz radio868 MHz+14 dBmGatewaySub-GHz → IPEthernet / LTEBrokerMQTT / TLSSPI / I²CSPIRFDashboard · node 0x2A● onlineIMU RMS (mm/s)X2.1Y1.4Z3.2overall RMS trendT 24.6 °CRSSI −92 dBmBatt 87 %uplink 60 sWhy Sub-GHz?· km range· goes through walls· µA sleep: years on one battery· nRF71 runs the app + Wi-Fi/BLE setup

IMU + temperature sensor → nRF71 MCU → Sub-GHz radio (868 MHz) → gateway → MQTT broker → dashboard. The node reports the 3-axis vibration RMS, temperature, RSSI and battery.

  • The node computes RMS locally and sends only a few bytes per minute. Raw samples never leave the board, which is what keeps the battery alive for years.
  • The nRF71 handles the application and Wi-Fi/BLE provisioning. A separate Sub-GHz transceiver provides the long-range link, since the nRF71 has no Sub-GHz radio itself.
  • RSSI and battery % travel with every uplink, so link health and battery life can be monitored too.
PID control loopKc 1.4 · Ti 7 s · Td 0.6 s · IAE 12.5
step ↑step ↓rampholdstep ↓load −30 %- - SP set-point — PV process valueCO controller output (clamped, anti-windup)FOPDT: K 1.5 · τ 8 s · θ 1.5 s

A first-order-plus-dead-time process following set-point steps up and down, a ramp and a hold, then rejecting a 30 % load disturbance.

  • PV (process value) tracks SP (set point). CO (controller output) shows the effort: it spikes on each step, then settles.
  • The derivative is filtered so it does not amplify noise. Integral anti-windup clamps CO at its limits.
  • IAE (integrated absolute error) gives one number for tuning. Lower is better.
Frequency response: anti-alias filterfc 100 Hz · ADC 1000 SPS · 12-bit
Nyquist 500 Hzabove → aliases1 LSB of 12 bits = -72 dB2nd: -28 dB4th: -56 dB−3 dB @ 100 Hz50 Hz signal: -0.02 dB— 4th order — 2nd order Butterworth1101001k10k0-20-40-60-80-100Hz

A low-pass filter in front of a 12-bit ADC sampling at 1 kSPS. Anything above Nyquist (500 Hz) folds back into the band, so the filter must suppress it below 1 LSB.

  • 2nd order: −28 dB at Nyquist, which still aliases well above 1 LSB (−72 dB). 4th order: −56 dB, much better.
  • Real fix: raise the sample rate (oversample) or the filter order until the curve crosses −72 dB before fs/2.
  • The 50 Hz signal of interest loses only a fraction of a dB. The dot traces the 4th-order response.
ADC noise & effective bits16-bit · 16,384 samples of a DC input
±1σcode histogram — the noise is Gaussian327613276832775output codenoise σ1.61 LSBeffective res.15.3 bitnoise-free 6.6σ12.6 bitSNR (FS sine)83.2 dBENOB13.5 bitENOB = (SNR − 1.76)/6.02ideal 16-bit: 98.1 dBto gain bits: shield,filter, average —4× oversample ≈ +1 bit

A constant input sampled 16,384 times. The output codes form a bell curve. Its width, not the datasheet bit count, sets the real resolution.

  • Effective resolution = N − log₂(σ). Noise-free bits = N − log₂(6.6σ): the bits that never flicker.
  • ENOB = (SNR − 1.76)/6.02. With σ ≈ 1.6 LSB, a 16-bit converter delivers an ENOB of about 13.5 bits.
  • Remedies: a clean reference, layout and shielding, an RC anti-alias filter, and averaging. Each 4× oversampling gains about 1 bit.
UART with RTS/CTS handshake115200 baud · 8N1 · RTS/CTS · 8.68 µs/bit
CTSTXRXRTSCTS ← peer ready: TX may startS10000010T'A' = 0x41LSB firstS11010010Treply 'K' 0x4BRTS → I can receive| strobe = sample point, mid-bit (UART oversamples 16× and votes on 3 samples) S start bit · T stop bitidle line = 1 (mark) · start bit pulls it to 0

The MCU sends 'A' (0x41) as an 8N1 frame once the peer asserts CTS, then raises RTS and receives the reply 'K'.

  • Idle line = 1. The start bit pulls it to 0 and starts the receiver's bit clock. Data follows LSB first, then a stop bit (1).
  • No shared clock: each side runs its own baud generator, so the receiver samples at mid-bit and tolerates about ±2 % mismatch.
  • RTS/CTS (active-low pins, drawn here as asserted = high) stop overruns when the receiver's buffer is full.
Firmware snippet
USART1->BRR  = SystemCoreClock / 115200;        // 8N1 at 115200 baud
USART1->CR3 |= USART_CR3_RTSE | USART_CR3_CTSE;  // hardware flow control
USART1->CR1 |= USART_CR1_TE | USART_CR1_RE | USART_CR1_UE;
while (!(USART1->ISR & USART_ISR_TXE)) {}        // waits while CTS is not asserted
USART1->TDR = 'A';                               // start, 1000 0010, stop
while (!(USART1->ISR & USART_ISR_RXNE)) {}       // wait for the reply
char ack = USART1->RDR;                          // 'K'
CAN 2.0A frame & bit timingID 0x123 · DLC 2 · 500 kbit/s · 61 bits incl. 1 stuff
ID 0x123DLC 2DATA DE ADCRC 0B6EEOFHLdominant 0: CAN_H 3.5 V / CAN_L 1.5 V · recessive 1: both 2.5 V▮ stuff bit after 5 equal bits · ACK slot pulled to 0 by every receiverone bit = 16 time quanta = 2 µs at 500 kbit/sSPROP 5 tqPHASE_SEG1 8 tqPS2 2 tqsample point 87.5 %SJW 2 tq: nodes resync on each recessive → dominant edge;lowest ID wins arbitration — 0x123 beats 0x200 without collision

A standard frame, ID 0x123 with two data bytes, drawn bit by bit: the real CRC-15, the inserted stuff bits and the differential CAN_H / CAN_L levels.

  • Dominant 0 overrides recessive 1, so the lowest ID wins arbitration without destroying either frame.
  • After five equal bits a stuff bit is inserted. This keeps edges coming so every node can resynchronise.
  • Each bit is split into 16 time quanta; sampling at 87.5 % leaves room for propagation delay on long buses.
Firmware snippet
CAN_TxHeaderTypeDef h = { .StdId = 0x123, .IDE = CAN_ID_STD,
                          .RTR = CAN_RTR_DATA, .DLC = 2 };
uint8_t data[2] = { 0xDE, 0xAD };  uint32_t mbox;
HAL_CAN_Start(&hcan1);                          // 500 kbit/s, sample point 87.5 %
HAL_CAN_AddTxMessage(&hcan1, &h, data, &mbox);  // CRC + stuffing done in hardware
// Linux SocketCAN:  ip link set can0 up type can bitrate 500000 sample-point 0.875
//                   cansend can0 123#DEAD   ·   candump can0

Recent articles

  1. AN-004
    Circuit diagrams, timing charts and interactive maths

    CircuiTikZ schematics, WaveDrom timing and register maps, live CircuitJS simulations, KiCad viewers, JSXGraph plots and Cytoscape networks — all from plain Markdown.

  2. AN-003
    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.

  3. AN-002
    Designing a 4–20 mA receiver front-end for a 12-bit ADC

    Burden resistor sizing, protection, filtering and scaling — a loop receiver that survives wiring mistakes in the field.

  4. AN-001
    Dual-bank bootloader: notes on a fail-safe update path

    How an A/B image layout, a tiny boot-state record and a watchdog give you firmware updates that can't brick a device.

From the journal

  1. JR-002
    ESD hit on the loop input

    TVS clamped it, but the ADC reading drifted 0.3 % afterwards. Suspect the series resistor.

  2. JR-001
    Power-cut test on the A/B bootloader

    500 random power cuts during update. Zero bricks, two rollbacks — exactly as designed.

Full journal →

On the bench

prototype

PT100 to 4–20 mA head-mount transmitter

Ratiometric 3-wire RTD measurement with lead-wire compensation and a loop-powered output stage.

  • #signal conditioning
  • #4-20mA
  • #analog
  • KiCad
  • C
  • Analog

All projects →

Courses

Embedded C for sensor interfacing5 lessons · 1 h 43 min
in progressintermediate

Embedded C for sensor interfacing

From an ADC reading to calibrated, filtered engineering units on a Cortex-M MCU — with real hardware in every lesson.

  • Odysee
  • #firmware
  • #signal conditioning
  • #course

All courses →