Hi,
ich versuche mit einem Timer jede Sekunde einen Interrupt zu erstellen.
Aber trotz meiner Einstellungen, die rechnerisch stimmen, zeigt mir das
Oszi jede 3,5us einen Interrupt.
Der Cortex läuft auf 32 Mhz. Mit dem Prescaler von 2048 erreiche ich,
das man 32Mhz/2048 = 15625 mal zählen muss, um auf 1s zu kommen.
Dacht ich zumindest.......
Aber wie gesagt, ich bekomme alle 3,5us einen Interrupt.
Habe ich bei meinen Einstellungen was vergessen?
Hier der Code:
1 | int main(void) {
|
2 |
|
3 | outpin_init(&led_ready, 'C', 0);
|
4 | outpin_init(&ready, 'C', 14);
|
5 |
|
6 | outpin_init(&led_4, 'C', 3);
|
7 |
|
8 | // this sets up the oscilator
|
9 | SystemInit();
|
10 | // Initialization
|
11 |
|
12 | CAN_inits();
|
13 | SPI2_Init();
|
14 |
|
15 |
|
16 | /* TIM4 clock enable */
|
17 | RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);
|
18 | /* GPIOB clock enable */
|
19 | RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
20 |
|
21 | TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
|
22 | TIM_TimeBaseStructure.TIM_Period = 15625;
|
23 | TIM_TimeBaseStructure.TIM_Prescaler = 2048;
|
24 | TIM_TimeBaseStructure.TIM_ClockDivision = 0;
|
25 | TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
|
26 |
|
27 | TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
|
28 |
|
29 | /* TIM IT enable */
|
30 | TIM_ITConfig(TIM4, TIM_IT_Update, ENABLE);
|
31 |
|
32 | /*set clock to Internal Clock*/
|
33 | TIM_InternalClockConfig(TIM4);
|
34 |
|
35 | /* TIM3 enable counter */
|
36 | TIM_Cmd(TIM4, ENABLE);
|
37 |
|
38 |
|
39 |
|
40 | /******************* Vector Interrupt ********************/
|
41 | NVIC_InitTypeDef NVIC_InitStructure;
|
42 |
|
43 | /* Enable the TIM3 global Interrupt */
|
44 | NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
|
45 | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
46 | NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
47 | NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
48 | NVIC_Init(&NVIC_InitStructure);
|
49 |
|
50 |
|
51 | //initialization terminated
|
52 | outpin_enable(&led_ready);
|
53 | outpin_enable(&ready);
|
54 |
|
55 |
|
56 | while (1) {}
|
57 |
|
58 |
|
59 | return 0;
|
60 | }
|
und hier die Interruptroutine:
1 | void TIM4_IRQHandler(void) {
|
2 | outpin_toggle(&led_4);
|
3 | }
|
Sieht jemand einen Denkfehler?
Gruß
Sylvia