Hallo Zusammen, ich möchte gerne den ADC des STM32F4 Discovery Board nutzen. Dies funktioniert soweit auch nur schwanken die Werte um ca. 400. Ich habe ein 10k Poti was an 3V und GND angeschlossen ist, zwischen Mittelabnehmer und GND ist noch ein 100nF Keramik Kondensator. Was kann ich dagegen machen? Vielen Dank.
1 | void ADC_init(void) |
2 | {
|
3 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE); |
4 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); |
5 | |
6 | //GPIO initialisieren
|
7 | GPIO_InitTypeDef GPIO_InitStructure; |
8 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_2; |
9 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; |
10 | GPIO_InitStructure.GPIO_OType = GPIO_OType_OD; |
11 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; |
12 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; |
13 | GPIO_Init(GPIOA, &GPIO_InitStructure); |
14 | |
15 | //erweiterte ADC Funktionen
|
16 | ADC_CommonInitTypeDef ADC_CommonInitStruct; |
17 | ADC_CommonInitStruct.ADC_Mode = ADC_Mode_Independent; |
18 | ADC_CommonInitStruct.ADC_Prescaler = ADC_Prescaler_Div4; |
19 | ADC_CommonInitStruct.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; |
20 | ADC_CommonInitStruct.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; |
21 | ADC_CommonInit(&ADC_CommonInitStruct); |
22 | |
23 | //als ADC initialisieren
|
24 | ADC_InitTypeDef ADC_InitStruct; |
25 | ADC_InitStruct.ADC_Resolution = ADC_Resolution_12b; |
26 | ADC_InitStruct.ADC_ScanConvMode = DISABLE; |
27 | ADC_InitStruct.ADC_ContinuousConvMode = ENABLE; |
28 | ADC_InitStruct.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; |
29 | ADC_InitStruct.ADC_DataAlign = ADC_DataAlign_Right; |
30 | ADC_InitStruct.ADC_NbrOfConversion = 1; |
31 | ADC_Init(ADC1, &ADC_InitStruct); |
32 | |
33 | ADC_Cmd(ADC3, ENABLE); |
34 | }
|
35 | |
36 | uint16_t ADC_Read(uint8_t kanal) |
37 | {
|
38 | uint16_t messwert = 0; |
39 | |
40 | ADC_RegularChannelConfig(ADC3, kanal, 1, ADC_SampleTime_480Cycles); |
41 | ADC_SoftwareStartConv(ADC3); |
42 | while(ADC_GetFlagStatus(ADC3, ADC_FLAG_EOC)==RESET); |
43 | messwert = ADC_GetConversionValue(ADC3); |
44 | |
45 | return(messwert); |
46 | }
|
In der main steht dann: "status1 = ADC_Read(Kanal_A)" wobei Kanal_A ein "#define Kanal_A ADC_Channel_1" ist. Diesen Wert gebe ich mir dann auf einem Display aus.