Mikrocontroller und Digitale Elektronik
›
Thread
STM32F407: TIM8 PWM->PC6
Guten Morgen,
versuche nun schon ein paar Stunden den PWM auf PC6 per TIM8 zumlaufen
zubringen.
Habe ich was vergessen?
1 //---------------------------------------------------------------------------
2 void PWM_Init ()
3 {
4 GPIO_InitTypeDef GPIO_InitStructure ;
5 TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure ;
6 TIM_OCInitTypeDef TIM_OCInitStructure ;
7
8 RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOC , ENABLE );
9 GPIO_InitStructure . GPIO_Pin = GPIO_Pin_6 ;
10 GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ;
11 GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ;
12 GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_UP ;
13 GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ;
14 GPIO_Init ( GPIOC , & GPIO_InitStructure );
15 GPIO_PinAFConfig ( GPIOC , GPIO_PinSource6 , GPIO_AF_TIM8 ); // PC6 -> TIM8 Channel 1
16
17 // TIM8 Clock enable
18 RCC_APB2PeriphClockCmd ( RCC_APB2Periph_TIM8 , ENABLE );
19
20 // Timer 8 Config PWM
21 TIM_TimeBaseInitStructure . TIM_Period = 0xFF ;
22 TIM_TimeBaseInitStructure . TIM_Prescaler = 127 ;
23 TIM_TimeBaseInitStructure . TIM_ClockDivision = TIM_CKD_DIV1 ;
24 TIM_TimeBaseInitStructure . TIM_CounterMode = TIM_CounterMode_Up ;
25 TIM_TimeBaseInit ( TIM8 , & TIM_TimeBaseInitStructure );
26
27 TIM_OCInitStructure . TIM_OCMode = TIM_OCMode_PWM1 ;
28 TIM_OCInitStructure . TIM_OutputState = TIM_OutputState_Enable ;
29 TIM_OCInitStructure . TIM_Pulse = 127 ;
30 TIM_OCInitStructure . TIM_OCPolarity = TIM_OCPolarity_High ;
31 TIM_OC1Init ( TIM8 , & TIM_OCInitStructure );
32
33 TIM_OC1PreloadConfig ( TIM8 , TIM_OCPreload_Enable );
34 TIM_ARRPreloadConfig ( TIM8 , ENABLE );
35 TIM_Cmd ( TIM8 , ENABLE );
36
37 TIM8 -> CCR1 = 63 ;
38 }
lg, markus
1
123
Gast
23.04.2016 10:29
#4554361
Hi,,
ich glaube du musst den Timer auch noch starten. den Befehl sehe ichh
nicht
mfg
1
123
Gast
23.04.2016 10:34
#4554367
Activate the TIM peripheral using one of the start functions depending
from the
feature used:
Time Base : HAL_TIM_Base_Start(), HAL_TIM_Base_Start_DMA(),
HAL_TIM_Base_Start_IT()
Input Capture : HAL_TIM_IC_Start(), HAL_TIM_IC_Start_DMA(),
HAL_TIM_IC_Start_IT()
Output Compare : HAL_TIM_OC_Start(), HAL_TIM_OC_Start_DMA(),
HAL_TIM_OC_Start_IT()
PWM generation : HAL_TIM_PWM_Start(), HAL_TIM_PWM_Start_DMA(),
HAL_TIM_PWM_Start_IT()
One-pulse mode output : HAL_TIM_OnePulse_Start(),
HAL_TIM_OnePulse_Start_IT()
Encoder mode output : HAL_TIM_Encoder_Start(),
HAL_TIM_Encoder_Start_DMA(), HAL_TIM_Encoder_Start_IT().
Du musst denke ich entspechend den Befehl der StdPerphLib verwenden
A
aSma>>
Gast
23.04.2016 10:35
#4554370
Servus,
Tim1&Tim8 sind advanced pwm outputs mit komplementären Ausgängen. Diese
eignen sich perfekt für Motorsteuerung...
Aber wenn du diese Schiene weiterhin fahren willst: 1 TIM_CtrlPWMOutputs ( TIM8 , ENABLE );
fehlt am Ende.
T
Thor
Gast
23.04.2016 10:36
#4554373
Hallo.
Danke für die Hinweise.
folgendes fehlte: 1 TIM_OCStructInit ( & TIM_OCInitStructure );
2
3 TIM_CtrlPWMOutputs ( TIM8 , ENABLE );
So funktioniert es jetzt:
1 void PWM_Init ()
2 {
3 GPIO_InitTypeDef GPIO_InitStructure ;
4 TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure ;
5 TIM_OCInitTypeDef TIM_OCInitStructure ;
6
7 RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOC , ENABLE );
8 GPIO_InitStructure . GPIO_Pin = GPIO_Pin_6 ;
9 GPIO_InitStructure . GPIO_OType = GPIO_OType_PP ;
10 GPIO_InitStructure . GPIO_Mode = GPIO_Mode_AF ;
11 GPIO_InitStructure . GPIO_PuPd = GPIO_PuPd_NOPULL ;
12 GPIO_InitStructure . GPIO_Speed = GPIO_Speed_50MHz ;
13 GPIO_Init ( GPIOC , & GPIO_InitStructure );
14 GPIO_PinAFConfig ( GPIOC , GPIO_PinSource6 , GPIO_AF_TIM8 ); // PC6 -> TIM8 Channel 1
15
16 // TIM8 Clock enable
17 RCC_APB2PeriphClockCmd ( RCC_APB2Periph_TIM8 , ENABLE );
18
19 // Timer 8 Config PWM
20 TIM_TimeBaseInitStructure . TIM_Period = 0xFF ;
21 TIM_TimeBaseInitStructure . TIM_Prescaler = 0xFF ;
22 TIM_TimeBaseInitStructure . TIM_ClockDivision = TIM_CKD_DIV1 ;
23 TIM_TimeBaseInitStructure . TIM_CounterMode = TIM_CounterMode_Up ;
24 TIM_TimeBaseInit ( TIM8 , & TIM_TimeBaseInitStructure );
25
26 TIM_OCStructInit ( & TIM_OCInitStructure );
27 TIM_OCInitStructure . TIM_OCMode = TIM_OCMode_PWM1 ;
28 TIM_OCInitStructure . TIM_OutputState = TIM_OutputState_Enable ;
29 TIM_OCInitStructure . TIM_Pulse = 0 ;
30 TIM_OCInitStructure . TIM_OCPolarity = TIM_OCPolarity_Low ;
31 TIM_OC1Init ( TIM8 , & TIM_OCInitStructure );
32
33 TIM_OC1PreloadConfig ( TIM8 , TIM_OCPreload_Enable );
34 TIM_ARRPreloadConfig ( TIM8 , ENABLE );
35 TIM_Cmd ( TIM8 , ENABLE );
36 TIM_CtrlPWMOutputs ( TIM8 , ENABLE );
37
38 TIM8 -> CCR1 = 63 ;
39 }
lg, markus
↑ Nach oben
← Zurück zu Mikrocontroller und Digitale Elektronik
Antwort schreiben