![]() |
![]() |
ADCBuf driver implementation for an LPF3 analog-to-digital converter.
The ADCBuf header file should be included in an application as follows:
This is an LPF3 specific implementation of the generic ADCBuf driver. The generic ADCBuf API specified in ti/drivers/ADCBuf.h should be called by the application, not the device specific implementation in ti/drivers/adcbuf/ADCBufLPF3.c
The internal ADC sample timer is used to generate samples at a specified frequency and the DMA is used to fill a buffer with a specified size in the background. The application may execute other tasks while the hardware handles the conversions. In contrast to the standard ti/drivers/ADC driver, this driver allows for precise sampling of waveforms.
| Driver | Number of samples needed in one call |
|---|---|
| ADC.h | 1 |
| ADCBuf.h | > 1 |
The ADC drivers supports making between 1 and 1024 measurements once or continuous measuring with returned buffer sizes between 1 and 1024 measurements.
The ADCBuf driver is opened by calling ADCBuf_open() which will set up interrupts and configure the internal components of the driver. However, the ADCBuf hardware or analog pins are not configured by calling ADCBuf_open() since other software components might be using the ADC.
In order to perform an ADC conversion, the application must call ADCBuf_convert(). This call will request the ADC resource, configure the ADC, set up the DMA, and perform the requested ADC conversions on the selected DIO or internal signal.
If the ADC is used by another component when the driver requests it at the start of the ADCBuf_convert() call, the calling task will be put in blocked state until the ADC is available. If ADCBuf_convert() is called from ISR context, the call will fail and return ADCBuf_STATUS_ERROR. The ADC resource may be pre-acquired by calling the ADCBufLPF3_acquireAdcSemaphore() function. The semaphore must be manually released again when done with the ADC by calling ADCBufLPF3_releaseAdcSemaphore()
The following errors may occur when opening the ADC without assertions enabled:
The following errors may occur when requesting an ADC conversion:
The TI Power management framework will try to put the device into the most power efficient mode whenever possible. Please see the technical reference manual for further details on each power mode.
While converting, the ADCBufLPF3 driver sets a power constraint to keep the device out of standby. When the conversion has finished, the power constraint is released. The driver also sets a dependency on the DMA to enable background transfers from the ADC FIFO to memory. The following statements are valid:
| API function | Description |
|---|---|
| ADCBuf_init() | Initialize ADC driver |
| ADCBuf_open() | Open the ADC driver and configure driver |
| ADCBuf_convert() | Perform ADC conversion |
| ADCBuf_convertCancel() | Cancel ongoing ADC conversion |
| ADCBuf_close() | Close ADC driver |
| ADCBuf_Params_init() | Initialise ADCBuf_Params structure to default values |
| ADCBuf_getResolution() | Get the resolution of the ADC of the current device |
| ADCBuf_adjustRawValues() | Adjust the values in a returned buffer for manufacturing tolerances |
| ADCBuf_convertAdjustedToMicroVolts() | Convert a buffer of adjusted values to microvolts |
| ADCBufLPF3_acquireAdcSemaphore() | Manually pre-acquire ADC semaphore |
| ADCBufLPF3_releaseAdcSemaphore() | Release ADC semaphore previously manually pre-acquired using |
| Reference | Resolution | Min Frequency | Max Frequency |
|---|---|---|---|
| External or VDDS | 8-bit | 978 sps | 1600 ksps |
| External or VDDS | 10-bit | 978 sps | 1330 ksps |
| External or VDDS | 12-bit | 977 sps | 1200 ksps |
| Internal | 8-bit | 976 sps | 400 ksps |
| Internal | 10-bit | 975 sps | 308 ksps |
| Internal | 12-bit | 975 sps | 267 ksps |
channelCount must always be set to 1 when calling ADCBuf_convert(). For the same reason, the value of the completedChannel argument in the ADCBuf_Callback will always be 0.#include <stdint.h>#include <stdbool.h>#include <ti/drivers/ADC.h>#include <ti/drivers/Power.h>#include <ti/drivers/ADCBuf.h>#include <ti/drivers/adc/ADCLPF3.h>#include <ti/drivers/dma/UDMALPF3.h>#include <ti/drivers/dpl/HwiP.h>#include <ti/drivers/dpl/SwiP.h>#include <ti/drivers/dpl/ClockP.h>#include <ti/drivers/dpl/SemaphoreP.h>#include <ti/devices/DeviceFamily.h>#include <DeviceFamily_constructPath(inc/hw_memmap.h)>#include <DeviceFamily_constructPath(inc/hw_adc.h)>#include <DeviceFamily_constructPath(inc/hw_types.h)>#include <DeviceFamily_constructPath(driverlib/adc.h)>#include <DeviceFamily_constructPath(driverlib/evtsvt.h)>
Go to the source code of this file.
Data Structures | |
| struct | ADCBufLPF3_AdcChannelLutEntry |
| Table entry that maps a virtual adc channel to the corresponding hardware configuration. More... | |
| struct | ADCBufLPF3_HWAttrs |
| ADCBufLPF3 Hardware Attributes. More... | |
| struct | ADCBufLPF3_Object |
| ADCBufLPF3 Object. More... | |
Macros | |
| #define | ADCBufLPF3_STATUS_UNDERFLOW (ADCBuf_STATUS_RESERVED - 0) |
| Underflow occurred during conversion. More... | |
| #define | ADCBufLPF3_STATUS_OVERFLOW (ADCBuf_STATUS_RESERVED - 1) |
| Overflow occurred during conversion. More... | |
| #define | ADCBufLPF3_STATUS_UNDERFLOW_AND_OVERFLOW (ADCBuf_STATUS_RESERVED - 2) |
| Both overflow and underflow occurred during conversion. More... | |
| #define | ADCBufLPF3_BYTES_PER_SAMPLE 2 |
Typedefs | |
| typedef struct ADCBufLPF3_Object * | ADCBufLPF3_Handle |
Enumerations | |
| enum | ADCBufLPF3_ConversionStatus { ADCBufLPF3_CONVERSION_NONE = 0, ADCBufLPF3_CONVERSION_STARTING, ADCBufLPF3_CONVERSION_IN_PROGRESS } |
| Conversion status used internally by the ADCBufLPF3 driver. More... | |
Functions | |
| bool | ADCBufLPF3_acquireAdcSemaphore (ADCBuf_Handle handle, uint32_t timeout) |
| Function to acquire the semaphore that arbitrates access to the ADC. More... | |
| bool | ADCBufLPF3_releaseAdcSemaphore (ADCBuf_Handle handle) |
| This function releases the ADC semaphore if it was pre it is in the possession of the ADCBuf instance. More... | |
Variables | |
| const ADCBuf_FxnTable | ADCBufLPF3_fxnTable |
| #define ADCBufLPF3_STATUS_UNDERFLOW (ADCBuf_STATUS_RESERVED - 0) |
Underflow occurred during conversion.
Underflow means that the DMA tried to read data from the ADC before it was ready.
This error code is passed to the ADCBuf_Callback function as the status parameter if an underflow has occurred.
Only applicable when the recurrence mode is ADCBuf_RECURRENCE_MODE_CONTINUOUS
| #define ADCBufLPF3_STATUS_OVERFLOW (ADCBuf_STATUS_RESERVED - 1) |
Overflow occurred during conversion.
Overflow means that the DMA tried to read data from the ADC before it was ready.
This error code is passed to the ADCBuf_Callback function as the status parameter if an underflow has occurred.
Only applicable when the recurrence mode is ADCBuf_RECURRENCE_MODE_CONTINUOUS
| #define ADCBufLPF3_STATUS_UNDERFLOW_AND_OVERFLOW (ADCBuf_STATUS_RESERVED - 2) |
Both overflow and underflow occurred during conversion.
Overflow means that the DMA tried to read data from the ADC before it was ready.
Underflow means that the DMA tried to read data from the ADC before it was ready.
This error code is passed to the ADCBuf_Callback function as the status parameter if both an overflow and underflow has occurred.
Only applicable when the recurrence mode is ADCBuf_RECURRENCE_MODE_CONTINUOUS
| #define ADCBufLPF3_BYTES_PER_SAMPLE 2 |
| typedef struct ADCBufLPF3_Object * ADCBufLPF3_Handle |
| bool ADCBufLPF3_acquireAdcSemaphore | ( | ADCBuf_Handle | handle, |
| uint32_t | timeout | ||
| ) |
Function to acquire the semaphore that arbitrates access to the ADC.
This function tries to pre-acquire the ADC semaphore before ADCBuf_convert() is called by the application. Normally, the ADCBuf driver acquires the ADC semaphore when calling ADCBuf_convert(). The driver may need to wait for the ADC to be available. Consequently, the time at which the conversion is actually made is normally non-deterministic. Pre-acquiring the semaphore makes the ADCBuf_convert() call deterministic.
If the ADC semaphore is manually acquired using this function, it must also be manually released using ADCBufLPF3_releaseAdcSemaphore(). It is not allowed to close the ADCBuf driver using ADCBuf_close() before the ADC semaphore has been released.
| handle | An ADCBufLPF3 handle returned from #ADCBufLPF3_open() |
| timeout | Timeout (in ClockP ticks) to wait for the semaphore to be posted (signalled). Passed directly to SemaphoreP_pend() |
| bool ADCBufLPF3_releaseAdcSemaphore | ( | ADCBuf_Handle | handle | ) |
This function releases the ADC semaphore if it was pre it is in the possession of the ADCBuf instance.
| handle | An ADCBuf handle returned from ADCBufLPF3_open() |
| const ADCBuf_FxnTable ADCBufLPF3_fxnTable |