Skip to content

Oversampling of ADC inputs

lbuild module: modm:driver:adc_sampler

This template class stores 8, 16 or 32bit ADC values in a buffer and provides an easy interface for managing that data.

The code will read the ADC channels you specify in an array. This means you can remap the ADC channels in the order that they should appear in the buffer. The array must obviously have as many elements as channels! For example, if channels 0,2,7 are connected, but the sensors are in the wrong order, just remap them with the array {7,0,2}.

To make use of oversampling and averaging, set Oversamples > 0. This will loop Oversamples times through the ADC channels, adding the average of each result to the buffer.

This class will choose the smallest data width for you. It decides this by adding the ADC resolution and the oversample size and choosing the next smallest size (not larger than 32bit though!).

Warning

The averaging algorithm only works for unsigned ADC data!

Dependencies

modm:driver:adc_sampler modm_driver_adc_sampler modm: driver: adc_sampler modm_architecture_adc modm: architecture: adc modm_driver_adc_sampler->modm_architecture_adc modm_math_utils modm: math: utils modm_driver_adc_sampler->modm_math_utils modm_utils modm: utils modm_driver_adc_sampler->modm_utils