Hallo, ich mache gerade die ersten Schritte mit ARM und ASF. Ich habe ein SAM D10 Xplained Board und möchte eine AD-Wandlung am Pin 1 (PA2 = ADC Pin 0)durchführen. Aus dem ASF heraus habe ich das Beispiel aus dem quick start guide verwendet http://asf.atmel.com/docs/3.16.0/samd21/html/asfdoc_sam0_adc_basic_use_case.html und damit das folgende Programm geschrieben. Das Problem ist, dass ich nach der AD-Wandlung für die Variable adc_result immer den Wert 0 bekomme.
1 | /*
|
2 | In this use case, the ADC will be configured with the following settings:
|
3 | |
4 | 1V from internal bandgap reference
|
5 | Div 4 clock prescaler
|
6 | 12 bit resolution
|
7 | Window monitor disabled
|
8 | No gain
|
9 | Positive input on ADC PIN 0
|
10 | Negative input on ADC PIN 1
|
11 | Averaging disabled
|
12 | Oversampling disabled
|
13 | Right adjust data
|
14 | Single-ended mode
|
15 | Free running disabled
|
16 | All events (input and generation) disabled
|
17 | Sleep operation disabled
|
18 | No reference compensation
|
19 | No gain/offset correction
|
20 | No added sampling time
|
21 | Pin scan mode disabled
|
22 | */
|
23 | |
24 | #include <asf.h> |
25 | |
26 | struct adc_module adc_instance; |
27 | void configure_adc(void); |
28 | |
29 | void configure_adc(void) |
30 | {
|
31 | struct adc_config config_adc; // Create a ADC module configuration struct, which can be filled out to adjust the configuration of a physical ADC peripheral. |
32 | |
33 | adc_get_config_defaults(&config_adc); // Initialize the ADC configuration struct with the module's default values. |
34 | // This should always be performed before using the configuration struct to ensure that all values are initialized to known default settings.
|
35 | adc_init(&adc_instance, ADC, &config_adc); // Set ADC configurations |
36 | adc_enable(&adc_instance); // Enable the ADC module so that conversions can be made. |
37 | }
|
38 | |
39 | uint16_t adc_result; // global variable |
40 | |
41 | int main (void) |
42 | {
|
43 | system_init(); |
44 | configure_adc(); |
45 | |
46 | uint16_t result; |
47 | |
48 | while (1) |
49 | {
|
50 | cpu_delay_ms(20); // delay in sys ticks |
51 | |
52 | adc_start_conversion(&adc_instance); |
53 | |
54 | do
|
55 | {
|
56 | /* Wait for conversion to be done and read out result */
|
57 | } while (adc_read(&adc_instance, &result) == STATUS_BUSY); |
58 | |
59 | adc_result = result; |
60 | |
61 | asm ("NOP"); |
62 | }
|
63 | }
|