NOTES¶
Producer-Consumer — Ring Buffer Decouples Acquisition from Processing
Default architecture. The Producer writes samples to a ring buffer; the Consumer reads and processes them periodically. When acquisition outruns processing, data queues up.
Intuition¶
Ring Buffer = Bicycle Chain¶
You (Producer) keep hanging items on the chain. Someone else (Consumer) takes items off to process. The chain is the ring buffer.
Key points:
- Producer never stops — even if Consumer hasn't finished the last batch
- Consumer wakes periodically (default 50 ms) and processes the N most recent samples
- If Consumer falls behind, new data overwrites old data (Producer never blocks)
Buffer Size Trade-off¶
Larger buffer → more history → better burst tolerance → more memory
Smaller buffer → less memory → drops data faster when consumer lags
Default: 512 samples × 28 bytes = ~14 KB. Reasonable on ESP32-S3.
Data Flow¶
Producer task (high priority)
each tick: read ADXL355 → write ring buffer
─────────────────
Consumer task (every 50 ms)
read last N samples → threshold detection → feature extraction → output
Notes¶
When to use Producer-Consumer
Default is safe. Change only if you need sub-50 ms processing intervals.
Consumer processing time must be < fill time
If Consumer takes longer than Producer takes to fill the buffer, samples drop continuously. Fix: - Reduce CONSUMER_PROCESS_SAMPLE_COUNT - Switch to DMA + Dual Core architecture