Forum: Mikrocontroller und Digitale Elektronik ADC bei STM 32 mehrere Werte abtasten mit DMA


von Anna Mey (Gast)


Lesenswert?

Hallo,
ich versuche mich derzeit am Auslesen des ADC des STM32F407, ich 
betreibe den ADC im tripple mode nach dem untenstehenden Beispiel von 
ST.
Den Buffer habe ich auf 300 Werte erhöht.

Das Beispiel läuft auch ganz gut, nur wenn ich mir die gewandelten Werte 
ansehe so fällt auf das diese erheblich schwanken.
Am Eingang hängt ein Poti zwischen 3V und GND

Hat hier jemand eine Erklärung, oder eine Idee was ich falsch mache?

Grüße Anna

1
#include "stm32f4xx.h"
2
#include "stm32f4xx_adc.h"
3
#include "stm32f4xx_dma.h"
4
#include "stm32f4xx_gpio.h"
5
#include "stm32f4xx_rcc.h"
6
7
8
#define ADC_CDR_ADDRESS    ((uint32_t)0x40012308)
9
__IO uint32_t ADCTripleConvertedValue[300];
10
11
ADC_InitTypeDef       ADC_InitStructure;
12
ADC_CommonInitTypeDef ADC_CommonInitStructure;
13
DMA_InitTypeDef       DMA_InitStructure;
14
GPIO_InitTypeDef      GPIO_InitStructure;
15
16
17
int main(void)
18
{
19
20
  /******************************************************************************/
21
  /*               ADCs interface clock, pin and DMA configuration              */
22
  /******************************************************************************/
23
24
    /* Enable peripheral clocks */
25
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOC, ENABLE);
26
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 | RCC_APB2Periph_ADC2 |
27
                           RCC_APB2Periph_ADC3, ENABLE);
28
29
    /* Configure ADC Channel 12 pin as analog input */
30
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
31
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
32
    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
33
    GPIO_Init(GPIOC, &GPIO_InitStructure);
34
35
    /* DMA2 Stream0 channel0 configuration */
36
    DMA_InitStructure.DMA_Channel = DMA_Channel_0;
37
    DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC_CDR_ADDRESS;
38
    DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADCTripleConvertedValue;
39
    DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory;
40
    DMA_InitStructure.DMA_BufferSize = 300;
41
    DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
42
    DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
43
    DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Word;
44
    DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Word;
45
    DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
46
    DMA_InitStructure.DMA_Priority = DMA_Priority_High;
47
    DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;
48
    DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
49
    DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single;
50
    DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
51
    DMA_Init(DMA2_Stream0, &DMA_InitStructure);
52
53
    /* DMA2_Stream0 enable */
54
    DMA_Cmd(DMA2_Stream0, ENABLE);
55
56
57
    /******************************************************************************/
58
    /*  ADCs configuration: triple interleaved with 5cycles delay to reach 6Msps  */
59
    /******************************************************************************/
60
61
      /* ADC Common configuration *************************************************/
62
      ADC_CommonInitStructure.ADC_Mode = ADC_TripleMode_Interl;
63
      ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles;
64
      ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_2;
65
      ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2;
66
      ADC_CommonInit(&ADC_CommonInitStructure);
67
68
      /* ADC1 regular channel 12 configuration ************************************/
69
      ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b;
70
      ADC_InitStructure.ADC_ScanConvMode = DISABLE;
71
      ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
72
      ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None;
73
      ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
74
      ADC_InitStructure.ADC_NbrOfConversion = 1;
75
      ADC_Init(ADC1, &ADC_InitStructure);
76
77
      ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
78
      /* Enable ADC1 DMA */
79
      ADC_DMACmd(ADC1, ENABLE);
80
81
      /* ADC2 regular channel 12 configuration ************************************/
82
      ADC_Init(ADC2, &ADC_InitStructure);
83
      /* ADC2 regular channel12 configuration */
84
      ADC_RegularChannelConfig(ADC2, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
85
86
      /* ADC3 regular channel 12 configuration ************************************/
87
      ADC_Init(ADC3, &ADC_InitStructure);
88
      /* ADC3 regular channel12 configuration */
89
      ADC_RegularChannelConfig(ADC3, ADC_Channel_12, 1, ADC_SampleTime_3Cycles);
90
91
      /* Enable DMA request after last transfer (multi-ADC mode) ******************/
92
      ADC_MultiModeDMARequestAfterLastTransferCmd(ENABLE);
93
94
      /* Enable ADC1 **************************************************************/
95
      ADC_Cmd(ADC1, ENABLE);
96
97
      /* Enable ADC2 **************************************************************/
98
      ADC_Cmd(ADC2, ENABLE);
99
100
      /* Enable ADC3 **************************************************************/
101
      ADC_Cmd(ADC3, ENABLE);
102
103
      /* Start ADC1 Software Conversion */
104
      ADC_SoftwareStartConv(ADC1);
105
106
    while(1)
107
    {
108
    }
109
}

von Sepp Obermair (Gast)


Lesenswert?

Kann dies evtl. daran liegen, das dein Pott zu hochohmig ist?

Was für einen Widrstand hast du den eingesetzt?

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.