Sensor Controller Studio

Peripherals : ADC

Description

Analog to digital converter

The ADC peripheral is a 12-bit general purpose successive-approximation type (SAR) ADC, which can be used to sample analog-capable I/O pins or internal chip voltages at up to 200 kS/s with manual, GPIO, COMPA or periodical timer trigger. The ADC input signal is also positive input to the COMPB peripheral.

The input stage consists of a switched capacitor stage where the input voltage is sampled and then held before the conversion is done. The ADC can be operated in synchronous or asynchronous mode:

The input and reference voltages are scaled down internally by a factor 1408 / 4095 before being used in the ADC. It is possible to disable down-scaling of the ADC input, for increased resolution at the cost of reduced input range. Note that this changes the maximum input rating of the ADC input, and that higher voltages may damage the ADC.

The reference voltage can either be fixed (nominally 4.3 V for scaled-down input) or relative (nominally VDDS for scaled-down input).

The ADC values returned by adcReadFifo() are not compensated for offset and gain errors in the ADC. This compensation, using factory configuration data stored during chip production, can be done by using the AUX_ADC DriverLib module on the System CPU to:

One or more instances of the Analog Pins resource must be used to enable sampling on analog-capable I/O pins.

Block Diagram

The block diagram shows signal routing for the ADC (with I/O pins for 7x7 RGZ package):

ADC FIFO

The ADC FIFO can store between between 0 and 4 samples. Use the adcGetFifoStatus() procedure to get the current FIFO status:

If overflow or underflow occurs, the ADC FIFO will enter an error condition, where no more samples can be added to the FIFO. During the overflow condition, it is still possible to read the samples that are already in the FIFO. Use the adcFlushFifo() procedure to clear the error condition.

Examples
Sampling One Pin

// Select ADC input
adcSelectGpioInput(AUXIO_A_SENSOR_OUTPUT);

// Enable the ADC (fixed reference, 2.7 us sample time, manual trigger)
adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);

// Sample the sensor and store the ADC value
adcGenManualTrigger();
adcReadFifo(output.adcValue);

// Disable the ADC
adcDisable();

Sampling Multiple Pins

// Enable the ADC (fixed reference, 2.7 us sample time, manual trigger)
adcEnableSync(ADC_REF_FIXED, ADC_SAMPLE_TIME_2P7_US, ADC_TRIGGER_MANUAL);

// For each pin (with one entry per pin in cfg.pAdcValue[] and output.pAdcValue[]) ...
for (U16 n = 0; n < SENSOR_OUTPUT_COUNT; n++) {

    // Select ADC input
    adcSelectGpioInput(cfg.pAuxioASensorOutput[n]);

    // Sample the pin and store the ADC value
    adcGenManualTrigger();
    adcReadFifo(output.pAdcValue[n]);
}

// Disable the ADC
adcDisable();

Constants

NameDescription
ADC_INPUT_DCOUPLSelects DCOUPL as input, nominally 1.27 V
ADC_INPUT_VDDSSelects VDDS (supply voltage) as input, nominally VDDS
ADC_INPUT_VSSSelects VSS/GND (ground) as input, nominally 0.0 V
ADC_REF_FIXEDSelects fixed reference, nominally 4.3 V
ADC_REF_VDDS_RELSelects relative reference, nominally VDDS
ADC_SAMPLE_TIME_10P6_USADC sampling time: Sample the input for 10.6 us before converting
ADC_SAMPLE_TIME_10P9_MSADC sampling time: Sample the input for 10.9 ms before converting
ADC_SAMPLE_TIME_170_USADC sampling time: Sample the input for 170 us before converting
ADC_SAMPLE_TIME_1P37_MSADC sampling time: Sample the input for 1.37 ms before converting
ADC_SAMPLE_TIME_21P3_USADC sampling time: Sample the input for 21.3 us before converting
ADC_SAMPLE_TIME_2P73_MSADC sampling time: Sample the input for 2.73 ms before converting
ADC_SAMPLE_TIME_2P7_USADC sampling time: Sample the input for 2.7 us before converting
ADC_SAMPLE_TIME_341_USADC sampling time: Sample the input for 341 us before converting
ADC_SAMPLE_TIME_42P6_USADC sampling time: Sample the input for 42.6 us before converting
ADC_SAMPLE_TIME_5P3_USADC sampling time: Sample the input for 5.3 us before converting
ADC_SAMPLE_TIME_5P46_MSADC sampling time: Sample the input for 5.46 ms before converting
ADC_SAMPLE_TIME_682_USADC sampling time: Sample the input for 682 us before converting
ADC_SAMPLE_TIME_85P3_USADC sampling time: Sample the input for 85.3 us before converting
ADC_TRIGGER_AUXIO_HIGH_BASEADC trigger: AUXIO (base + index) rising edge
ADC_TRIGGER_AUXIO_LOW_BASEADC trigger: AUXIO (base + index) falling edge
ADC_TRIGGER_AUX_TIMER0ADC trigger: Periodical, generated by the Timer 0 resource
ADC_TRIGGER_AUX_TIMER1ADC trigger: Periodical, generated by the Timer 1 resource
ADC_TRIGGER_COMPA_HIGHADC trigger: COMPA output rising edge
ADC_TRIGGER_COMPA_LOWADC trigger: COMPA output falling edge
ADC_TRIGGER_MANUALADC trigger: Single, generated by calling adcGenManualTrigger()
BV_ADC_FIFO_ALMOST_FULLADC FIFO flag: The FIFO is almost full (3 of 4 samples)
BV_ADC_FIFO_EMPTYADC FIFO flag: The FIFO is empty
BV_ADC_FIFO_FULLADC FIFO flag: The FIFO is full (4 of 4 samples)
BV_ADC_FIFO_OVERFLOWADC FIFO flag: FIFO overflow has occurred
BV_ADC_FIFO_UNDERFLOWADC FIFO flag: FIFO underflow has occurred

