Analog data conversion utilities

Utility functions for converting analog data samples. More...

Detailed Description

Utility functions for converting analog data samples.

Files

file  analog_util.h
 Analog utility function interfaces.
 

Functions

int adc_util_map (int sample, adc_res_t res, int min, int max)
 Map a sampled ADC value to a given range. More...
 
float adc_util_mapf (int sample, adc_res_t res, float min, float max)
 Map a sampled ADC value to a given range (using floating point arithmetics) More...
 
uint16_t dac_util_map (int value, int min, int max)
 Map a value out of the given range to a 16-bit unsigned int. More...
 
uint16_t dac_util_mapf (float value, float min, float max)
 Helper function to map a given float value range to a valid DAC value. More...
 

Function Documentation

◆ adc_util_map()

int adc_util_map ( int  sample,
adc_res_t  res,
int  min,
int  max 
)

Map a sampled ADC value to a given range.

This function is useful for converting sampled ADC values into their physical representation.

The min value is asserted to be smaller than the max value.

Parameters
[in]samplesampled ADC value
[in]resADC resolution
[in]minthe lower bound of the target interval
[in]maxthe upper bound of the target interval
Returns
the mapped value

◆ adc_util_mapf()

float adc_util_mapf ( int  sample,
adc_res_t  res,
float  min,
float  max 
)

Map a sampled ADC value to a given range (using floating point arithmetics)

See also
adc_util_map
Parameters
[in]samplesampled ADC value
[in]resADC resolution
[in]minthe lower bound of the target interval
[in]maxthe upper bound of the target interval
Returns
the mapped value

◆ dac_util_map()

uint16_t dac_util_map ( int  value,
int  min,
int  max 
)

Map a value out of the given range to a 16-bit unsigned int.

The min value is assumed to be smaller than max value and value is assumed to be between min and max.

Parameters
[in]valuevalue to map to a DAC set value
[in]minthe lower bound of the source interval
[in]maxthe upper bound of the source interval
Returns
the mapped value

◆ dac_util_mapf()

uint16_t dac_util_mapf ( float  value,
float  min,
float  max 
)

Helper function to map a given float value range to a valid DAC value.

See also
dac_util_map
Parameters
[in]valuevalue to map to a DAC set value
[in]minthe lower bound of the source interval
[in]maxthe upper bound of the source interval
Returns
the mapped value