Overview
The ADC driver allows you to manage an Analog to Digital peripheral via simple and portable APIs. This driver supports sampling and converting raw values into microvolts.
Usage
This documentation provides a basic usage summary and a set of examples in the form of commented code fragments. Detailed descriptions of the APIs are provided in subsequent sections.
Synopsis
#define THERMOCOUPLE_OUT 0
Examples
Opening an ADC instance
if (adc == NULL) {
while (1) {}
}
Taking an ADC sample
An ADC conversion with an ADC peripheral is started by calling ADC_convert(). The result value is returned by ADC_convert() once the conversion is finished.
int_fast16_t res;
uint_fast16_t adcValue;
{
print(adcValue);
}
Converting a sample to microvolts
The result value returned by ADC_convert() is a raw value. The following uses ADC_convertToMicroVolts() to convert the raw value into microvolts.
int_fast16_t res;
uint_fast16_t adcValue;
uint32_t adcValueUv;
{
}
Executing multi-channel sampling
ADC_convertChain() provides an optimized way to perform ADC conversions for several ADC instances. It takes a list of identically configured ADC instances and returns a buffer with the corresponding result values once the conversion is finished. One typical use-case would be reading a group of sensors that share the sampling duration.
Should the configuration of the ADC instances differ, the configuration of the first instance in the list is used to set the parameters of the entire conversion chain.
int_fast16_t res;
uint16_t retValues[ADC_COUNT];
uint8_t i;
{
for (i = 0; i < ADC_COUNT; i++) {
print(retValues[i]);
}
}
§ ADC_convertRawToMicroVolts
§ ADC_Config
§ ADC_close()
Function to close an ADC driver instance.
- Precondition
- ADC_open() has to be called first.
- Parameters
-
§ ADC_control()
int_fast16_t ADC_control |
( |
ADC_Handle |
handle, |
|
|
uint_fast16_t |
cmd, |
|
|
void * |
arg |
|
) |
| |
Function performs implementation specific features on a driver instance.
- Precondition
- ADC_open() has to be called first.
- Parameters
-
[in] | handle | An ADC_Handle returned from ADC_open() |
[in] | cmd | A command value defined by the device specific implementation |
[in] | arg | An optional R/W (read/write) argument that is accompanied with cmd |
- Returns
- Implementation specific return codes. Negative values indicate unsuccessful operations.
- Return values
-
§ ADC_convert()
int_fast16_t ADC_convert |
( |
ADC_Handle |
handle, |
|
|
uint16_t * |
value |
|
) |
| |
Function to perform an ADC conversion.
Function to perform a single channel sample conversion.
- Precondition
- ADC_open() has been called
- Parameters
-
[in] | handle | An ADC_Handle returned from ADC_open() |
[in,out] | value | A pointer to a uint16_t to store the conversion result |
- Return values
-
- See also
- ADC_convertToMicroVolts()
§ ADC_convertChain()
int_fast16_t ADC_convertChain |
( |
ADC_Handle * |
handleList, |
|
|
uint16_t * |
dataBuffer, |
|
|
uint8_t |
channelCount |
|
) |
| |
Function to perform a multi-channel ADC conversion.
Function to perform a multi-channel sample conversion.
- Precondition
- ADC_open() has been called
- Parameters
-
[in] | handleList | A list of ADC_Handle which have returned from ADC_open() |
[in,out] | dataBuffer | A pointer to a uint16_t data buffer to store the conversion result |
[in] | channelCount | The number of channels that make up the list of ADC_Handle |
- Return values
-
- See also
- ADC_convert()
§ ADC_convertToMicroVolts()
uint32_t ADC_convertToMicroVolts |
( |
ADC_Handle |
handle, |
|
|
uint16_t |
adcValue |
|
) |
| |
Function to convert a raw ADC sample into microvolts.
- Precondition
- ADC_convert() has to be called first.
- Parameters
-
- Returns
adcValue
converted into microvolts
- See also
- ADC_convert()
§ ADC_init()
Function to initialize the ADC driver.
This function must also be called before any other ADC driver APIs.
§ ADC_open()
Function to initialize the ADC peripheral.
Function to initialize the ADC peripheral specified by the particular index value.
- Precondition
- ADC_init() has been called
- Parameters
-
[in] | index | Index in the ADC_Config [] array. |
[in] | params | Pointer to an initialized ADC_Params structure. If NULL, the default ADC_Params values are used. |
- Returns
- An ADC_Handle on success or NULL on error.
- See also
- ADC_init()
-
ADC_close()
§ ADC_Params_init()
Initialize an ADC_Params structure to its default values.
- Parameters
-
Default values are:
§ ADCMSPM0_fxnTable
ADC function table pointer