Global Variables

None.

Procedures
adcDisable

Prototype: adcDisable()

Disables the ADC.

adcDisableInputScaling

Prototype: adcDisableInputScaling()

Disables scaling of the ADC input. Scaling is enabled by default, and is always reenabled by adcDisable().

This procedure must only be called while the ADC is disabled, before calling adcEnableSync() or adcEnableAsync().

Note that different input maximum ratings apply when input scaling is disabled, and that violating these may damage the device.

adcEnableAsync

Prototype: adcEnableAsync(#refSource, #trigger)

Enables the ADC for asynchronous operation, with continuous sampling between conversions.

The ADC trigger starts the conversion. Note that the first conversion may be invalid if the initial sampling period is too short.

This procedure must only be called when the ADC is disabled. To change ADC configuration, call adcDisable() before re-enabling the ADC.

Parameter value(s)

adcEnableSync

Prototype: adcEnableSync(#refSource, #sampleTime, #trigger)

Enables the ADC for synchronous operation, with a fixed sampling period before each conversion.

The ADC is idle between conversions, and the ADC trigger starts the sampling period before the conversion.

This procedure must only be called when the ADC is disabled. To change ADC configuration, call adcDisable() before re-enabling the ADC.

Parameter value(s)

adcFlushFifo

Prototype: adcFlushFifo()

Flushes the ADC FIFO. This empties the FIFO and clears the underflow/overflow flags.

Note: This procedure must only be called while the ADC is enabled.

adcGenManualTrigger

Prototype: adcGenManualTrigger()

Generates a single manual ADC trigger.

For synchronous mode, the trigger starts sampling followed by conversion.

For asynchronous mode, the trigger starts conversion.

adcGetFifoStatus

Prototype: adcGetFifoStatus(value)

Returns flags indicating the status of the ADC FIFO.

The flags indicate FIFO empty, full and almost full, and whether overflow/underflow has occurred.

Return value(s)

adcPopFifo

Prototype: adcPopFifo(value)

Pops and returns the first sample from the FIFO.

Note that this procedure causes ADC FIFO underflow if executed while the FIFO is empty.

Return value(s)

adcReadFifo

Prototype: adcReadFifo(value)

Waits until there is at least one sample in the ADC FIFO, and then pops and returns the first sample from the FIFO.

Note that this procedure will deadlock under the following conditions:

Use instead a combination of adcGetFifoStatus(), adcPopFifo() and timeout, if such conditions are relevant for your application.

Return value(s)

adcSelectGpioInput

Prototype: adcSelectGpioInput(auxio)

Selects a GPIO pin as input for the ADC.

Note that calling this procedure also selects the same input for COMPB.

Parameter value(s)

adcSelectIntInput

Prototype: adcSelectIntInput(intInput)

Selects an internal voltage as input the ADC. This may be used for calibration and for measuring power supply voltage.

Note that calling this procedure also selects the same input for COMPB.

Parameter value(s)