Hallo,
ich habe einen kleines Programm geschrieben, welches einen Timer
aktiviert und einen Pin toggelt.
1 | void initTIM1(){
|
2 | GPIO_InitTypeDef GPIO_InitStructure,GPIO_InitB;
|
3 | TIM_TimeBaseInitTypeDef TIMDef;
|
4 | TIM_OCInitTypeDef TIM_OC_InitStructure;
|
5 |
|
6 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);
|
7 | RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA ,ENABLE);
|
8 |
|
9 |
|
10 |
|
11 | GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
|
12 | GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
|
13 | GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
14 | GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
|
15 | GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
16 | GPIO_Init(GPIOA,&GPIO_InitStructure);
|
17 | GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM2);
|
18 |
|
19 | TIMDef.TIM_ClockDivision = 1;
|
20 | TIMDef.TIM_CounterMode = TIM_CounterMode_Up;
|
21 | TIMDef.TIM_Period = 130;
|
22 | TIMDef.TIM_Prescaler = 1;
|
23 | TIM_TimeBaseInit(TIM2,&TIMDef);
|
24 |
|
25 | TIM_OC_InitStructure.TIM_OCMode = TIM_OCMode_PWM1;
|
26 | TIM_OC_InitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;
|
27 | TIM_OC_InitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set;
|
28 | TIM_OC_InitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
|
29 | TIM_OC_InitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
|
30 | TIM_OC_InitStructure.TIM_OutputState = TIM_OutputState_Enable;
|
31 | TIM_OC_InitStructure.TIM_OutputNState = TIM_OutputNState_Disable;
|
32 | TIM_OC_InitStructure.TIM_Pulse = 10;
|
33 | TIM_OC1Init(TIM2, &TIM_OC_InitStructure);
|
34 |
|
35 | TIM_Cmd(TIM2,ENABLE);
|
36 | }
|
Die PeriphClockPrescaler habe ich auf eins gesetzt.
1 | RCC_PCLK1Config(RCC_HCLK_Div1);
|
Wenn ich den Prescaler des Timers auf 20 setze. Bekommt ich eine
Freuqenz von 61kHz. Rechne ich das zurück:
Das ist in etwa die Taktfrequenz des Cores. Stelle ich jedoch den
Prescal auf 1 bekomme ich nur CoreClock/2 raus.
Wo ist mein Denkfehler. Hat einer eine Idee?
Danke Gruß Icke