1 | adcifa_opt_t adc_options = {
|
2 | .frequency = 32000,
|
3 | .reference_source = ADCIFA_REF06VDD, // Vref = 0,6*VDDANA
|
4 | .sample_and_hold_disable = false,
|
5 | .single_sequencer_mode = false,
|
6 | .free_running_mode_enable = false,
|
7 | .sleep_mode_enable = false,
|
8 | .mux_settle_more_time = false,
|
9 | };
|
10 |
|
11 |
|
12 | adcifa_sequencer_opt_t adc_seq = {
|
13 | .convnb = 1,
|
14 | .resolution = ADCIFA_SRES_12B, // 12 Bit
|
15 | .trigger_selection = ADCIFA_TRGSEL_SOFT,
|
16 | .start_of_conversion = ADCIFA_SOCB_ALLSEQ,
|
17 | .sh_mode = ADCIFA_SH_MODE_OVERSAMP,
|
18 | .half_word_adjustment = ADCIFA_HWLA_NOADJ,
|
19 | .software_acknowledge = ADCIFA_SA_EOS_SOFTACK,
|
20 | };
|
21 |
|
22 | adcifa_sequencer_conversion_opt_t adc_seq_con0 = {
|
23 | .channel_p = AVR32_ADCIFA_INP_ADCIN0,
|
24 | .channel_n = AVR32_ADCIFA_INN_GNDANA,
|
25 | .gain = ADCIFA_SHG_1,
|
26 | };
|
27 |
|
28 | adcifa_configure(&AVR32_ADCIFA, &adc_options, 32000);
|
29 | while(adcifa_configure_sequencer(&AVR32_ADCIFA, ADCIFA_SEQ0, &adc_seq, &adc_seq_con0) == ADCIFA_CONFIGURATION_REFUSED);
|
30 | adcifa_start_sequencer(&AVR32_ADCIFA, ADCIFA_SEQ0);
|
31 |
|
32 | while(1){
|
33 | get_adc_value(&measure, &adc_options, &adc_seq);
|
34 | }
|
35 |
|
36 |
|
37 |
|
38 | void get_adc_value(uint16_t *measure, adcifa_opt_t *adc_options, adcifa_sequencer_opt_t *adc_seq){
|
39 | while(adcifa_get_values_from_sequencer(&AVR32_ADCIFA, ADCIFA_SEQ0, adc_seq, measure) != ADCIFA_STATUS_COMPLETED);
|
40 |
|
41 | adcifa_configure(&AVR32_ADCIFA, &adc_options, 1500000);
|
42 | adcifa_start_sequencer(&AVR32_ADCIFA, ADCIFA_SEQ0);
|
43 | }
|