Data Structures | Macros | Typedefs | Functions
ADC.h File Reference

Detailed Description

Analog to Digital Conversion (ADC) Input Driver.


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);
}

Configuration

Refer to the Driver's Configuration section for driver configuration information.


#include <stdbool.h>
#include <stdint.h>
Include dependency graph for ADC.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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
 
#define ADC_CMD_RESERVED
 
#define ADC_STATUS_RESERVED
 
#define ADC_STATUS_SUCCESS   (0)
 Successful status code returned by ADC_control(). More...
 
#define ADC_STATUS_ERROR   (-1)
 Generic error status code returned by ADC_control(). More...
 
#define ADC_STATUS_UNDEFINEDCMD   (-2)
 An error status code returned by ADC_control() for undefined command codes. More...
 

Typedefs

typedef struct ADC_Config_ADC_Handle
 A handle that is returned from an ADC_open() call. More...
 
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...
 
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...
 

Macro Definition Documentation

§ ADC_convertRawToMicroVolts

#define ADC_convertRawToMicroVolts   ADC_convertToMicroVolts

Typedef Documentation

§ ADC_Handle

typedef struct ADC_Config_* ADC_Handle

A handle that is returned from an ADC_open() call.

§ 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_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:

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