Hallo
Ich habe Timer2 als Encoder Timer konfiguriert, was auch super
funktioniert. Jetzt möchte ich zusätzlich einen TimerWert als Compare
Wert setzen, der mir einen Interrupt auslöst sobald die Encoder-Position
diesen Wert erreicht, der Timer soll aber weiterzählen.
Geht das überhaupt? Mit der Konfiguration unten geht es leider nicht.
Beispiel:
Encoder Timer Werte steht auf 1000, sobald ich den Encoder drehe, wird
der Timerstand erhöht bis 10000 usw. Wird die Position von 5000 erreicht
möchte ich einen Interrupt, der Zähler soll aber normal weiterlaufen.
void PositionEncoder_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_5;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource1, GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource5, GPIO_AF_TIM2);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 0xffff;
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Down;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* Configure the timer */
TIM_EncoderInterfaceConfig(TIM2, TIM_EncoderMode_TI12,
TIM_ICPolarity_Rising, TIM_ICPolarity_Falling);
TIM_SetCounter (TIM2, (uint32_t) Encoder_Position_Default);
//set the Timer to the default init value (middle)
/* TIM2 counter enable */
TIM_Cmd(TIM2, ENABLE);
//TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_CC1, ENABLE);
TIM_ITConfig(TIM2, TIM_IT_CC2, ENABLE);
/////////////////////
// configure PWM mode and duration
TIM_OCStructInit (&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
//TIM_OCMode_Timing
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Disable;
//TIM_OutputState_Enable
//TIM_OCInitStructure.TIM_Pulse = PulseDurationInMicroSeconds; // set
the duty cycle / pulse here!
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC2Init(TIM2, &TIM_OCInitStructure);
}
Gast
#3994261
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
15 | |
16 | |
17 | |
18 | |
19 | |
20 | |
21 | |
22 | |
23 | |
24 | |
25 | |
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | |
51 | |
52 | |
53 | |
ich hab das mal in "c" "/c" Brackets gesetzt
Stefan Schulz schrieb: > ich hab das mal in "c" "/c" Brackets gesetzt Danke :-)
Antwort schreiben
Bitte melde dich an, um einen Beitrag zu schreiben.