MSPM0L11XX_L13XX TI-Driver Library  2.01.00.03
Modules | Data Structures | Macros | Typedefs | Functions | Variables
Analog to Digital Conversion (ADC)
Collaboration diagram for Analog to Digital Conversion (ADC):

Modules

 ADC_control command and status codes
 

Data Structures

struct  ADC_Params
 ADC Parameters used with ADC_open(). More...
 
struct  ADC_FxnTable
 The definition of an ADC function table that contains the required set of functions to control a specific ADC driver implementation. More...
 
struct  ADC_Config_
 ADC driver's custom configuration structure. More...
 

Macros

#define ADC_convertRawToMicroVolts   ADC_convertToMicroVolts
 

Typedefs

typedef struct ADC_Config_ADC_Handle
 A handle that is returned from an ADC_open() call.
 
typedef struct ADC_Config_ ADC_Config
 ADC driver's custom configuration structure. More...
 

Functions

void ADC_close (ADC_Handle handle)
 Function to close an ADC driver instance. More...
 
int_fast16_t ADC_control (ADC_Handle handle, uint_fast16_t cmd, void *arg)
 Function performs implementation specific features on a driver instance. More...
 
int_fast16_t ADC_convert (ADC_Handle handle, uint16_t *value)
 Function to perform an ADC conversion. More...
 
int_fast16_t ADC_convertChain (ADC_Handle *handleList, uint16_t *dataBuffer, uint8_t channelCount)
 Function to perform a multi-channel ADC conversion. More...
 
uint32_t ADC_convertToMicroVolts (ADC_Handle handle, uint16_t adcValue)
 Function to convert a raw ADC sample into microvolts. More...
 
void ADC_init (void)
 Function to initialize the ADC driver. More...
 
ADC_Handle ADC_open (uint_least8_t index, ADC_Params *params)
 Function to initialize the ADC peripheral. More...
 
void ADC_Params_init (ADC_Params *params)
 Initialize an ADC_Params structure to its default values. More...
 

Variables

const ADC_FxnTable ADCMSPM0_fxnTable
 

Detailed Description

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

// Import ADC Driver definitions
#include <ti/drivers/ADC.h>
// Define name for ADC channel index
#define THERMOCOUPLE_OUT 0
// One-time init of ADC driver
// initialize optional ADC parameters
ADC_Params params;
ADC_Params_init(&params);
params.isProtected = true;
// Open ADC channels for usage
ADC_Handle adcHandle = ADC_open(THERMOCOUPLE_OUT, &params);
// Sample the analog output from the Thermocouple
ADC_convert(adcHandle, &result);
// Convert the sample to microvolts
resultUv = ADC_convertToMicroVolts(adcHandle, result);
ADC_close(adcHandle);

Examples

Opening an ADC instance

ADC_Params params;
ADC_Params_init(&params);
adc = ADC_open(0, &params);
if (adc == NULL) {
// ADC_open() failed
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;
res = ADC_convert(adc, &adcValue);
if (res == ADC_STATUS_SUCCESS)
{
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;
res = ADC_convert(adc, &adcValue);
if (res == ADC_STATUS_SUCCESS)
{
adcValueUv = ADC_convertToMicroVolts(adc, adcValue);
}

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.

ADC_Handle adc[ADC_COUNT];
int_fast16_t res;
uint16_t retValues[ADC_COUNT];
uint8_t i;
res = ADC_convertChain(adc, retValues, ADC_COUNT);
if (res == ADC_STATUS_SUCCESS)
{
for (i = 0; i < ADC_COUNT; i++) {
print(retValues[i]);
}
}

Macro Definition Documentation

§ ADC_convertRawToMicroVolts

#define ADC_convertRawToMicroVolts   ADC_convertToMicroVolts

Typedef Documentation

§ ADC_Config

typedef struct ADC_Config_ ADC_Config

ADC driver's custom configuration structure.

See also
ADC_init()
ADC_open()

Function Documentation

§ ADC_close()

void ADC_close ( ADC_Handle  handle)

Function to close an ADC driver instance.

Precondition
ADC_open() has to be called first.
Parameters
[in]handleAn ADC_Handle returned from ADC_open()

§ 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]handleAn ADC_Handle returned from ADC_open()
[in]cmdA command value defined by the device specific implementation
[in]argAn optional R/W (read/write) argument that is accompanied with cmd
Returns
Implementation specific return codes. Negative values indicate unsuccessful operations.
Return values
ADC_STATUS_SUCCESSThe call was successful.
ADC_STATUS_UNDEFINEDCMDThe cmd value is not supported by the device specific implementation.

§ 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]handleAn ADC_Handle returned from ADC_open()
[in,out]valueA pointer to a uint16_t to store the conversion result
Return values
ADC_STATUS_SUCCESSThe conversion was successful.
ADC_STATUS_ERRORThe conversion failed and value is invalid.
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]handleListA list of ADC_Handle which have returned from ADC_open()
[in,out]dataBufferA pointer to a uint16_t data buffer to store the conversion result
[in]channelCountThe number of channels that make up the list of ADC_Handle
Return values
ADC_STATUS_SUCCESSThe conversion was successful.
ADC_STATUS_ERRORThe conversion failed and value is invalid.
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
[in]handleAn ADC_Handle returned from ADC_open()
[in]adcValueA sampling result return from ADC_convert()
Returns
adcValue converted into microvolts
See also
ADC_convert()

§ ADC_init()

void ADC_init ( void  )

Function to initialize the ADC driver.

This function must also be called before any other ADC driver APIs.

§ ADC_open()

ADC_Handle ADC_open ( uint_least8_t  index,
ADC_Params params 
)

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]indexIndex in the ADC_Config[] array.
[in]paramsPointer 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()

void ADC_Params_init ( ADC_Params params)

Initialize an ADC_Params structure to its default values.

Parameters
[in]paramsA pointer to an ADC_Params structure.

Default values are:

Variable Documentation

§ ADCMSPM0_fxnTable

const ADC_FxnTable ADCMSPM0_fxnTable

ADC function table pointer

© Copyright 1995-2024, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale