Forum: Mikrocontroller und Digitale Elektronik stm32 capture compare


von Rather then Je (Gast)


Lesenswert?

Ich möchte gerne mit dem STM32 die Zeiten beim Flankenwechsel machen, 
dazu
habe ich folgenden Code unten. Leider wird die Angabe: 
"TIM_ICPolarity_BothEdge" ignoriert und es wird immer nur die steigende 
Flanke erkannt. Weiß jemand wie man den STM32 dazu kriegt die Zeiten zw. 
Steigender und Fallender und andersherum messen zu können?
1
void
2
TIMER3_Init(void) {
3
4
  TIM_ICInitTypeDef  TIM_ICInitStructure;
5
  GPIO_InitTypeDef GPIO_InitStructure;
6
  NVIC_InitTypeDef NVIC_InitStructure;
7
8
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
9
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC, ENABLE);
10
11
  // Enable the TIM3 global Interrupt
12
  NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
13
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
14
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 6;
15
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
16
  NVIC_Init(&NVIC_InitStructure);
17
18
  // TIM3 channel 4 pin (PC.09) configuration
19
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_9;
20
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
21
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
22
  GPIO_Init(GPIOC, &GPIO_InitStructure);
23
  GPIO_PinRemapConfig( GPIO_FullRemap_TIM3, ENABLE);
24
25
  TIM_ICInitStructure.TIM_Channel = TIM_Channel_4;
26
  TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_BothEdge;
27
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
28
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
29
  TIM_ICInitStructure.TIM_ICFilter = 0x00;
30
  TIM_ICInit(TIM3, &TIM_ICInitStructure);
31
  TIM_ITConfig(TIM3, TIM_IT_CC4, ENABLE);
32
  TIM_Cmd(TIM3, ENABLE);
33
34
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
35
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
36
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
37
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
38
39
  GPIO_Init(GPIOB, &GPIO_InitStructure);
40
41
//  NVIC_EnableIRQ(TIM3_IRQn);
42
}

: Verschoben durch Moderator
von Detlef K. (adenin)


Lesenswert?

Poste doch mal bitte, was in CCER-Register von Timer 3 steht.

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.