ADC

The ADC driver provides API to configure the ADC module. Below are the high level features supported by the ADC driver.

Features Supported

  • Configuration of parameters: mode, open delay etc

  • Configuration of FIFO threshold levels

  • Configuration of range of data for the ADC conversion result

  • Generation of interrupt when the the conversion result exceeds the range

  • Programmable averaging of input samples. The number of samples taken for averaging can be configured

  • Support for getting the number of words present in the FIFO and also reading the FIFO data

  • Support for enabling/disabling various interrupts

  • Get ADC interrupt status register to determine the source of interrupt

SysConfig Features

It is strongly recommend to use SysConfig where it is available instead of using direct SW API calls. This will help simplify the SW application and also catch common mistakes early in the development cycle.

  • Selection of input channels.

  • Selection of ADC source clock

Features NOT Supported

  • Big Endian

Important Usage Guidelines

  • Global initialization of surrounding modules must be done after a device reset (Please refer TRM)

  • A minimum wait for 4 us is required before starting a conversion to provide time for AFE to power up. The user needs to ensure this.

Example Usage

Include the below file to access the APIs

#include <drivers/adc.h>

Initialize ADC

    /* Use internal calibration */
    uint32_t errOffset = 1;
    /* Starts internal calibration */
    uint32_t calibration = 1;

    ADC_init(adcBaseAddr, TRUE, errOffset, calibration);

Get FIFO threshold level

    /* Get threshold level for FIFO 0 */
    uint32_t level = ADC_getCPUFIFOThresholdLevel(adcBaseAddr, ADC_FIFO_NUM_0);

    DebugP_log("Number of words after which interrupt to CPU will be generated for FIFO0 is : %i\r\n", level);

Check if ADC is powered up or not

    /* Check if ADC is powered up or not */
    uint32_t status = Adc_isPoweredUp(adcBaseAddr);

    if(TRUE == status)
    {
        DebugP_log("ADC is powered up\r\n");
    }

    else
    {
        DebugP_log("ADC is not powered up\r\n");
    }

API

group APIs for ADC

This module contains APIs to program and use the ADC module.

ADC Fifo Num

typedef uint32_t adcChannel_t

Enum to select the channel for input.

typedef uint32_t adcFIFONum_t

Enum to select FIFO to store the data.

ADC_CHANNEL_1

Select channel 1 for input

ADC_CHANNEL_2

Select channel 2 for input

ADC_CHANNEL_3

Select channel 3 for input

ADC_CHANNEL_4

Select channel 4 for input

ADC_CHANNEL_5

Select channel 5 for input

ADC_CHANNEL_6

Select channel 6 for input

ADC_CHANNEL_7

Select channel 7 for input

ADC_CHANNEL_8

Select channel 8 for input

ADC_FIFO_NUM_0

Select FIFO 0 to store data

ADC_FIFO_NUM_1

Select FIFO 1 to store data

ADC Step Id

typedef uint32_t adcStepId_t

Enum to select the step for operation.

ADC_STEP_1

Select step 1

ADC_STEP_2

Select step 2

ADC_STEP_3

Select step 3

ADC_STEP_4

Select step 4

ADC_STEP_5

Select step 5

ADC_STEP_6

Select step 6

ADC_STEP_7

Select step 7

ADC_STEP_8

Select step 8

ADC_STEP_9

Select step 9

ADC_STEP_10

Select step 10

ADC_STEP_11

Select step 11

ADC_STEP_12

Select step 12

ADC_STEP_13

Select step 13

ADC_STEP_14

Select step 14

ADC_STEP_15

Select step 15

ADC_STEP_16

Select step 16

ADC Operation Mode

typedef uint32_t adcOperationMode_t

Enum to select the ADC Operation Mode.

    ADC can either operate in software enabled single shot mode or
    software enabled continuous mode.
ADC_OPERATION_MODE_SINGLE_SHOT

Configure ADC operation mode to software enabled single shot

ADC_OPERATION_MODE_CONTINUOUS

Configure ADC operation mode to software enabled continuous

ADC Averaging

typedef uint32_t adcAveraging_t

Enum to number of samplings to average.

    ADC allows user to program the number of samplings to average.
ADC_AVERAGING_NONE

Disable averaging

ADC_AVERAGING_2_SAMPLES

Set number of samplings to average to 2

ADC_AVERAGING_4_SAMPLES

Set number of samplings to average to 4

ADC_AVERAGING_8_SAMPLES

Set number of samplings to average to 8

ADC_AVERAGING_16_SAMPLES

Set number of samplings to average to 16

ADC Interrupt source

typedef uint32_t adcIntrSrc_t

Enum for ADC interrupts.

ADC_INTR_SRC_END_OF_SEQUENCE

End of sequence interrupt

