Hallo zusammen,
ich möchte bei einem STM32F437 ein PWM-Signal am Pin PC.8 generieren.
Das ist der Timer TIM3 CH3. Der PCLK1 sollte nach Konfiguration 84 MHz
betragen.
Den Timer konfiguriere ich mit der STD_Periph_Lib wie folgt:
1 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
2 | TIM_OCInitTypeDef timerTIM3_OCInitStructure;
|
3 |
|
4 | /* TIM3 clock enable */
|
5 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
|
6 |
|
7 | /**TIM3 GPIO Configuration
|
8 | PC8 ------> TIM3_CH3 */
|
9 | /*Configure GPIO pins : PC8 */
|
10 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
|
11 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
12 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
13 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
|
14 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
15 | GPIO_Init(GPIOC, &GPIO_InitStructure);
|
16 | GPIO_PinAFConfig(GPIOC, GPIO_PinSource8, GPIO_AF_TIM3);
|
17 |
|
18 | /* Time base configuration for TIM3 */
|
19 | TIM_TimeBaseStructure.TIM_Period = 10;
|
20 | TIM_TimeBaseStructure.TIM_Prescaler = 0;
|
21 | TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
22 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
23 | TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
|
24 |
|
25 | /* PWM2 Mode configuration: Channel3 */
|
26 | timerTIM3_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
|
27 | timerTIM3_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
|
28 | timerTIM3_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
|
29 | timerTIM3_OCInitStructure.TIM_Pulse = (uint32_t)5; /* Duty Cycle 50 % */
|
30 | TIM_OC3Init(TIM3, &timerTIM3_OCInitStructure);
|
31 | TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
|
32 | TIM_ARRPreloadConfig(TIM3, ENABLE);
|
33 | /* TIM3 enable counter */
|
34 | TIM_Cmd(TIM3, ENABLE);
|
Erwarten würde ich jetzt ein PWM-Signal mit einem Takt von 8,4MHz
(84MHz/10) und einem Duty-Cycle von 50%
Raus kommt aber ein Takt von 7,7MHz (der Duty Cylce beträgt akzeptable
ca. 54%).
Wie kann das sein? Was mache ich falsch?
Danke & Grüße
Jochen