ADC Design for Vibration
ADC Design for Vibration
This multi-chapter example ties together binary, ADC, sampling, and DAC concepts.
Scenario: Design a predictive maintenance system that monitors machine vibration to detect bearing failures.
Requirements:
- Detect vibrations from 10 Hz (normal operation) to 5 kHz (bearing defects)
- Amplitude range: 0.1g to 10g (acceleration)
- Accuracy: ±0.01g to catch early-stage failures
- Output: Visual alert via LED brightness (proportional to vibration level)
Step 1: Sensor and ADC Selection (Chapter 2: ADC Fundamentals)
Accelerometer (ADXL1002, single-axis MEMS vibration sensor) outputs analog voltage: - Sensitivity: about 26 mV/g @ 3.3 V supply (40 mV/g is specified at 5 V) - Range: ±50g → output centered at 1.65V (mid-supply) - Output around 0 g: about 1.65 V; at ±25 g and 3.3 V supply, about 0.99–2.31 V before offsets and tolerances.
To achieve ±0.01g accuracy: - Voltage per 0.01 g at 3.3 V supply ≈ 0.264 mV. - A 10 g span covers ≈264 mV and 1,000 desired 0.01 g increments, but converter bit depth must also cover the larger biased input range. - For an ideal 3.3 V full-scale model, 3.3 V/0.264 mV = 12,500 steps; at least 14 bits are needed for one code per 0.01 g, before noise and accuracy errors.
Decision: A 12-bit ideal 3.3 V converter has 3.3 V / 4096 ≈ 0.806 mV per code, coarser than the ADXL1002’s ≈0.264 mV change per 0.01 g at 3.3 V. The ESP32 ADC’s actual transfer depends on attenuation and calibration; ±0.01 g accuracy is not established without a validated signal chain.
Step 2: Sampling Rate Calculation (Chapter 3: Nyquist Sampling)
Maximum vibration frequency: 5 kHz (bearing defect signature)
For a signal that includes a 5 kHz component, choose f_sample > 2 × f_max. The Nyquist-rate boundary is 2 × 5 kHz = 10 kHz; exactly two samples per cycle can miss a sinusoid depending on phase. - A practical example is 12.5 kHz, 2.5 times the highest retained frequency, with an anti-alias filter designed to suppress frequencies that would fold into the band.
ESP32 sample rate depends on the chip, configuration and software. Measure the actual timing and check the data sheet before accepting 12.5 kHz.
Sampling period = 1 / 12,500 Hz = 80 µs per sample
Step 3: Binary Representation (Chapter 1: Binary Fundamentals)
ESP32 12-bit ADC outputs 0-4095: - For +2.0 g: output ≈ 1.65 V + 2×0.0264 V = 1.7028 V. - An actual ESP32 raw code must be calibrated for its configured attenuation. In a separate ideal 3.3 V/12-bit endpoint model, floor(1.7028/3.3×4095)=2113 = 100001000001₂.
Step 4: PWM Output for LED Alert (Chapter 5: DAC and PWM)
Map the instantaneous absolute acceleration to LED duty with a linear scale: 0 g gives about 10%, 2 g gives 28%, and 10 g gives 100%. This is not a vibration-amplitude estimate. A real vibration alert needs a defined time window and a measured statistic such as RMS or peak amplitude.
For 2.0 g reading (sensor output ≈ 1.7028 V): - Normalized vibration = 2.0g / 10g = 0.2 (20% of full scale) - PWM duty cycle = 10% + (0.2 x 90%) = 28% duty cycle - PWM value (8-bit) = 0.28 x 255 = 71 (send to ledcWrite())
Step 5: Complete Code Implementation
This sketch requires Arduino-ESP32 core 2.x: its LEDC setup and channel-based write calls changed in core 3.x. Choose the matching core or migrate those calls before compiling.
// ESP32 Vibration Monitor -- ADC to PWM LED Alert
#define ACCEL_PIN 34 // ADC1 input
#define LED_PIN 25 // PWM output
#define PWM_CH 0
const float V_BIAS = 1.65f, SENS = 0.0264f; // nominal values at 3.3 V; calibrate
void setup() {
analogReadResolution(12);
analogSetPinAttenuation(ACCEL_PIN, ADC_11db);
ledcSetup(PWM_CH, 5000, 8); // 5 kHz, 8-bit
ledcAttachPin(LED_PIN, PWM_CH);
}
void loop() {
float v = analogReadMilliVolts(ACCEL_PIN) / 1000.0f;
float g = abs((v - V_BIAS) / SENS); // instantaneous absolute acceleration in g
int pwm = constrain((int)(25 + (g / 10.0) * 230), 0, 255);
ledcWrite(PWM_CH, pwm);
delayMicroseconds(80); // 80 us delay plus loop work; measure or timer-control the actual sample rate
}Step 6: Verification Against Requirements
- Frequency range 10 Hz - 5 kHz: 12.5 kHz would be 2.5x the 5 kHz signal frequency (1.25x the 10 kHz Nyquist rate). Achieved: not demonstrated: the sample clock and anti-alias filter need verification, and the ADXL1002’s 5% bandwidth is 4.7 kHz, below the 5 kHz endpoint.
- Amplitude range 0.1g - 10g: ±50g accelerometer range (ADXL1002). Achieved: yes.
- Accuracy ±0.01 g: In an ideal 3.3 V/12-bit model, 0.806 mV per code / 26.4 mV/g ≈ 0.0305 g per code (±0.0153 g at best for midpoint reconstruction). Achieved: no; include sensor and ADC errors in a tested accuracy budget.
- LED output: The example maps instantaneous absolute acceleration to roughly 10–100% duty. It does not yet measure vibration amplitude or establish an alert.
Key Integration Points:
- Binary (Ch1): ADC output is binary number requiring correct interpretation
- ADC (Ch2): nominal 12-bit resolution alone does not establish ±0.01 g accuracy; calibrate and test the full chain.
- Nyquist (Ch3): a measured sample rate above 10 kS/s plus an analog anti-alias filter is needed to capture 5 kHz content without folding higher frequencies into the band.
- PWM (Ch5): LED dimming via PWM provides visual feedback without true DAC
This example demonstrates how all chapters work together in a complete IoT sensing and actuation system!