1.3.2 1.4.2 1.5.2 1.29.2 1.38.2 1.39.1 1.40.2 Analog Digital Converter (ADC)
-
8-bit, 10-bit or 12-bit resolution
-
Up to 1,000,000 samples per second (1 MSPS)
-
Differential and single-ended inputs
-
Five internal inputs
-
Single, continuous, and sequencing options
-
Windowing monitor with selectable channel
-
Built-in internal reference and external reference options
-
Event-triggered conversion for accurate timing (one event input)
-
Optional DMA transfer of conversion settings or result
-
Hardware gain and offset compensation
-
Averaging and oversampling with decimation to support up to 16-bit result
-
Selectable sampling time
-
Flexible Power or Throughput rate management
Using The Library
ADC Sample:
#include <stddef.h> // Defines NULL #include <stdbool.h> // Defines true #include <stdlib.h> // Defines EXIT_FAILURE #include <stdio.h> #include "definitions.h" // SYS function prototypes #define ADC_VREF (3.3f) #define DAC_COUNT_INCREMENT (31U) // equivalent to 0.1V(0.1 / (3.3 / ((2^10) - 1))) #define DAC_COUNT_MAX (1023U) uint16_t adc_count; float input_voltage; /* Initial value of dac count which is midpoint = 1.65 V*/ uint16_t dac_count = 0x200; void switch_handler(uintptr_t context ) { /* Write next data sample */ dac_count = dac_count + DAC_COUNT_INCREMENT; if (dac_count > DAC_COUNT_MAX) dac_count=0; DAC_DataWrite(dac_count); } // ***************************************************************************** // ***************************************************************************** // Section: Main Entry Point // ***************************************************************************** // ***************************************************************************** int main ( void ) { /* Initialize all modules */ SYS_Initialize ( NULL ); printf("\n\r---------------------------------------------------------"); printf("\n\r ADC Sample Demo "); printf("\n\r---------------------------------------------------------\n\r"); ADC0_Enable(); SYSTICK_TimerStart(); EIC_CallbackRegister(EIC_PIN_3, switch_handler, (uintptr_t) NULL); DAC_DataWrite(dac_count); while (1) { /* Start ADC conversion */ ADC0_ConversionStart(); /* Wait till ADC conversion result is available */ while(!ADC0_ConversionStatusGet()) { }; /* Read the ADC result */ adc_count = ADC0_ConversionResultGet(); input_voltage = (float)adc_count * ADC_VREF / 4095U; printf("ADC Count = 0x%03x, ADC Input Voltage = %d.%02d V \r", adc_count, (int)input_voltage, (int)((input_voltage - (int)input_voltage)*100.0)); SYSTICK_DelayMs(500); } /* Execution should not come here during normal operation */ return ( EXIT_FAILURE ); }
Library Interface
Analog Digital Converter peripheral library provides the following interfaces:
Functions
Name | Description |
---|---|
ADCx_Initialize | Initializes given instance of ADC peripheral |
ADCx_Enable | Enables given instance of ADC peripheral |
ADCx_Disable | Disables given instance of ADC peripheral |
ADCx_ChannelSelect | Selects ADC input channel |
ADCx_ConversionStart | Starts the ADC conversion with the software trigger |
ADCx_ConversionStatusGet | Returns the status of the conversion of the channel |
ADCx_ConversionResultGet | Returns the conversion result of the channel |
ADCx_ConversionSequenceIsFinished | Returns the status of automatic sequence conversion |
ADCx_WindowMonitorStatusGet | Returns the status of the window monitor flag |
ADCx_ComparisonWindowSet | Returns the status of automatic sequence conversion |
ADCx_CallbackRegister | Registers the function to be called from interrupt |
Data types and constants
Name | Type | Description |
---|---|---|
ADC_STATUS | Enum | Identifies ADC interrupt flag status |
ADC_POSINPUT | Enum | Identifies ADC positive input pin to select |
ADC_NEGINPUT | Enum | Identifies ADC negative input pin to select |
ADC_CALLBACK | Typedef | Defines the data type and function signature for the ADC peripheral callback function |