STM32F107 ADC mit timer triggern

OP #4124449
Lesenswert?
• ▲
▼
Hallo Gemeinde,

ich verwende ein Olimex Board mit einem STM32f107 und möchte den ADC mit 
einem 200 KHz Signal triggern.
Gemessen wird zur Zeit jede Sekunde, egal ob ich TIM2_CH2 mit 1 Hz oder 
mit 200 KHz einstelle. Wenn ich "ADC_ExternalTrigConv_None" einstelle, 
wird nicht getriggert.

Vielleicht hat einer für mich einen Hinweis, danke.

Gruß Kalle
1
static void TIM_Configuration(void) {
2

3

4
  RCC_ClocksTypeDef RCC_Clocks;
5
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
6
  TIM_OCInitTypeDef TIM_OCInitStructure;
7
  TIM_ICInitTypeDef TIM_ICInitStructure;
8

9
  SystemInit();
10

11
  RCC_GetClocksFreq(&RCC_Clocks);
12

13
  /* SystTick configuration: an interrupt every 10ms */
14
  SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100);
15

16
  /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
17
  /* The Localtime should be updated during the Ethernet packets processing */
18
  NVIC_SetPriority(SysTick_IRQn, 1);
19

20
/* TIM 2 configuration: --> ? Hz ------------------------------------------------------------------ */
21

22
  /* Time base configuration */
23
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
24
  TIM_TimeBaseStructure.TIM_Period = 1000 - 1;
25
    TIM_TimeBaseStructure.TIM_Prescaler = 72000000 / 1000 - 1;
26
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
27
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
28
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
29
   TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
30

31
   /* Master Configuration in PWM1 Mode */
32
   TIM_OCStructInit(&TIM_OCInitStructure);
33
   TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
34
   TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
35
   TIM_OCInitStructure.TIM_Pulse = 100;
36
   TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
37
   TIM_OC2Init(TIM2, &TIM_OCInitStructure);      /* Channel 2 */
38

39
 //  // TODO: wird dies benötigt?
40
 //  TIM_OC2FastConfig(TIM2, TIM_OCFast_Enable);
41

42
   TIM_ICStructInit(&TIM_ICInitStructure);       /* TIM Input Capture Init structure definition  */
43
   TIM_SelectOnePulseMode(TIM2, TIM_OPMode_Single);     /* One Pulse Mode selection */
44

45
  /* Slave Mode selection: TIM2   -->  sync with ITR1 */
46
    TIM_SelectSlaveMode(TIM2, TIM_SlaveMode_Trigger);     /* Slave Mode selection: Trigger Mode */
47
  TIM_SelectInputTrigger(TIM2, TIM_TS_ITR1);       /* Input Trigger selection */
48

49
  /* Select the Master Slave Mode */
50
   TIM_SelectMasterSlaveMode(TIM2, TIM_MasterSlaveMode_Enable);
51

52
  /* Master Mode selection */
53
  TIM_SelectOutputTrigger(TIM2, TIM_TRGOSource_OC2Ref);
54

55
  /* TIM enable counter */
56
  TIM_Cmd(TIM2, ENABLE);
57
}
58

59

60
static void ADC_Configuration(void) {
61

62
  ADC_InitTypeDef ADC_InitStructure;
63
  /* Put everything back to power-on defaults */
64
  ADC_DeInit(ADC1);
65

66
  /* ADC1 configuration ------------------------------------------------------*/
67
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
68
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
69
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
70
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T2_CC2;    // todo:
71
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
72
  ADC_InitStructure.ADC_NbrOfChannel = 1;
73
  ADC_Init(ADC1, &ADC_InitStructure);
74

75
  /* ADC1 regular channel14 configuration - ADC_Channel 4 = pin A4 --> Board PA3 (ADC12_IN4)*/
76
  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_41Cycles5);
77

78
  /* Enable ADC1 DMA */
79
  ADC_DMACmd(ADC1, ENABLE);
80

81
  /* Enable ADC1 external trigger */
82
  ADC_ExternalTrigConvCmd(ADC1, ENABLE);
83

84
  /* Enable ADC1 */
85
  ADC_Cmd(ADC1, ENABLE);
86

87
  /* Enable ADC1 reset calibration register */
88
  ADC_ResetCalibration(ADC1);
89
  /* Check the end of ADC1 reset calibration register */
