ADC Drivers

This Analog to Digital Converter (ADC) driver provides an interface for the conversion of analog voltage to digital value.

The following driver variants are available:

  • ADC Synchronous Driver: The driver will block there (i.e. not return) until the requested data has been read. Functionality is therefore synchronous to the calling thread, i.e. the thread will wait for the result to be ready. The adc_sync_read_channel function will perform a conversion of the voltage on the specified channel and return the result when it is ready.

  • ADC Asynchronous Driver: The driver adc_async_read_channel function will attempt to read the required number of conversion results from a ring buffer. It will return immediately (i.e. not block), even if the requested number of data is not available. If data was not available, or less data than requested was available, this will be indicated in the function's return value. The asynchronous driver uses interrupts to communicate that ADC data is available, and the driver's IRQ handler reads data from hardware and into ring buffers in memory. These ring buffers decouple the generation of data in the ADC with the timing of the application request for this data. In a way, the producer and consumer events are asynchronous to each other. The user can register a callback function to piggyback on the IRQ handler routine for communicating with the main application.

  • ADC RTOS Driver: The driver is intended to use ADC functions in a Real-Time operating system, i.e. is thread safe.

  • ADC DMA Driver: The driver uses a DMA system to transfer data from ADC to a memory buffer in RAM.

ADC Basics and Best Practice

An Analog-to-Digital Converter (ADC) converts analog signals to digital values. A reference signal with a known voltage level is quantified into equally sized chunks, each representing a digital value from 0 to the highest number possible with the bit resolution supported by the ADC. The input voltage measured by the ADC is compared against these chunks and the chunk with the closest voltage level defines the digital value that can be used to represent the analog input voltage level.

Normally an ADC can operate in either differential or single-ended mode. In differential mode two signals (V+ and V-) are compared against each other and the resulting digital value represents the relative voltage level between V+ and V-. This means that if the input voltage level on V+ is lower than on V- the digital value is negative, which also means that in differential mode one bit is lost to the sign. In single-ended mode only V+ is compared against the reference voltage, and the resulting digital value can only be positive, but the full bit-range of the ADC can be used.

Normally multiple resolutions are supported by the ADC. Lower resolution can reduce the conversion time, but lose accuracy.

Some ADCs have a gain stage on the input lines, which can be used to increase the dynamic range. The default gain value is normally x1, which means that the conversion range is from 0V to the reference voltage. Applications can change the gain stage to increase or reduce the conversion range.

The window mode allows the conversion result to be compared to a set of predefined threshold values. Applications can use the callback function to monitor if the conversion result exceeds the predefined threshold value.

Normally multiple reference voltages are supported by the ADC, both internal and external, with different voltage levels. The reference voltage have an impact on the accuracy, and should be selected to cover the full range of the analog input signal and never less than the expected maximum input voltage.

There are two conversion modes supported by ADC: single shot and free running. In single shot mode the ADC make only one conversion when triggered by the application. In free running mode it continues to make conversion from it is triggered until it is stopped by the application. When window monitoring, the ADC should be set to free running mode.