Skip to content

ADC Buffer

The ADC buffer is the board's shared landing zone for raw conversions. DMA writes into these arrays, and the rest of the firmware reads them when it is time to update the sensor models.

WARNING

These buffers are shared state. They should be treated as live input, not as stable snapshots, unless the surrounding code has already synchronized on the conversion-complete flags.

What the buffer gives the rest of the board

The board keeps separate storage for ADC1 and ADC2 because the sensor layout is split across multiple analog paths. The conversion-complete flags tell the processing layer when a fresh set of samples is ready.

The rank macros in system_var.h show which sensor slot ends up in which DMA buffer index:

c
#define SENSOR1 200 // Wheel Speed timer
#define SENSOR2 0   // adc1
#define SENSOR3 200 // Wheel Speed timer
#define SENSOR4 1   // adc1
#define SENSOR5 0   // adc2
#define SENSOR6 1   // adc2
#define SENSOR7 2   // adc2
#define SENSOR8 3   // adc2
#define SENSOR9 200 // EXTI
#define SENSOR10 2  // adc1
#define SENSOR11 4  // adc2
#define SENSOR12 5  // adc2

That means the buffer indexes are not arbitrary: when the processing layer reads adc1_buffer[1], it is reading the sensor slot mapped to SENSOR4, and when it reads adc2_buffer[4], it is reading SENSOR11.

How to think about it

This module does not interpret the data. It only holds the latest samples long enough for the processing layer to consume them. That makes it a transport layer for analog data rather than a sensor layer.

c
if (adc1_conversion_complete != 0U && adc2_conversion_complete != 0U)
{
    process_sensor_data();
}

That pattern is the point of the buffer: keep the DMA side simple, then let the processing code decide when the samples are ready to use.

Released under the MIT License.