Content including 1) features; 2) driver design logic and use method; 3) typical use case.
More...
Peripheral features and how this peripheral works
Analog-to-Digital Converter function
For the chip-specific implementation details of this module's instances see the chip configuration information.The 16-bit analog-to-digital converter (ADC) is a successive approximation ADC designed for operation within an integrated microcontroller system-on-chip.For the chip specific modes of operation, see the power management information of the device.
Features
- Supports up to 24 single-ended analog inputs channels.
- A single-ended input is selected for conversion through the channel select bits, with their own Sample/Hold unit and converter.
- Supports long sample and short sample.(There is an additional 2-cycle adder on any conversion.)
- For long sample,This allows higher impedance inputs to be accurately sampled or to maximize conversion speed for lower impedance inputs.Longer sample times can also be used to lower overall power consumption when continuous conversions are enabled if high conversion rates are not required.Default long sample time 20 extra ADCK cycles;24 ADCK cycles total.
- For short sample,if not need to accurately sample higher impedance inputs. After the module becomes active, sampling of the input begins.
- select between sample times based on the conversion mode that is selected.
- When sampling is completed, the converter is isolated from the input channel and a successive approximation algorithm is applied to determine the digital value of the analog signal.
- The result of the conversion is transferred to Rn upon completion of the conversion algorithm.
- Supports single or continuous conversion.
- If hardawre average and software enanle,If continuous conversions are also enabled, a new set of conversions to be averaged are initiated following the last of the selected number of conversions.
- Support power configuration and high-speed conversion.
- Power mode 1.normal power 2.low-power mode For low-power,the power is reduced at the expense of maximum clock speed.Stop mode is a low-power consumption Standby mode during which most or all clock sources on the MCU are disabled.All module registers contain their reset values following exit from Low-Power Stop mode. Therefore,the module must be re-enabled and re-configured following exit from Low-Power Stop mode.
- Conversion rate 1.high-speed conversion Nedd 2 additional ADCK cycles to total conversion time.
- Support auto Calibration. The ADC contains a self-calibration function that is required to achieve the specified accuracy. Calibration must be run, or valid calibration values written, after any reset andbefore a conversion is initiated.The calibration function sets the offset calibration value and the plus-side calibration values.The offset calibration value is automatically stored in the ADC offset correction register and the plus-side calibration values are automatically stored in the ADC plus-side calibration registers. The user must configure the ADC correctly prior to calibration, and must generate the plus-side gain calibration results and store them in the ADC plus-side gain register after the calibration function completes.Prior to calibration, the user must configure the ADC's clock source and frequency, low power configuration,voltage reference selection, sample time, and high speed configuration according to the application's clock source availability and needs. If the application uses the ADC in a wide variety of configurations, the configuration for which the highest accuracy is required should be selected, or multiple calibrations can be done for the different configurations.For best calibration results: Set hardware averaging to maximum.
- support selectable asynchronous hardware conversion trigger. The ADC module has a selectable asynchronous hardware conversion trigger, ADHWT, when hardware conversion enable,ADHWTSn, has occurred. This source is not available on all MCUs. See the Chip Configuration chapter for information on the ADHWT source and the ADHWTSn configurations specific to this MCU. When an ADHWT source is available and hardware trigger is enabled, that is when hardware conversion enable, a conversion is initiated on the rising-edge of ADHWT after a hardware trigger select event, that is, ADHWTSn, has occurred. If a conversion is in progress when a rising-edge of a trigger occurs, the rising-edge is ignored. In continuous convert configuration, only the initial rising-edge to launch continuous conversions is observed, and until conversion is aborted, the ADC continues to do conversions on the same SCn register that initiated the conversion.
- support different clock operation the mcu. For example,Asynchronous clock (ADACK): This clock is generated from a clock source within the ADC module. When the ADACK clock source is selected, it is not required to be active prior to conversion start.When it is selected and it is not active prior to a conversion start , ADACK is activated at the start of a conversion and deactivated when conversions are terminated. In this case, there is an associated clock startup delay each time the clock source is re-activated. To avoid the conversion times variability and latency associated with the ADACK clock startup, enable Asynchronous Clock and wait the worst-case startup time of 5 μs prior to initiating any conversions using the ADACK clock source. Conversions are possible using ADACK as the input clock source while the MCU is in Normal Stop mode.See Power Control for more information.
- Supports DMA.
- DMA trigger source can be selected as trigger from end of scan interrupt or sample slot result ready bit.
- Each converter can generate DMA trigger signal.
- Supports Interrupts.
- Conversion complete interrupt
How does this peripheral work
Before the ADC16 module can be used to complete conversions, an initialization procedure must be performed. A typical sequence is:
- Get ADC16 default Configuration.
- Update select the input clock source and the divide ratio used to generate ADCK. This register is also used for selecting sample time and low-power configuration.
- Update select the conversion trigger, hardware or software, and compare function options, if enabled.
- Update select whether conversions will be continuous or completed only once and whether to perform hardware averaging.
- Update registers to enable or disable conversion complete interrupts. Also, select the input channel which can be used to perform conversions.
- Initialization ADC16 Configuration,Calibrate the ADC by following the calibration instructions in Calibration function.
- Turn on the ADC16 conversion.
How this driver is designed to make this peripheral works
The adc16 driver provides a structure adc16_config_t, which contains the main options of the adc16 function. The ADC16_Init() function uses adc16_config_t type parameters, this function can be used for configuration In addition to clock selection, frequency setting, sampling time, trigger mode, interrupt enable, DAM enable, hardware trigger configuration, the main features of the ADC16 module.After the ADC16_Init() function is called when the relevant converter is powered on,exist The software starts or is triggered by the hardware, and starts according to the configured options.
- Initialization and deinitialization Interfaces. The APIs in the function group can be used to initialize or de-initialize the adc16 module.
- Trigger control interface. The API in this function group can be used to configure the trigger mode, with hardware trigger and software trigger.
- DMA Control Interfaces. The APIs in this function group can be used to set DMA features. Such as select DMA trigger source, enable/disable DMA.
- Interrupt Control Interfaces. The APIs in this function group can be used to enable/disable interrupts.
How to use this driver
- Sets the ADC16 resources by invoking ADC16_Init()
- Defines the variable in type of adc16_config_t.
- [Optional] Invokes ADC16_GetDefaultConfig() function with the pointer of variable which is type of adc16_config_t to get the default options.
- Sets the member of the variable which is in type of adc16_config_t. Listed below are some members that must be configured to implement ADC16. -eReferenceVoltageSource: Used to select the reference voltage source, For external pins pair of VrefH and VrefL,this member defaults to kADC16_ReferenceVoltageSourceVref
- eConversionTrigger: Used to set the trigger mode of the converter trigger E.g. If the user wants to set the trigger mode to software trigger mode. This member Can be set to kADC16_SoftWareTrigger. -eChannelInput: Used to set the input channel of the corresponding configuration, the default configuration of This member can be set to kADC16_ModuleDisabled. -u32GroupId: Used to select the group registers.At any point,for example,the u32GroupId 0 is for Group A registers. The u32GroupId 0 is used for both software and hardware trigger modes.
- Invokes ADC16_Init() function to set ADC16 resources.
Typical Use Case
This function initializes the converter configuration structure with available settings. The default values are as follows.
- ADC16_polling initialize
- ADC16_interrupt initialize
- ADC16_continuous_dma initialize In this type of use case. Note the continuous mode must be selected,turn on the dma.If the application wants to use interrupt, please remember to enable related interrupts.The prototype of this type of use case is shown below.