3.2.1 Basic ADC
10-bit Basic Analog-to-Digital Converter
3.2.1.1 Introduction
This Analog-to-Digital Converter (ADC) features a 10-bit successive approximation. The device also supports 16 differential voltage input combinations. Two of the differential inputs (ADC1, ADC0 and ADC3, ADC2) are equipped with a programmable gain stage. This provides amplification steps of 0 dB (1x), 20 dB (10x), or 46 dB (200x) on the differential input voltage before the A/D conversion. Seven differential analog input channels share a common negative terminal (ADC1), while any other ADC input can be selected as the positive input terminal. If 1x or 10x gain is used, 8-bit resolution can be expected. If 200x gain is used, 6- bit resolution can be expected. Note that internal references of 1.1V should not be used on 10x and 200x gain.
3.2.1.2 Supported Device Families
ATmega32xx |
3.2.1.3 Required header files:
#include "mcc_generated_files/adc/adc[X].h"
3.2.1.4 Module Documentation
3.2.1.4.1 ADC
This file contains the API prototypes and other data types for the Analog-to-Digital Converter (ADC) module.
Module description
This file contains the API prototypes and other data types for the Analog-to-Digital Converter (ADC) module.
Typedefs
typedef void(* adc_irq_cb_t) (void)
Function pointer to the callback function called by the IRQ when operating in Normal mode. The default value is set to NULL, which means that no callback function will be used.
typedef uint16_t adc_result_t
Data type for the result of the Analog-to-Digital Conversion (ADC).
typedef uint8_t adc_0_channel_t
Data type for the ADC Input Selection.
Functions
int8_t ADC_Initialize (void)
Initializes the ADC interface. If the module is configured to the Disabled state, the clock is also disabled.
void ADC_Enable (void)
Enables the ADC module and the clock system by setting the Enable bit in the ADC Control register.
void ADC_Disable (void)
Disables the ADC module and the clock by clearing the Enable bit in the ADC Control register.
void ADC_StartConversion (adc_0_channel_t channel)
Starts an Analog-to-Digital (A/D) conversion.
bool ADC_IsConversionDone (void)
Checks if the A/D conversion is done.
adc_result_t ADC_GetConversionResult (void)
Reads the result of the A/D conversion.
adc_result_t ADC_GetConversion (adc_0_channel_t channel)
Starts a conversion and returns the result.
uint8_t ADC_GetResolution (void)
Returns the number of bits from the result of the conversion.
void ADC_DigitalInputDisable (uint8_t DisableValue)
Disables Register 0 for ADC digital input.
void ADC_RegisterCallback (adc_irq_cb_t callback)
Registers a callback function which is called if the conversion satisfies the window criteria.
Typedef Documentation
adc_0_channel_t
uint8_t adc_0_channel_t
Data type for the ADC Input Selection.
adc_irq_cb_t
void adc_irq_cb_t
Function pointer to the callback function called by the IRQ when operating in Normal mode. The default value is set to NULL, which means that no callback function will be used.
adc_result_t
uint16_t adc_result_t
Data type for the result of the Analog-to-Digital Conversion (ADC).
Function Documentation
ADC_DigitalInputDisable()
void ADC_DigitalInputDisable (uint8_t DisableValue)
Disables Register 0 for ADC digital input.
|
None. |
ADC_Disable()
void ADC_Disable (void )
Disables the ADC module and the clock by clearing the Enable bit in the ADC Control register.
|
None. |
ADC_Enable()
void ADC_Enable (void )
Enables the ADC module and the clock system by setting the Enable bit in the ADC Control register.
|
None. |
ADC_GetConversion()
adc_result_t ADC_GetConversion (adc_0_channel_t channel)
Starts a conversion and returns the result.
|
adc_result_t - The result of the conversion read from the ADC module. |
ADC_GetConversionResult()
adc_result_t ADC_GetConversionResult (void )
Reads the result of the A/D conversion.
|
adc_result_t - The result of the conversion read from the ADC module |
ADC_GetResolution()
uint8_t ADC_GetResolution (void )
Returns the number of bits from the result of the conversion.
|
uint8_t - The number of bits in the result of the conversion. |
ADC_Initialize()
int8_t ADC_Initialize (void )
Initializes the ADC interface. If the module is configured to the Disabled state, the clock is also disabled.
|
|
Initializes the ADC interface. If the module is configured to the Disabled state, the clock is also disabled.
ADC_IsConversionDone()
bool ADC_IsConversionDone (void )
Checks if the A/D conversion is done.
|
|
ADC_RegisterCallback()
void ADC_RegisterCallback (adc_irq_cb_t callback)
Registers a callback function which is called if the conversion satisfies the window criteria.
|
None. |
ADC_StartConversion()
void ADC_StartConversion (adc_0_channel_t channel)
Starts an Analog-to-Digital (A/D) conversion.
|
None. |
3.2.1.5 File Documentation
3.2.1.5.1 source/adc.c File Reference
This file contains the driver code for the ADC module.
#include <avr/io.h> #include "../adc.h"
Functions
int8_t ADC_Initialize (void)
Initialize ADC interface.
void ADC_Enable (void)
Enables the ADC module and the clock system by setting the Enable bit in the ADC Control register.
void ADC_Disable (void)
Disables the ADC module and the clock by clearing the Enable bit in the ADC Control register.
void ADC_StartConversion (adc_0_channel_t channel)
Starts an Analog-to-Digital (A/D) conversion.
bool ADC_IsConversionDone (void)
Checks if the A/D conversion is done.
adc_result_t ADC_GetConversionResult (void)
Reads the result of the A/D conversion.
adc_result_t ADC_GetConversion (adc_0_channel_t channel)
Starts a conversion and returns the result.
uint8_t ADC_GetResolution (void)
Returns the number of bits from the result of the conversion.
void ADC_DigitalInputDisable (uint8_t DisableValue)
Disables Register 0 for ADC digital input.
void ADC_RegisterCallback (adc_irq_cb_t callback)
Registers a callback function which is called if the conversion satisfies the window criteria.
Variables
adc_irq_cb_t ADC_cb = NULL
Detailed Description
This file contains the driver code for the ADC module.
ADC Generated Driver File
Variable Documentation
ADC_cb
adc_irq_cb_t ADC_cb = NULL
Section: Included FilesFunction pointer to the callback function called by the IRQ when operating in Normal mode. The default value is set to NULL, which means that no callback function will be used.
3.2.1.5.2 source/adc.h File Reference
#include "../system/utils/compiler.h"
Functions
int8_t ADC_Initialize (void)
Initializes the ADC interface. If the module is configured to the Disabled state, the clock is also disabled.
void ADC_Enable (void)
Enables the ADC module and the clock system by setting the Enable bit in the ADC Control register.
void ADC_Disable (void)
Disables the ADC module and the clock by clearing the Enable bit in the ADC Control register.
void ADC_StartConversion (adc_0_channel_t channel)
Starts an Analog-to-Digital (A/D) conversion.
bool ADC_IsConversionDone (void)
Checks if the A/D conversion is done.
adc_result_t ADC_GetConversionResult (void)
Reads the result of the A/D conversion.
adc_result_t ADC_GetConversion (adc_0_channel_t channel)
Starts a conversion and returns the result.
uint8_t ADC_GetResolution (void)
Returns the number of bits from the result of the conversion.
void ADC_DigitalInputDisable (uint8_t DisableValue)
Disables Register 0 for ADC digital input.
void ADC_RegisterCallback (adc_irq_cb_t callback)
Registers a callback function which is called if the conversion satisfies the window criteria.
Typedefs
typedef void(* adc_irq_cb_t) (void)
Function pointer to the callback function called by the IRQ when operating in Normal mode. The default value is set to NULL, which means that no callback function will be used.
typedef uint16_t adc_result_t
Data type for the result of the Analog-to-Digital Conversion (ADC).
typedef uint8_t adc_0_channel_t
Data type for the ADC Input Selection.
Detailed Description
ADC Generated Driver API Header File