ADC_INTR_SRC_FIFO0_THRESHOLD

FIFO0 threshold interrupt

ADC_INTR_SRC_FIFO0_OVERRUN

FIFO0 overrun interrupt

ADC_INTR_SRC_FIFO0_UNDERFLOW

FIFO0 underrun interrupt

ADC_INTR_SRC_FIFO1_THRESHOLD

FIFO1 threshold interrupt

ADC_INTR_SRC_FIFO1_OVERRUN

FIFO1 overrun interrupt

ADC_INTR_SRC_FIFO1_UNDERFLOW

FIFO1 underrun interrupt

ADC_INTR_SRC_OUT_OF_RANGE

Out of interrupt

ADC Idle mode

typedef uint32_t adcIdleMode_t

Enum to configure ADC idle mode.Applicable for TDA3XX Only.

ADC_IDLE_MODE_FORCE_IDLE

Force idle mode

ADC_IDLE_MODE_NO_IDLE

No idle mode

ADC_IDLE_MODE_SMART_IDLE

Smart idle mode

Defines

ADC_INTR_STATUS_ALL

Macro defines mask for all the interrupts status for ADC.

ADC_INTR_ENABLE_ALL

Macro defines mask for all the interrupts to enable for ADC.

ADC_INTR_DISABLE_ALL

Macro defines mask for all the interrupts to disable for ADC.

ADC_INTR_ALL

Macro defines mask for all the interrupts for ADC.

ADC_OPENDELAY_MAX

Macro defines the maximum value of open delay for a step for ADC.

ADC_SAMPLEDELAY_MAX

Macro defines the maximum value of sample delay for a step for ADC.

ADC_RANGE_MAX

Macro defines the maximum allowable range for ADC.

ADC_RANGE_MIN

Macro defines the minimum allowable range for ADC.

ADC_FIFO_SIZE

Macro defines the maximum number of samples FIFO0 can store.

ADC_GET_RANGE(bit)

Returns the ADC max range given the bit support.

Functions

void ADC_powerUp(uint32_t baseAddr, uint32_t powerUp)

This API will power up ADC Module.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • powerUp – ADC is powered up if it is TRUE. ADC is powered down if it is FALSE.

uint32_t Adc_isPoweredUp(uint32_t baseAddr)

This function checks if the ADC module is powered up.

Parameters:

baseAddr – Base Address of the ADC Registers.

Return values:

state – Returns TRUE if ADC is powered up. Else returns FALSE.

int32_t ADC_setClkDivider(uint32_t baseAddr, uint32_t clkDivider)

This API will configure clock divider for the ADC Module.

Note

Actual value programmed is (clkDivider - 1) to get the divider value as clkDivider. This API is applicable only for TDA3XX.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • clkDivider – Clock divider value.

Returns:

status Configuration status.

void ADC_init(uint32_t baseAddr, uint32_t errCorrection, uint32_t errOffset, uint32_t calibration)

This API is used to initialize the ADC module.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • errCorrection – Error Correction is enabled if it is TRUE. Error Correction is disabled if it is FALSE.

  • errOffset – Write 0 to use internal calibration. Write 1 to use EFUSE code.

  • calibration – Writing 0 does not start internal calibration. Writing 1 starts internal calibration.

void ADC_FIFODMAAccessEnable(uint32_t baseAddr, uint32_t fifoNum, uint32_t dmaLineEnable)

This API will enable DMA access for FIFO.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO from which data is to be read. Refer enum adcFIFONum_t.

  • dmaLineEnable – DMA Line is enabled if it is TRUE. DMA Line is disabled if it is FALSE.

int32_t ADC_setStepParams(uint32_t baseAddr, uint32_t stepId, const adcStepConfig_t *configParams)

This API will configure a step for analog to digital conversion.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • stepId – Id of step to be configured. Refer enum adcStepId_t.

  • configParams – Configuration parameters for ADC step. Refer struct adcStepConfig_t.

Returns:

status ADC step configure status.

void ADC_stepEnable(uint32_t baseAddr, uint32_t stepId, uint32_t stepEnable)

This API will enable ADC step.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • stepId – Id of step to be enabled. Refer enum adcStepId_t.

  • stepEnable – Step is enabled if it is TRUE. Step is disabled if it is FALSE.

void ADC_clearAllSteps(uint32_t baseAddr)

This API will clear all the ADC steps.

Parameters:

baseAddr – Base Address of the ADC Registers.

void ADC_start(uint32_t baseAddr, uint32_t adcEnable)

This API will start ADC.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • adcEnable – ADC is enabled/started if it is TRUE. ADC is disabled/stopped if it is FALSE.

void ADC_stepIdTagEnable(uint32_t baseAddr, uint32_t stepIdTag)