90
  while(ADC_GetResetCalibrationStatus(ADC1));
91

92
   /* Start ADC1 calibration */
93
  ADC_StartCalibration(ADC1);
94
  /* Check the end of ADC1 calibration */
95
  while(ADC_GetCalibrationStatus(ADC1));
96

97
}
OP #4125859
Lesenswert?
• ▲
▼
Hi Gemeinde,

ich habe es geschafft. Nun wird der ADC mit einem 2 Hz Signal über den 
Timer1 Channel1 getriggert. Messung klappt. Es ist auch kein Problem auf 
200 KHz hoch zu skalieren.
Ein Blick in das Forum des Herstellers ST war sehr hilfreich. clive1 
kennt sich in diesem Gebiet gut aus(Posted: 2/29/2012 11:05 PM).

https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Reading%20voltage%20-ADC&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&currentviews=2019

Viel Spaß, der Kalle.
1
static void TIM_Configuration(void) {
2

3
  RCC_ClocksTypeDef RCC_Clocks;
4
  TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
5
  TIM_OCInitTypeDef TIM_OCInitStructure;
6
  TIM_ICInitTypeDef TIM_ICInitStructure;
7

8
  SystemInit();
9

10
  RCC_GetClocksFreq(&RCC_Clocks);
11

12
  /* SystTick configuration: an interrupt every 10ms */
13
  SysTick_Config(RCC_Clocks.SYSCLK_Frequency / 100);
14

15
  /* Update the SysTick IRQ priority should be higher than the Ethernet IRQ */
16
  /* The Localtime should be updated during the Ethernet packets processing */
17
  NVIC_SetPriority(SysTick_IRQn, 1);
18

19

20
/* TIM1 configuration: 2 Hz ----------------------------------------------------------------------------*/
21
  /* Timer Base configuration */
22

23
  TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
24
  TIM_TimeBaseStructure.TIM_Period = 1000 - 1;
25
  TIM_TimeBaseStructure.TIM_Prescaler = RCC_Clocks.SYSCLK_Frequency / 2000 - 1;
26
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
27
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
28
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
29

30
  /* Channel 1 output configuration */
31
  TIM_OCStructInit(&TIM_OCInitStructure);
32
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
33
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
34
  TIM_OCInitStructure.TIM_Pulse = 1;
35
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
36
  TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
37
  TIM_OC1Init(TIM1, &TIM_OCInitStructure);        /* Channel 1 */
38

39
  /* Very much needed.  Enable Preload register on CCR1. */
40
  TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Enable);
41

42
  /* Enables or disables the specified TIM peripheral. */
43
  TIM_Cmd(TIM1, ENABLE);
44

45
  /* TIM1 Main Output Enable */
46
  TIM_CtrlPWMOutputs(TIM1, ENABLE);
47

48
}
49

50
static void ADC_Configuration(void) {
51

52
  ADC_InitTypeDef ADC_InitStructure;
53
  /* Put everything back to power-on defaults */
54
  ADC_DeInit(ADC1);
55

56
  /* ADC1 configuration ------------------------------------------------------*/
57
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
58
  ADC_InitStructure.ADC_ScanConvMode = DISABLE;
59
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
60
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;  
61
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
62
  ADC_InitStructure.ADC_NbrOfChannel = 1;
63
  ADC_Init(ADC1, &ADC_InitStructure);
64

65
  /* ADC1 regular channel4 configuration - ADC_Channel 4 = pin A4 --> Board PA3 (ADC12_IN4)*/
66
  ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_41Cycles5);
67

68
  /* Enable ADC1 DMA */
69
  ADC_DMACmd(ADC1, ENABLE);
70

71
  /* Enable ADC1 external trigger */
72
  ADC_ExternalTrigConvCmd(ADC1, ENABLE);
73

74
  /* Enable ADC1 */
75
  ADC_Cmd(ADC1, ENABLE);
76

77
  /* Enable ADC1 reset calibration register */
78
  ADC_ResetCalibration(ADC1);
79

80
  /* Check the end of ADC1 reset calibration register */
81
  while(ADC_GetResetCalibrationStatus(ADC1));
82

83
  /* Start ADC1 calibration */
84
  ADC_StartCalibration(ADC1);
85

86
  /* Check the end of ADC1 calibration */
87
  while(ADC_GetCalibrationStatus(ADC1));
88

89
}

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.