ADC Interface

ADC Platform interface

ADC Overview

An Analog-to-Digital Converter (ADC) is an essential component in electronics that converts analog signals (continuous signals) into digital data (discrete signals) that microcontrollers or digital systems can process. Below is an overview of ADCs, their purpose, types, and key parameters

Application Interface

The below table captures the functions that are to be called from the application layer.

API Functions

Function

Description

rs_adc_init

To open adc unit

rs_adc_configure_channel

To configures the ADC channel

rs_adc_start_channel

To starts the conversion for the given channel

rs_adc_stop_channel

To stops the conversion for the given channel

rs_adc_register_completion_callback

callback function is called on completion of given activity

rs_adc_deinit

To close the adc unit

Error Code

  • Every API’s for the ADC returns some success or failure values. Please refer below section,

Implementation Guide

  • Initialize the ADC unit

  • Configure the ADC channel under the unit

  • Register the callback function

  • Start the ADC conversion

  • Callback gets called.

  • Stop the conversion once work is done

  • Un-Initialize the ADC unit

Documentation from the relevant header as follows:

Defines

RS_ADC_CONVERSION_MODE_ONE_SHOT

Do it once as needed

RS_ADC_CONVERSION_MODE_CONTINUOUS

Convert continously

RS_ADC_CONVERSION_MODE_MULTI_CYCLES

Convert given number of cycles

RS_ADC_OPERATION_MODE_BLOCKING

Blocking Mode operation

RS_ADC_OPERATION_MODE_NON_BLOCKING

Non-Blocking Mode operation

RS_ADC_RESOLUTION_8_BIT

8 bit resolution

RS_ADC_RESOLUTION_10_BIT

10 bit resolution

RS_ADC_RESOLUTION_12_BIT

12 bit resolution

RS_ADC_RESOLUTION_16_BIT

16 bit resolution

RS_ADC_DATA_ALIGNMENT_LEFT

Result aligned to left

RS_ADC_DATA_ALIGNMENT_RIGHT

Result aligned to right

RS_ADC_TRIGGER_SOFTWARE

Conversion triggered by software

RS_ADC_TRIGGER_HARDWARE

Conversion triggered by hardware

Typedefs

typedef struct __rs_adc_channel_config rs_adc_channel_config_t

Structure for setting up each ADC Channel configuration

typedef struct __rs_adc_config rs_adc_config_t

Structure for setting up each ADC Unit configuration

typedef void (*rs_adc_callback_completion)(rs_handle_t handle, rs_ret_val_t result, uint32_t u32_channel, void *ptr_value)

Callback function format.

This callback function is called on completion of given activity

Param handle:

[in] - Handle to the ADC unit

Param result:

[in] - Result of the last operation requested in non-blocking mode

Param u32_channel:

[in] - Channel for whiche the result is for

Param ptr_value:

[in] - Conversion result storage buffer as provided in the configuration structure

Return:

None

Functions

rs_handle_t rs_adc_init(rs_adc_config_t *ptr_config)

Configures the ADC Unit.

This function configures/reconfigures the ADC Unit as per the given configuration

Parameters:

ptr_config[in] - Pointer to the configuration structure

Returns:

0 on success or error code on failure

rs_ret_val_t rs_adc_configure_channel(rs_handle_t handle, rs_adc_channel_config_t *ptr_config)

Configures the ADC channel.

This function configures/reconfigures the channel as per the given configuration

Parameters:
  • handle[in] - Handle to the ADC unit

  • ptr_config[in] - Pointer to the configuration structure

Returns:

0 on success or error code on failure

rs_ret_val_t rs_adc_start_channel(rs_handle_t handle, uint32_t u32_channel)

Starts the conversion for the given channel.

This function intitiates the conversion operation for the given ADC channel

Parameters:
  • handle[in] - Handle to the ADC unit

  • u32_channel[in] - Channel number

Returns:

0 on success or error code on failure

rs_ret_val_t rs_adc_stop_channel(rs_handle_t handle, uint32_t u32_channel)

Stops the conversion for the given channel.

This function stops the conversion operation for the given ADC channel

Parameters:
  • handle[in] - Handle to the ADC unit

  • u32_channel[in] - Channel number

Returns:

0 on success or error code on failure

rs_ret_val_t rs_adc_register_completion_callback(rs_handle_t handle, rs_adc_callback_completion ptr_func)

Registers the given callback function for completion of ADC conversion operation.

This function registers the given callback function for completion of conversion operation

Parameters:
  • handle[in] - Handle to the ADC unit

  • ptr_func[in] - Callback function to call to

Returns:

0 on success or error code on failure

rs_ret_val_t rs_adc_deinit(rs_handle_t handle)

Uninitializes the ADC Unit.

This function un-initializes the ADC Unit and releases the handle

Parameters:

handle[in] - Handle to the ADC Unit

Returns:

0 on success or error code on failure

struct __rs_adc_channel_config
#include <rs_adc.h>

Structure for setting up each ADC Channel configuration

Public Members

uint8_t unit_index

Index to ADC unit as defined by underlying HAL layer

uint8_t channel

Channel number inside the unit, Starting from 0 index

uint8_t group

Grouping of channel, if supported

uint8_t trigger

Trigger source

struct __rs_adc_config
#include <rs_adc.h>

Structure for setting up each ADC Unit configuration

Public Members

uint8_t unit

Index to ADC Unit

uint8_t conversion_mode

Operation mode - One-shot, continuous etc

uint8_t oper_mode

Operation mode - One-shot, continuous etc

uint8_t resolution

Conversion resolution

uint8_t alignment

Data alignement

uint8_t trigger

Trigger source

uint8_t average_count

Number of samples to be averaged

uint16_t sampling_freq

Sampling frequency

void *ptr_result

Buffer to store the results