This API is used to configure the ADC module for storing step ID along with ADC data.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • stepIdTag – Step ID is stored along with ADC data in FIFO, if it is TRUE. Step ID is not stored along with ADC data in FIFO, if it is FALSE.

uint32_t ADC_getFIFOData(uint32_t baseAddr, uint32_t fifoNum)

This API will read and return FIFO data.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO from which data is to be read. Refer enum adcFIFONum_t.

Returns:

data FIFO data.

uint32_t ADC_getFIFOWordCount(uint32_t baseAddr, uint32_t fifoNum)

This API will return number of word present in the FIFO.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO for which word count is needed. Refer enum adcFIFONum_t.

Returns:

FIFO level Number of words present in the FIFO.

int32_t ADC_setCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum, uint32_t threshold)

This API will configure threshold level for a FIFO.

Note

Actual value programmed is (threshold - 1) to get the threshold level as threshold.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO for which threshold level is to be set. Refer enum adcFIFONum_t.

  • threshold – Number of words in FIFO after which interrupt to CPU will be generated. It can take value from 1 to ADC_FIFO_SIZE.

Returns:

status Configuration status.

uint32_t ADC_getCPUFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum)

This API will read and return threshold level for a FIFO.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO number. Refer enum adcFIFONum_t.

Returns:

threshold Number of words in FIFO after which interrupt to CPU will be generated.

int32_t ADC_setDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum, uint32_t threshold)

This API will configure DMA request level for a FIFO.

Note

Actual value programmed is (threshold - 1) to get the threshold level as threshold.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO for which DMA request level is to be set. Refer enum adcFIFONum_t.

  • threshold – Number of words in FIFO after which DMA request will be generated. It can take value from 1 to ADC_FIFO_SIZE.

Returns:

status Configuration status.

uint32_t ADC_getDMAFIFOThresholdLevel(uint32_t baseAddr, uint32_t fifoNum)

This API will read and return DMA request level for a FIFO.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • fifoNum – FIFO number. Refer enum adcFIFONum_t.

Returns:

threshold Number of words in FIFO after which DMA request will be generated.

void ADC_enableIntr(uint32_t baseAddr, uint32_t intrMask)

This API is used to enable interrupts.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • intrMask – Interrupts to enable. Refer enum adcIntrSrc_t.

void ADC_disableIntr(uint32_t baseAddr, uint32_t intrMask)

This API is used to disable interrupts.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • intrMask – Interrupts to disable.

void ADC_writeEOI(uint32_t baseAddr)

This API is used for EOI for ADC.

Parameters:

baseAddr – Base Address of the ADC Registers.

uint32_t ADC_getIntrStatus(uint32_t baseAddr)

This API is used to get the pending interrupts.

Parameters:

baseAddr – Base Address of the ADC Registers.

Returns:

status Pending interrupt status/occurred.

void ADC_clearIntrStatus(uint32_t baseAddr, uint32_t intrMask)

This API is used to clear the interrupt status.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • intrMask – Interrupts to clear status.

uint32_t ADC_getIntrRawStatus(uint32_t baseAddr)

This API is used to get the raw interrupt status.

Parameters:

baseAddr – Base Address of the ADC Registers.

Returns:

status Pending interrupt status/occurred.

int32_t ADC_setRange(uint32_t baseAddr, uint32_t highRange, uint32_t lowRange)

This API is used to configure the range for ADC.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • highRange – Allowable upper range of data.

  • lowRange – Allowable lower range of data.

Returns:

status configuration status.

void ADC_getRange(uint32_t baseAddr, uint32_t *highRange, uint32_t *lowRange)

This API is used to get the range for conversion.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • highRange – Allowable upper range of data.

  • lowRange – Allowable lower range of data.

void ADC_getSequencerStatus(uint32_t baseAddr, adcSequencerStatus_t *status)

This API is used to get the Sequencer status.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • status – Current status of the sequencer. Refer struct adcSequencerStatus_t.

void ADC_setIdleMode(uint32_t baseAddr, uint32_t idleMode)

This API is used to configure ADC idle mode.

Note

This API is applicable only for TDA3XX.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • idleMode – Idle mode to be configured for ADC module. Refer enum adcIdleMode_t.

void ADC_getRevisionId(uint32_t baseAddr, adcRevisionId_t *revId)

This API is used get the ADC revision ID.

Parameters:
  • baseAddr – Base Address of the ADC Registers.

  • revId – Contains Revision ID of ADC module.. Refer struct adcRevisionId_t.

struct adcRevisionId_t
#include <adc.h>

Structure for accessing Revision ID of ADC module.

struct adcStepConfig_t
#include <adc.h>

Structure containing parameters for ADC step configuration.

struct adcSequencerStatus_t
#include <adc.h>

Structure for reporting ADC sequencer status.