51#if !SAM4C && !SAM4CP && !SAM4CM
52#define ADC_FREQ_MAX 20000000
54#define ADC_FREQ_MAX 16000000
57#define ADC_FREQ_MIN 1000000
59#define ADC_STARTUP_NORM 40
61#define ADC_STARTUP_FAST 12
64#if SAM3S || SAM4S || SAM3XA
71 ADC_8_BITS = ADC_MR_LOWRES_BITS_8,
76 ADC_8_BITS = ADC_MR_LOWRES_BITS_8,
80#elif SAM4C || SAM4CP || SAM4CM
82 ADC_8_BITS = ADC_MR_LOWRES_BITS_8,
84 ADC_11_BITS = ADC_EMR_OSR_OSR4,
101#if SAM4C || SAM4CP || SAM4CM
109 ADC_TRIG_TIO_CH_6 = ADC_MR_TRGSEL_ADC_TRIG6 |
ADC_MR_TRGEN,
111#if SAM3S || SAM4S || SAM3XA || SAM3U
121enum adc12b_trigger_t {
123 ADC12B_TRIG_SW = ADC12B_MR_TRGEN_DIS,
125 ADC12B_TRIG_EXT = ADC12B_MR_TRGSEL_ADC_TRIG0 | ADC12B_MR_TRGEN,
127 ADC12B_TRIG_TIO_CH_0 = ADC12B_MR_TRGSEL_ADC_TRIG1 | ADC12B_MR_TRGEN,
129 ADC12B_TRIG_TIO_CH_1 = ADC12B_MR_TRGSEL_ADC_TRIG2 | ADC12B_MR_TRGEN,
131 ADC12B_TRIG_TIO_CH_2 = ADC12B_MR_TRGSEL_ADC_TRIG3 | ADC12B_MR_TRGEN,
133 ADC12B_TRIG_PWM_EVENT_LINE_0 = ADC12B_MR_TRGSEL_ADC_TRIG4 | ADC12B_MR_TRGEN,
135 ADC12B_TRIG_PWM_EVENT_LINE_1 = ADC12B_MR_TRGSEL_ADC_TRIG5 | ADC12B_MR_TRGEN
139#if SAM3S || SAM4S || SAM3N || SAM3XA || SAM4C || SAM4CP || SAM4CM
149#if SAM4C || SAM4CP || SAM4CM
176#if !SAM4C && !SAM4CP && !SAM4CM
186#if SAM3S || SAM4S || SAM3XA
195#if SAM3S || SAM4S || SAM3N || SAM3XA || SAM4C || SAM4CP || SAM4CM
217#if SAM3S || SAM4S || SAM3N || SAM3XA || SAM4C || SAM4CP || SAM4CM
218uint32_t
adc_init(
Adc *p_adc,
const uint32_t ul_mck,
221 const uint8_t uc_freerun);
223 const uint8_t uc_num);
230#if SAM4C || SAM4CP || SAM4CM
231void adc_set_comparison_filter(
Adc *p_adc, uint8_t filter);
235 const uint16_t us_high_threshold);
243uint32_t
adc_init(
Adc * p_adc,
const uint32_t ul_mck,
const uint32_t ul_adc_clock,
244 const uint32_t ul_startuptime);
249#if SAM3S8 || SAM4S || SAM3N || SAM3SD8
251 const uint8_t uc_fwup);
252#elif SAM3U || SAM4C || SAM4CP || SAM4CM
272#if SAM3S || SAM4S || SAM3XA
284#elif SAM3N || SAM4C || SAM4CP || SAM4CM
290#if SAM3S || SAM4S || SAM3XA || SAM4C || SAM4CP || SAM4CM
293#if SAM4C || SAM4CP || SAM4CM
295enum adc_temp_cmp_mode {
296 ADC_TEMP_CMP_MODE_0 = ADC_TEMPMR_TEMPCMPMOD_LOW,
297 ADC_TEMP_CMP_MODE_1 = ADC_TEMPMR_TEMPCMPMOD_HIGH,
298 ADC_TEMP_CMP_MODE_2 = ADC_TEMPMR_TEMPCMPMOD_IN,
299 ADC_TEMP_CMP_MODE_3 = ADC_TEMPMR_TEMPCMPMOD_OUT
301void adc_configure_ts_comparison(
Adc *p_adc,
enum adc_temp_cmp_mode mode,
302 uint16_t low_threshold, uint16_t high_threshold);
306#if SAM3S8 || SAM3SD8 || SAM4S
310#if SAM4C || SAM4CP | SAM4CM
311void adc_set_averaging_trigger(
Adc *p_adc,
bool multi);
312enum adc_internal_ref_voltage {
313 ADC_INTERNAL_REF_2426MV = 0,
314 ADC_INTERNAL_REF_2305MV,
315 ADC_INTERNAL_REF_2184MV,
316 ADC_INTERNAL_REF_2063MV,
317 ADC_INTERNAL_REF_1941MV,
318 ADC_INTERNAL_REF_1820MV,
319 ADC_INTERNAL_REF_1699MV,
320 ADC_INTERNAL_REF_1578MV,
321 ADC_INTERNAL_REF_3396MV,
322 ADC_INTERNAL_REF_3275MV,
323 ADC_INTERNAL_REF_3154MV,
324 ADC_INTERNAL_REF_3032MV,
325 ADC_INTERNAL_REF_2911MV,
326 ADC_INTERNAL_REF_2790MV,
327 ADC_INTERNAL_REF_2699MV,
328 ADC_INTERNAL_REF_2547MV,
330struct adc_internal_ref {
331 bool adc_internal_ref_change_enable;
332 enum adc_internal_ref_voltage volt;
333 bool adc_force_internal_ref;
334 bool adc_internal_ref_on;
336enum status_code adc_set_internal_reference_voltage(
Adc *p_adc,
337 struct adc_internal_ref *ref);
341uint32_t adc12b_init(Adc12b *p_adc,
const uint32_t ul_mck,
const uint32_t ul_adc_clock,
342 const uint32_t ul_startuptime,
const uint32_t ul_offmode_startuptime);
343void adc12b_set_resolution(Adc12b *p_adc,
const enum adc_resolution_t resolution);
344void adc12b_configure_trigger(Adc12b *p_adc,
const enum adc12b_trigger_t trigger);
345void adc12b_configure_power_save(Adc12b *p_adc,
const uint8_t uc_sleep,
346 const uint8_t uc_offmode);
347void adc12b_configure_timing(Adc12b *p_adc,
const uint32_t ul_sh);
348void adc12b_start(Adc12b *p_adc);
349void adc12b_reset(Adc12b *p_adc);
352void adc12b_enable_all_channel(Adc12b *p_adc);
353void adc12b_disable_all_channel(Adc12b *p_adc);
354uint32_t adc12b_get_channel_status(
const Adc12b *p_adc,
const enum adc_channel_num_t adc_ch);
355uint32_t adc12b_get_channel_value(
const Adc12b *p_adc,
const enum adc_channel_num_t adc_ch);
356uint32_t adc12b_get_latest_value(
const Adc12b *p_adc);
357void adc12b_enable_differential_input(Adc12b *p_adc);
358void adc12b_disable_differential_input(Adc12b *p_adc);
359void adc12b_enable_input_offset(Adc12b *p_adc);
360void adc12b_disable_input_offset(Adc12b *p_adc);
361void adc12b_set_input_gain(Adc12b *p_adc,
const enum adc_gainvalue_t uc_gain);
362uint32_t adc12b_get_actual_adc_clock(
const Adc12b *p_adc,
const uint32_t ul_mck);
363void adc12b_enable_interrupt(Adc12b *p_adc,
const uint32_t ul_source);
364void adc12b_disable_interrupt(Adc12b *p_adc,
const uint32_t ul_source);
365uint32_t adc12b_get_interrupt_mask(
const Adc12b *p_adc);
366uint32_t adc12b_get_status(
const Adc12b *p_adc);
367void adc12b_set_bias_current(Adc12b *p_adc,
const uint8_t uc_ibctl);
368Pdc *adc12b_get_pdc_base(
const Adc12b *p_adc);
@ ADC_TRIG_PWM_EVENT_LINE_1
@ ADC_TRIG_PWM_EVENT_LINE_0
adc_startup_time
Definitions for ADC Start Up Time.
#define ADC_MR_TRGEN_DIS
(ADC_MR) Hardware triggers are disabled.
#define ADC_MR_STARTUP_SUT960
(ADC_MR) 960 periods of ADCClock
#define ADC_MR_LOWRES_BITS_12
(ADC_MR) 12-bit resolution
#define ADC_MR_TRGEN
(ADC_MR) Trigger Enable
#define ADC_MR_STARTUP_SUT8
(ADC_MR) 8 periods of ADCClock
#define ADC_MR_STARTUP_SUT832
(ADC_MR) 832 periods of ADCClock
#define ADC_MR_STARTUP_SUT768
(ADC_MR) 768 periods of ADCClock
#define ADC_MR_STARTUP_SUT64
(ADC_MR) 64 periods of ADCClock
#define ADC_MR_TRGSEL_ADC_TRIG4
(ADC_MR) PWM Event Line 0
#define ADC_MR_STARTUP_SUT96
(ADC_MR) 96 periods of ADCClock
#define ADC_MR_SETTLING_AST9
(ADC_MR) 9 periods of ADCClock
#define ADC_MR_STARTUP_SUT80
(ADC_MR) 80 periods of ADCClock
#define ADC_MR_SETTLING_AST5
(ADC_MR) 5 periods of ADCClock
#define ADC_MR_STARTUP_SUT896
(ADC_MR) 896 periods of ADCClock
#define ADC_MR_STARTUP_SUT0
(ADC_MR) 0 periods of ADCClock
#define ADC_MR_LOWRES_BITS_10
(ADC_MR) 10-bit resolution
#define ADC_MR_STARTUP_SUT640
(ADC_MR) 640 periods of ADCClock
#define ADC_MR_TRGSEL_ADC_TRIG3
(ADC_MR) TIO Output of the Timer Counter Channel 2
#define ADC_MR_SETTLING_AST3
(ADC_MR) 3 periods of ADCClock
#define ADC_MR_TRGSEL_ADC_TRIG5
(ADC_MR) PWM Event Line 1
#define ADC_MR_STARTUP_SUT24
(ADC_MR) 24 periods of ADCClock
#define ADC_MR_TRGSEL_ADC_TRIG1
(ADC_MR) TIO Output of the Timer Counter Channel 0
#define ADC_MR_STARTUP_SUT512
(ADC_MR) 512 periods of ADCClock
#define ADC_MR_STARTUP_SUT112
(ADC_MR) 112 periods of ADCClock
#define ADC_MR_SETTLING_AST17
(ADC_MR) 17 periods of ADCClock
#define ADC_MR_STARTUP_SUT576
(ADC_MR) 576 periods of ADCClock
#define ADC_MR_STARTUP_SUT704
(ADC_MR) 704 periods of ADCClock
#define ADC_MR_TRGSEL_ADC_TRIG2
(ADC_MR) TIO Output of the Timer Counter Channel 1
#define ADC_MR_STARTUP_SUT16
(ADC_MR) 16 periods of ADCClock
#define ADC_MR_TRGSEL_ADC_TRIG0
(ADC_MR) External trigger
void adc_disable_ts(Adc *p_adc)
Turn off temperature sensor.
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.
uint32_t adc_get_latest_value(const Adc *p_adc)
Read the last ADC result data.
void adc_disable_channel_differential_input(Adc *p_adc, const enum adc_channel_num_t channel)
Disable differential input for the specified channel.
void adc_set_comparison_channel(Adc *p_adc, const enum adc_channel_num_t channel)
Configure comparison selected channel.
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.
void adc_set_resolution(Adc *p_adc, const enum adc_resolution_t resolution)
Configure the conversion resolution.
void adc_start_sequencer(Adc *p_adc)
Enable conversion sequencer.
uint32_t adc_get_writeprotect_status(const Adc *p_adc)
Indicate write protect status.
void adc_set_calibmode(Adc *p_adc)
Set ADC auto calibration mode.
void adc_stop_sequencer(Adc *p_adc)
Disable conversion sequencer.
void adc_set_bias_current(Adc *p_adc, const uint8_t uc_ibctl)
Adapt performance versus power consumption.
void adc_configure_sequence(Adc *p_adc, const enum adc_channel_num_t ch_list[], const uint8_t uc_num)
Configure conversion sequence.
enum adc_channel_num_t adc_get_tag(const Adc *p_adc)
Indicate the last converted channel.
void adc_disable_channel_input_offset(Adc *p_adc, const enum adc_channel_num_t channel)
Disable analog signal offset for the specified channel.
uint32_t adc_get_status(const Adc *p_adc)
Get ADC interrupt and overrun error status.
uint32_t adc_get_overrun_status(const Adc *p_adc)
Get ADC interrupt and overrun error status.
void adc_disable_all_channel(Adc *p_adc)
Disable all ADC channel.
void adc_disable_tag(Adc *p_adc)
Disable TAG option.
void adc_disable_channel(Adc *p_adc, const enum adc_channel_num_t adc_ch)
Disable the specified ADC channel.
void adc_disable_interrupt(Adc *p_adc, const uint32_t ul_source)
Disable ADC interrupts.
void adc_start(Adc *p_adc)
Start analog-to-digital conversion.
void adc_reset(Adc *p_adc)
Reset ADC.
uint32_t adc_get_interrupt_mask(const Adc *p_adc)
Read ADC interrupt mask.
void adc_enable_tag(Adc *p_adc)
Enable TAG option so that the number of the last converted channel can be indicated.
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.
void adc_set_comparison_mode(Adc *p_adc, const uint8_t uc_mode)
Configure comparison mode.
void adc_disable_anch(Adc *p_adc)
Disable analog change.
void adc_enable_channel_differential_input(Adc *p_adc, const enum adc_channel_num_t channel)
Enable differential input for the specified channel.
void adc_enable_all_channel(Adc *p_adc)
Enable all ADC channels.
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.
void adc_enable_interrupt(Adc *p_adc, const uint32_t ul_source)
Enable ADC interrupts.
void adc_enable_anch(Adc *p_adc)
Enable analog change.
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.
void adc_configure_power_save(Adc *p_adc, const uint8_t uc_sleep, const uint8_t uc_fwup)
Configures ADC power saving mode.
uint32_t adc_get_actual_adc_clock(const Adc *p_adc, const uint32_t ul_mck)
Return the actual ADC clock.
void adc_set_writeprotect(Adc *p_adc, const uint32_t ul_enable)
Enable or disable write protection of ADC registers.
Pdc * adc_get_pdc_base(const Adc *p_adc)
Get PDC registers base address.
void adc_enable_channel(Adc *p_adc, const enum adc_channel_num_t adc_ch)
Enable the specified ADC channel.
void adc_check(Adc *p_adc, const uint32_t ul_mck)
Check ADC configurations.
void adc_enable_channel_input_offset(Adc *p_adc, const enum adc_channel_num_t channel)
Enable analog signal offset for the specified channel.
void adc_set_comparison_window(Adc *p_adc, const uint16_t us_low_threshold, const uint16_t us_high_threshold)
Configure ADC compare window.
uint32_t adc_get_comparison_mode(const Adc *p_adc)
Get comparison mode.
uint32_t adc_get_channel_status(const Adc *p_adc, const enum adc_channel_num_t adc_ch)
Read the ADC channel status.
void adc_enable_ts(Adc *p_adc)
Turn on temperature sensor.