Project 5: Sensor Truth - ADC Calibration and Noise Study
Calibrate Teensy ADC readings, measure noise, and build a repeatable analog measurement pipeline.
Quick Reference
| Attribute | Value |
|---|---|
| Difficulty | Level 2: Intermediate |
| Time Estimate | 10-15 hours |
| Main Programming Language | C++ |
| Alternative Programming Languages | C, Python (for analysis) |
| Coolness Level | Level 3: Genuinely Clever |
| Business Potential | 2. The “Component” Business |
| Prerequisites | C/C++ basics, Teensyduino setup, basic electronics, ability to use a multimeter/logic analyzer |
| Key Topics | ADC, sampling, noise, calibration |
1. Learning Objectives
By completing this project, you will:
- Explain the core question for this project in your own words.
- Implement the main workflow and validate it with measurements.
- Handle at least two failure modes and document recovery.
- Produce a deterministic report that matches hardware behavior.
2. All Theory Needed (Per-Concept Breakdown)
ADC Sampling, Calibration, and Noise
Fundamentals An ADC converts a voltage into a digital code by sampling and quantizing. Accuracy depends on reference voltage, sampling time, and input impedance. Noise comes from sensors, power rails, and the ADC itself. Calibration maps raw counts into real units and is required for repeatable measurements.
Deep Dive into the concept The i.MX RT1062 ADC is a SAR converter that uses a sample-and-hold capacitor. If the sensor has high impedance, the capacitor does not fully charge and readings skew low. The reference voltage defines full scale; any noise or drift on the reference directly changes results. Decoupling and external references can improve stability. Quantization creates an unavoidable error because voltage is represented in discrete steps. Oversampling and averaging reduce noise but trade bandwidth for stability. Calibration uses known voltages to estimate offset and gain, then applies correction to all readings. This is essential for absolute accuracy. A measurement pipeline should include raw sampling, filtering, calibration, and logging. Raw data reveals noise distribution, filtered data reveals stability, and calibration ensures correct units. This project uses logging and analysis to prove the quality of your analog pipeline.
How this fit on projects This concept directly powers the implementation choices and validation steps in this project.
Definitions & key terms
- SAR ADC: Successive Approximation Register ADC that converges on a value.
- Quantization: Mapping a continuous voltage to discrete steps.
- Reference voltage: Voltage that defines full-scale ADC range.
- Oversampling: Sampling faster than required to reduce noise via averaging.
Mental model diagram (ASCII)
Sensor -> Sample/Hold -> ADC -> Counts -> Calibration -> Units
How it works (step-by-step)
- Measure a known voltage and record raw counts.
- Compute offset and gain correction.
- Sample a sensor repeatedly and log noise distribution.
- Apply filtering and re-measure noise.
Minimal concrete example
int raw = analogRead(A0);
float volts = (raw * 3.3f) / 4095.0f;
Common misconceptions
- ADC readings are exact if you use float math.
- Noise is always from the sensor.
- Averaging never changes signal meaning.
Check-your-understanding questions
- Why does input impedance matter for ADC accuracy?
- How does oversampling trade bandwidth for noise reduction?
- What is the effect of reference drift?
Check-your-understanding answers
- The sample capacitor needs time to charge through the source impedance.
- More samples reduce variance but reduce time resolution.
- Any drift scales all measurements, causing systematic error.
Real-world applications
- Sensor calibration
- Battery measurement
- Precision instrumentation
Where you’ll apply it
- See §3.2 Functional Requirements and §5.10 Implementation Phases in this file.
- Also used in: P12-power-budgeter-battery-life-and-low-power-modes.md, P16-teensy-data-logger-sd-card-sensor-archive.md
References
- NXP i.MX RT ADC chapter
- Analog Devices ADC fundamentals
Key insights
ADC accuracy is an analog system problem, not just a software problem.
Summary
You can only trust analog data after you measure noise and calibrate conversion.
Homework/Exercises to practice the concept
- Record 1000 samples of a stable reference and compute mean/stddev.
- Compare raw vs averaged readings and plot noise reduction.
Solutions to the homework/exercises
- Use a fixed reference and log to CSV, then compute statistics in Python.
- Average N samples and compare standard deviation before and after.
3. Project Specification
3.1 What You Will Build
Calibrate Teensy ADC readings, measure noise, and build a repeatable analog measurement pipeline.
3.2 Functional Requirements
- Measure ADC noise with a stable reference.
- Compute calibration offset/gain.
- Apply filtering and compare noise reduction.
- Export calibration report.
3.3 Non-Functional Requirements
- Performance: Meet the target timing/throughput for the project.
- Reliability: Detect errors and recover without undefined behavior.
- Usability: Provide clear logs and a repeatable workflow.
3.4 Example Usage / Output
./P05-sensor-truth-adc-calibration-and-noise-study --run
3.5 Data Formats / Schemas / Protocols
CSV with columns: sample_id, raw_count, volts, mode
3.6 Edge Cases
- High source impedance
- Noisy power rail
- ADC saturation near rails
3.7 Real World Outcome
You will run the project and see deterministic logs and measurements that match physical hardware behavior.
3.7.1 How to Run (Copy/Paste)
cd project-root
make
./P05-sensor-truth-adc-calibration-and-noise-study --run
3.7.2 Golden Path Demo (Deterministic)
Use a fixed input configuration and a known test signal. Capture output for 60 seconds and verify it matches expected values.
3.7.3 If CLI: exact terminal transcript
$ ./P05-sensor-truth-adc-calibration-and-noise-study --run --seed 42
[INFO] Sensor Truth - ADC Calibration and Noise Study starting
[INFO] Report saved to data/report.csv
[INFO] Status: OK
$ echo $?
0
Failure Demo (Deterministic)
$ ./P05-sensor-truth-adc-calibration-and-noise-study --run --missing-device
[ERROR] Device not detected
$ echo $?
2
4. Solution Architecture
4.1 High-Level Design
Inputs -> Acquisition -> Processing -> Output/Log
4.2 Key Components
| Component | Responsibility | Key Decisions |
|---|---|---|
| Acquisition | Configure peripherals and capture data | Use stable clock settings |
| Processing | Convert raw data to meaningful values | Apply calibration/filters |
| Output/Log | Emit reports and logs | CSV for reproducibility |
4.3 Data Structures (No Full Code)
struct Sample {
uint32_t timestamp_us;
uint32_t value;
uint32_t flags;
};
4.4 Algorithm Overview
Key Algorithm: Measurement + Report
- Initialize hardware and verify configuration.
- Capture data and record timestamps.
- Compute metrics and write report.
Complexity Analysis:
- Time: O(n) in samples
- Space: O(n) for log storage
5. Implementation Guide
5.1 Development Environment Setup
# Arduino IDE + Teensyduino must be installed
# Optional CLI workflow
arduino-cli core update-index
arduino-cli core install teensy:avr
5.2 Project Structure
project-root/
├── src/
│ ├── main.ino
│ ├── hw_config.h
│ └── measurements.cpp
├── tools/
│ └── analyze.py
├── data/
│ └── samples.csv
└── README.md
5.3 The Core Question You’re Answering
“How accurate are my analog readings, and how do I prove it?”
5.4 Concepts You Must Understand First
Stop and research these before coding:
- ADC, sampling, noise, calibration
- Data logging and measurement techniques
- Basic timing math and error analysis
5.5 Questions to Guide Your Design
- Which reference voltage will you trust?
- How many samples are enough for stable statistics?
- Which filter is best for your data?
5.6 Thinking Exercise
Estimate expected ADC LSB size and compare to observed noise.
5.7 The Interview Questions They’ll Ask
- What is quantization error?
- Why does source impedance matter?
- How does oversampling improve resolution?
5.8 Hints in Layers
- Use a stable reference regulator.
- Log raw samples before filtering.
- Plot histograms to see noise distribution.
5.9 Books That Will Help
| Topic | Book | Chapter | |——-|——|———| | ADC basics | Arduino Workshop | Ch. 10 | | Embedded measurement | Making Embedded Systems | Ch. 6 | | Signal processing | The Scientist and Engineer’s Guide to DSP | Ch. 1-4 |
5.10 Implementation Phases
Phase 1: Foundation (4 hours)
Goals:
- Collect raw ADC data
- Compute LSB size
Tasks:
- Collect raw ADC data
- Compute LSB size
Checkpoint: Raw noise captured
Phase 2: Core Functionality (6 hours)
Goals:
- Implement calibration
- Apply filtering
Tasks:
- Implement calibration
- Apply filtering
Checkpoint: Calibrated readings
Phase 3: Polish (3 hours)
Goals:
- Analyze histograms
- Document accuracy
Tasks:
- Analyze histograms
- Document accuracy
Checkpoint: Final calibration report
5.11 Key Implementation Decisions
| Decision | Options | Recommendation | Rationale | |———-|———|—————-|———–| | Buffering | Single buffer, double buffer | Double buffer | Avoids data loss during processing | | Logging format | CSV, binary | CSV | Human-readable while still scriptable | | Clock speed | Default, overclock | Default | Keeps peripherals in spec |
6. Testing Strategy
6.1 Test Categories
| Category | Purpose | Examples | |———-|———|———-| | Unit Tests | Validate math, parsing, and conversions | Timer math, CRC checks | | Integration Tests | Verify peripherals and pipelines | DMA -> buffer -> log | | Edge Case Tests | Handle boundary conditions | Brownout, missing sensor |
6.2 Critical Test Cases
{test_cases}
6.3 Test Data
Use a fixed test input pattern and record outputs to data/report.csv
7. Common Pitfalls & Debugging
7.1 Frequent Mistakes
| Pitfall | Symptom | Solution | |———|———|———-| {pitfalls}
7.2 Debugging Strategies
{debug_strats}
7.3 Performance Traps
Large buffers improve stability but increase latency. Measure both throughput and jitter to choose the right size.
8. Extensions & Challenges
8.1 Beginner Extensions
{ex_begin}
8.2 Intermediate Extensions
{ex_inter}
8.3 Advanced Extensions
{ex_adv}
9. Real-World Connections
9.1 Industry Applications
{industry_apps}
9.2 Related Open Source Projects
{open_source}
9.3 Interview Relevance
{interview_rel}
10. Resources
10.1 Essential Reading
{resources}
10.2 Video Resources
- Embedded systems timing walkthrough (YouTube)
- Teensy hardware deep dive (Conference talk)
10.3 Tools & Documentation
- Teensyduino: Toolchain for Teensy boards
- Logic Analyzer: Timing verification
- Multimeter: Voltage and current measurement
10.4 Related Projects in This Series
{related_projects}
11. Self-Assessment Checklist
11.1 Understanding
- I can explain the main concept without notes.
- I can explain why the measurements match (or do not match) expectations.
- I understand at least one tradeoff made in this project.
11.2 Implementation
- All functional requirements are met.
- All critical test cases pass.
- Logs and reports are reproducible.
- Edge cases are handled.
11.3 Growth
- I documented lessons learned.
- I can explain this project in a job interview.
- I identified one improvement for next iteration.
12. Submission / Completion Criteria
Minimum Viable Completion: {comp_min}
Full Completion: {comp_full}
Excellence (Going Above & Beyond): {comp_ex}