Analog-to-Digital Converter (ADC/ADC12B) driver for SAM.
Copyright (c) 2011-2018 Microchip Technology Inc. and its subsidiaries.
#include "compiler.h"
Data Structures | |
struct | adc_internal_ref |
Macros | |
#define | ADC_FREQ_MAX 20000000 |
#define | ADC_FREQ_MIN 1000000 |
#define | ADC_STARTUP_FAST 12 |
#define | ADC_STARTUP_NORM 40 |
Enumerations | |
enum | adc12b_trigger_t { ADC12B_TRIG_SW = ADC12B_MR_TRGEN_DIS, ADC12B_TRIG_EXT = ADC12B_MR_TRGSEL_ADC_TRIG0 | ADC12B_MR_TRGEN, ADC12B_TRIG_TIO_CH_0 = ADC12B_MR_TRGSEL_ADC_TRIG1 | ADC12B_MR_TRGEN, ADC12B_TRIG_TIO_CH_1 = ADC12B_MR_TRGSEL_ADC_TRIG2 | ADC12B_MR_TRGEN, ADC12B_TRIG_TIO_CH_2 = ADC12B_MR_TRGSEL_ADC_TRIG3 | ADC12B_MR_TRGEN, ADC12B_TRIG_PWM_EVENT_LINE_0 = ADC12B_MR_TRGSEL_ADC_TRIG4 | ADC12B_MR_TRGEN, ADC12B_TRIG_PWM_EVENT_LINE_1 = ADC12B_MR_TRGSEL_ADC_TRIG5 | ADC12B_MR_TRGEN } |
enum | adc_channel_num_t { ADC_CHANNEL_0 = 0, ADC_CHANNEL_1 = 1, ADC_CHANNEL_2 = 2, ADC_CHANNEL_3 = 3, ADC_CHANNEL_4 = 4, ADC_CHANNEL_5 = 5, ADC_CHANNEL_6 = 6, ADC_TEMPERATURE_SENSOR = 7 } |
enum | adc_gainvalue_t { ADC_GAINVALUE_0 = 0, ADC_GAINVALUE_1 = 1, ADC_GAINVALUE_2 = 2, ADC_GAINVALUE_3 = 3 } |
enum | adc_internal_ref_voltage { ADC_INTERNAL_REF_2426MV = 0, ADC_INTERNAL_REF_2305MV, ADC_INTERNAL_REF_2184MV, ADC_INTERNAL_REF_2063MV, ADC_INTERNAL_REF_1941MV, ADC_INTERNAL_REF_1820MV, ADC_INTERNAL_REF_1699MV, ADC_INTERNAL_REF_1578MV, ADC_INTERNAL_REF_3396MV, ADC_INTERNAL_REF_3275MV, ADC_INTERNAL_REF_3154MV, ADC_INTERNAL_REF_3032MV, ADC_INTERNAL_REF_2911MV, ADC_INTERNAL_REF_2790MV, ADC_INTERNAL_REF_2699MV, ADC_INTERNAL_REF_2547MV } |
enum | adc_resolution_t { ADC_10_BITS = ADC_MR_LOWRES_BITS_10, ADC_12_BITS = ADC_MR_LOWRES_BITS_12 } |
enum | adc_settling_time_t { ADC_SETTLING_TIME_0 = ADC_MR_SETTLING_AST3, ADC_SETTLING_TIME_1 = ADC_MR_SETTLING_AST5, ADC_SETTLING_TIME_2 = ADC_MR_SETTLING_AST9, ADC_SETTLING_TIME_3 = ADC_MR_SETTLING_AST17 } |
enum | adc_startup_time { ADC_STARTUP_TIME_0 = ADC_MR_STARTUP_SUT0, ADC_STARTUP_TIME_1 = ADC_MR_STARTUP_SUT8, ADC_STARTUP_TIME_2 = ADC_MR_STARTUP_SUT16, ADC_STARTUP_TIME_3 = ADC_MR_STARTUP_SUT24, ADC_STARTUP_TIME_4 = ADC_MR_STARTUP_SUT64, ADC_STARTUP_TIME_5 = ADC_MR_STARTUP_SUT80, ADC_STARTUP_TIME_6 = ADC_MR_STARTUP_SUT96, ADC_STARTUP_TIME_7 = ADC_MR_STARTUP_SUT112, ADC_STARTUP_TIME_8 = ADC_MR_STARTUP_SUT512, ADC_STARTUP_TIME_9 = ADC_MR_STARTUP_SUT576, ADC_STARTUP_TIME_10 = ADC_MR_STARTUP_SUT640, ADC_STARTUP_TIME_11 = ADC_MR_STARTUP_SUT704, ADC_STARTUP_TIME_12 = ADC_MR_STARTUP_SUT768, ADC_STARTUP_TIME_13 = ADC_MR_STARTUP_SUT832, ADC_STARTUP_TIME_14 = ADC_MR_STARTUP_SUT896, ADC_STARTUP_TIME_15 = ADC_MR_STARTUP_SUT960 } |
Definitions for ADC Start Up Time. More... | |
enum | adc_temp_cmp_mode { ADC_TEMP_CMP_MODE_0 = ADC_TEMPMR_TEMPCMPMOD_LOW, ADC_TEMP_CMP_MODE_1 = ADC_TEMPMR_TEMPCMPMOD_HIGH, ADC_TEMP_CMP_MODE_2 = ADC_TEMPMR_TEMPCMPMOD_IN, ADC_TEMP_CMP_MODE_3 = ADC_TEMPMR_TEMPCMPMOD_OUT } |
Definitions for Temperature Comparison Mode. More... | |
enum | adc_trigger_t { ADC_TRIG_SW = ADC_MR_TRGEN_DIS, ADC_TRIG_EXT = ADC_MR_TRGSEL_ADC_TRIG0 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_0 = ADC_MR_TRGSEL_ADC_TRIG1 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_1 = ADC_MR_TRGSEL_ADC_TRIG2 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_2 = ADC_MR_TRGSEL_ADC_TRIG3 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_3 = ADC_MR_TRGSEL_ADC_TRIG3 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_4 = ADC_MR_TRGSEL_ADC_TRIG4 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_5 = ADC_MR_TRGSEL_ADC_TRIG5 | ADC_MR_TRGEN, ADC_TRIG_TIO_CH_6 = ADC_MR_TRGSEL_ADC_TRIG6 | ADC_MR_TRGEN, ADC_TRIG_PWM_EVENT_LINE_0 = ADC_MR_TRGSEL_ADC_TRIG4 | ADC_MR_TRGEN, ADC_TRIG_PWM_EVENT_LINE_1 = ADC_MR_TRGSEL_ADC_TRIG5 | ADC_MR_TRGEN } |
Functions | |
void | adc12b_configure_power_save (Adc12b *p_adc, const uint8_t uc_sleep, const uint8_t uc_offmode) |
Configure ADC power saving mode. More... | |
void | adc12b_configure_timing (Adc12b *p_adc, const uint32_t ul_sh) |
Configure ADC timing. More... | |
void | adc12b_configure_trigger (Adc12b *p_adc, const enum adc12b_trigger_t trigger) |
Configure conversion trigger and free run mode. More... | |
void | adc12b_disable_all_channel (Adc12b *p_adc) |
Disable all ADC channel. More... | |
void | adc12b_disable_channel (Adc12b *p_adc, const enum adc_channel_num_t adc_ch) |
Disable the specified ADC channel. More... | |
void | adc12b_disable_differential_input (Adc12b *p_adc) |
Disable differential input for the specified channel. More... | |
void | adc12b_disable_input_offset (Adc12b *p_adc) |
Disable analog signal offset for the specified channel. More... | |
void | adc12b_disable_interrupt (Adc12b *p_adc, const uint32_t ul_source) |
Disable ADC interrupts. More... | |
void | adc12b_enable_all_channel (Adc12b *p_adc) |
Enable all ADC channels. More... | |
void | adc12b_enable_channel (Adc12b *p_adc, const enum adc_channel_num_t adc_ch) |
Enable the specified ADC channel. More... | |
void | adc12b_enable_differential_input (Adc12b *p_adc) |
Enable differential input for all channels. More... | |
void | adc12b_enable_input_offset (Adc12b *p_adc) |
Enable analog signal offset for the specified channel. More... | |
void | adc12b_enable_interrupt (Adc12b *p_adc, const uint32_t ul_source) |
Enable ADC interrupts. More... | |
uint32_t | adc12b_get_actual_adc_clock (const Adc12b *p_adc, const uint32_t ul_mck) |
Return the actual ADC clock. More... | |
uint32_t | adc12b_get_channel_status (const Adc12b *p_adc, const enum adc_channel_num_t adc_ch) |
Read the ADC channel status. More... | |
uint32_t | adc12b_get_channel_value (const Adc12b *p_adc, const enum adc_channel_num_t adc_ch) |
Read the ADC result data of the specified channel. More... | |
uint32_t | adc12b_get_interrupt_mask (const Adc12b *p_adc) |
Read ADC interrupt mask. More... | |
uint32_t | adc12b_get_latest_value (const Adc12b *p_adc) |
Read the last ADC result data. More... | |
Pdc * | adc12b_get_pdc_base (const Adc12b *p_adc) |
Get PDC registers base address. More... | |
uint32_t | adc12b_get_status (const Adc12b *p_adc) |
Read ADC interrupt status. More... | |
uint32_t | adc12b_init (Adc12b *p_adc, const uint32_t ul_mck, const uint32_t ul_adc_clock, const uint32_t ul_startuptime, const uint32_t ul_offmode_startuptime) |
Initialize the given ADC with the specified ADC clock and startup time. More... | |
void | adc12b_reset (Adc12b *p_adc) |
Reset ADC. More... | |
void | adc12b_set_bias_current (Adc12b *p_adc, const uint8_t uc_ibctl) |
Adapt performance versus power consumption. More... | |
void | adc12b_set_input_gain (Adc12b *p_adc, const enum adc_gainvalue_t uc_gain) |
Configure input gain for the specified channel. More... | |
void | adc12b_set_resolution (Adc12b *p_adc, const enum adc_resolution_t resolution) |
Configure conversion resolution. More... | |
void | adc12b_start (Adc12b *p_adc) |
Start ADC conversion. More... | |
void | adc_check (Adc *p_adc, const uint32_t ul_mck) |
Check ADC configurations. More... | |
void | adc_configure_power_save (Adc *p_adc, const uint8_t uc_sleep, const uint8_t uc_fwup) |
Configures ADC power saving mode. More... | |
void | adc_configure_sequence (Adc *p_adc, const enum adc_channel_num_t ch_list[], const uint8_t uc_num) |
Configure conversion sequence. More... | |
void | adc_configure_timing (Adc *p_adc, const uint8_t uc_tracking, const enum adc_settling_time_t settling, const uint8_t uc_transfer) |
Configure ADC timing. More... | |
void | adc_configure_trigger (Adc *p_adc, const enum adc_trigger_t trigger, const uint8_t uc_freerun) |
Configure conversion trigger and free run mode. More... | |
void | adc_configure_ts_comparison (Adc *p_adc, enum adc_temp_cmp_mode mode, uint16_t low_threshold, uint16_t high_threshold) |
Configure temperature sensor comparison. More... | |
void | adc_disable_all_channel (Adc *p_adc) |
Disable all ADC channel. More... | |
void | adc_disable_anch (Adc *p_adc) |
Disable analog change. More... | |
void | adc_disable_channel (Adc *p_adc, const enum adc_channel_num_t adc_ch) |
Disable the specified ADC channel. More... | |
void | adc_disable_channel_differential_input (Adc *p_adc, const enum adc_channel_num_t channel) |
Disable differential input for the specified channel. More... | |
void | adc_disable_channel_input_offset (Adc *p_adc, const enum adc_channel_num_t channel) |
Disable analog signal offset for the specified channel. More... | |
void | adc_disable_interrupt (Adc *p_adc, const uint32_t ul_source) |
Disable ADC interrupts. More... | |
void | adc_disable_tag (Adc *p_adc) |
Disable TAG option. More... | |
void | adc_disable_ts (Adc *p_adc) |
Turn off temperature sensor. More... | |
void | adc_enable_all_channel (Adc *p_adc) |
Enable all ADC channels. More... | |
void | adc_enable_anch (Adc *p_adc) |
Enable analog change. More... | |
void | adc_enable_channel (Adc *p_adc, const enum adc_channel_num_t adc_ch) |
Enable the specified ADC channel. More... | |
void | adc_enable_channel_differential_input (Adc *p_adc, const enum adc_channel_num_t channel) |
Enable differential input for the specified channel. More... | |
void | adc_enable_channel_input_offset (Adc *p_adc, const enum adc_channel_num_t channel) |
Enable analog signal offset for the specified channel. More... | |
void | adc_enable_interrupt (Adc *p_adc, const uint32_t ul_source) |
Enable ADC interrupts. More... | |
void | adc_enable_tag (Adc *p_adc) |
Enable TAG option so that the number of the last converted channel can be indicated. More... | |
void | adc_enable_ts (Adc *p_adc) |
Turn on temperature sensor. More... | |
uint32_t | adc_get_actual_adc_clock (const Adc *p_adc, const uint32_t ul_mck) |
Return the actual ADC clock. More... | |
uint32_t | adc_get_channel_status (const Adc *p_adc, const enum adc_channel_num_t adc_ch) |
Read the ADC channel status. More... | |
uint32_t | adc_get_channel_value (const Adc *p_adc, const enum adc_channel_num_t adc_ch) |
Read the ADC result data of the specified channel. More... | |
uint32_t | adc_get_comparison_mode (const Adc *p_adc) |
Get comparison mode. More... | |
uint32_t | adc_get_interrupt_mask (const Adc *p_adc) |
Read ADC interrupt mask. More... | |
uint32_t | adc_get_latest_value (const Adc *p_adc) |
Read the last ADC result data. More... | |
uint32_t | adc_get_overrun_status (const Adc *p_adc) |
Get ADC interrupt and overrun error status. More... | |
Pdc * | adc_get_pdc_base (const Adc *p_adc) |
Get PDC registers base address. More... | |
uint32_t | adc_get_status (const Adc *p_adc) |
Get ADC interrupt and overrun error status. More... | |
enum adc_channel_num_t | adc_get_tag (const Adc *p_adc) |
Indicate the last converted channel. More... | |
uint32_t | adc_get_writeprotect_status (const Adc *p_adc) |
Indicate write protect status. More... | |
uint32_t | adc_init (Adc *p_adc, const uint32_t ul_mck, const uint32_t ul_adc_clock, const enum adc_startup_time startup) |
Initialize the given ADC with the specified ADC clock and startup time. More... | |
void | adc_reset (Adc *p_adc) |
Reset ADC. More... | |
void | adc_set_averaging_trigger (Adc *p_adc, bool multi) |
Set digital averaging trigger. More... | |
void | adc_set_bias_current (Adc *p_adc, const uint8_t uc_ibctl) |
Adapt performance versus power consumption. More... | |
void | adc_set_calibmode (Adc *p_adc) |
Set ADC auto calibration mode. More... | |
void | adc_set_channel_input_gain (Adc *p_adc, const enum adc_channel_num_t channel, const enum adc_gainvalue_t uc_gain) |
Configure input gain for the specified channel. More... | |
void | adc_set_comparison_channel (Adc *p_adc, const enum adc_channel_num_t channel) |
Configure comparison selected channel. More... | |
void | adc_set_comparison_filter (Adc *p_adc, uint8_t filter) |
Set comparison filter. More... | |
void | adc_set_comparison_mode (Adc *p_adc, const uint8_t uc_mode) |
Configure comparison mode. More... | |
void | adc_set_comparison_window (Adc *p_adc, const uint16_t us_low_threshold, const uint16_t us_high_threshold) |
Configure ADC compare window. More... | |
enum status_code | adc_set_internal_reference_voltage (Adc *p_adc, struct adc_internal_ref *ref) |
Set ADC analog control(internal reference voltage). More... | |
void | adc_set_resolution (Adc *p_adc, const enum adc_resolution_t resolution) |
Configure the conversion resolution. More... | |
void | adc_set_writeprotect (Adc *p_adc, const uint32_t ul_enable) |
Enable or disable write protection of ADC registers. More... | |
void | adc_start (Adc *p_adc) |
Start analog-to-digital conversion. More... | |
void | adc_start_sequencer (Adc *p_adc) |
Enable conversion sequencer. More... | |
void | adc_stop_sequencer (Adc *p_adc) |
Disable conversion sequencer. More... | |
#define ADC_FREQ_MAX 20000000 |
Referenced by adc_check().
#define ADC_FREQ_MIN 1000000 |
Referenced by adc_check().
#define ADC_STARTUP_FAST 12 |
Referenced by adc_check().
#define ADC_STARTUP_NORM 40 |
Referenced by adc_check().
enum adc12b_trigger_t |
enum adc_channel_num_t |
enum adc_gainvalue_t |
enum adc_resolution_t |
enum adc_settling_time_t |
enum adc_startup_time |
Definitions for ADC Start Up Time.
enum adc_temp_cmp_mode |
enum adc_trigger_t |
void adc12b_configure_power_save | ( | Adc12b * | p_adc, |
const uint8_t | uc_sleep, | ||
uint8_t | uc_offmode | ||
) |
Configure ADC power saving mode.
p_adc | Pointer to an ADC instance. |
uc_sleep | ADC_MR_SLEEP_NORMAL keeps the ADC Core and reference voltage circuitry ON between conversions. ADC_MR_SLEEP_SLEEP keeps the ADC Core and reference voltage circuitry OFF between conversions. |
uc_offmode | 0 Standby Mode (if Sleep Bit = 1), 1 Off Mode. |
void adc12b_configure_timing | ( | Adc12b * | p_adc, |
const uint32_t | ul_sh | ||
) |
Configure ADC timing.
p_adc | Pointer to an ADC instance. |
ul_sh | ADC sample and hold time = uc_sh / ADC clock. |
void adc12b_configure_trigger | ( | Adc12b * | p_adc, |
const enum adc12b_trigger_t | trigger | ||
) |
Configure conversion trigger and free run mode.
p_adc | Pointer to an ADC instance. |
trigger | Conversion trigger. |
void adc12b_disable_all_channel | ( | Adc12b * | p_adc | ) |
Disable all ADC channel.
p_adc | Pointer to an ADC instance. |
void adc12b_disable_channel | ( | Adc12b * | p_adc, |
const enum adc_channel_num_t | adc_ch | ||
) |
Disable the specified ADC channel.
p_adc | Pointer to an ADC instance. |
adc_ch | ADC channel number. |
void adc12b_disable_differential_input | ( | Adc12b * | p_adc | ) |
Disable differential input for the specified channel.
p_adc | Pointer to an ADC instance. |
void adc12b_disable_input_offset | ( | Adc12b * | p_adc | ) |
Disable analog signal offset for the specified channel.
p_adc | Pointer to an ADC instance. |
void adc12b_disable_interrupt | ( | Adc12b * | p_adc, |
const uint32_t | ul_source | ||
) |
Disable ADC interrupts.
p_adc | Pointer to an ADC instance. |
ul_source | Interrupts to be disabled. |
void adc12b_enable_all_channel | ( | Adc12b * | p_adc | ) |
Enable all ADC channels.
p_adc | Pointer to an ADC instance. |
void adc12b_enable_channel | ( | Adc12b * | p_adc, |
const enum adc_channel_num_t | adc_ch | ||
) |
Enable the specified ADC channel.
p_adc | Pointer to an ADC instance. |
adc_ch | ADC channel number. |
void adc12b_enable_differential_input | ( | Adc12b * | p_adc | ) |
Enable differential input for all channels.
p_adc | Pointer to an ADC instance. |
void adc12b_enable_input_offset | ( | Adc12b * | p_adc | ) |
Enable analog signal offset for the specified channel.
p_adc | Pointer to an ADC instance. |
void adc12b_enable_interrupt | ( | Adc12b * | p_adc, |
const uint32_t | ul_source | ||
) |
Enable ADC interrupts.
p_adc | Pointer to an ADC instance. |
ul_source | Interrupts to be enabled. |
uint32_t adc12b_get_actual_adc_clock | ( | const Adc12b * | p_adc, |
const uint32_t | ul_mck | ||
) |
Return the actual ADC clock.
p_adc | Pointer to an ADC instance. |
ul_mck | Main clock of the device (in Hz). |
0 | The actual ADC clock (in Hz). |
uint32_t adc12b_get_channel_status | ( | const Adc12b * | p_adc, |
const enum adc_channel_num_t | adc_ch | ||
) |
Read the ADC channel status.
p_adc | Pointer to an ADC instance. |
adc_ch | ADC channel number. |
1 | if channel is enabled. |
0 | if channel is disabled. |
uint32_t adc12b_get_channel_value | ( | const Adc12b * | p_adc, |
const enum adc_channel_num_t | adc_ch | ||
) |
Read the ADC result data of the specified channel.
p_adc | Pointer to an ADC instance. |
adc_ch | ADC channel number. |
uint32_t adc12b_get_interrupt_mask | ( | const Adc12b * | p_adc | ) |
Read ADC interrupt mask.
p_adc | Pointer to an ADC instance. |
uint32_t adc12b_get_latest_value | ( | const Adc12b * | p_adc | ) |
Read the last ADC result data.
p_adc | Pointer to an ADC instance. |
Pdc* adc12b_get_pdc_base | ( | const Adc12b * | p_adc | ) |
Get PDC registers base address.
p_adc | Pointer to an ADC instance. |
References UNUSED.
uint32_t adc12b_get_status | ( | const Adc12b * | p_adc | ) |
Read ADC interrupt status.
p_adc | Pointer to an ADC instance. |
ADC | interrupt status. |
uint32_t adc12b_init | ( | Adc12b * | p_adc, |
const uint32_t | ul_mck, | ||
const uint32_t | ul_adc_clock, | ||
const uint32_t | ul_startuptime, | ||
const uint32_t | ul_offmode_startuptime | ||
) |
Initialize the given ADC with the specified ADC clock and startup time.
p_adc | Pointer to an ADC instance. |
ul_mck | Main clock of the device (in Hz). |
ul_adc_clock | Analog-to-Digital conversion clock (in Hz). |
ul_startuptime | ADC startup time value (value in us). Please refer to the product datasheet for more details. |
ul_offmode_startuptime | ADC off mode startup time value (value in us). Please refer to the product datasheet for more details. |
void adc12b_reset | ( | Adc12b * | p_adc | ) |
Reset ADC.
p_adc | Pointer to an ADC instance. |
void adc12b_set_bias_current | ( | Adc12b * | p_adc, |
const uint8_t | uc_ibctl | ||
) |
Adapt performance versus power consumption.
p_adc | Pointer to an ADC instance. |
uc_ibctl | ADC Bias current control. |
void adc12b_set_input_gain | ( | Adc12b * | p_adc, |
const enum adc_gainvalue_t | gain | ||
) |
Configure input gain for the specified channel.
p_adc | Pointer to an ADC instance. |
gain | Gain value for the input. |
void adc12b_set_resolution | ( | Adc12b * | p_adc, |
const enum adc_resolution_t | resolution | ||
) |
Configure conversion resolution.
p_adc | Pointer to an ADC instance. |
resolution | ADC resolution. |
void adc12b_start | ( | Adc12b * | p_adc | ) |
Start ADC conversion.
p_adc | Pointer to an ADC instance. |