Forum: Mikrocontroller und Digitale Elektronik STM32 Hilfe bei Nutzung des TIM1_IRQHandler


von Marcus P. (spell)


Lesenswert?

Hallo, ich nutze den STM32F107VC und habe bereits den Timer 2 genutzt um 
Interrupts mit Hilfe steigender Flanken auszulösen und so Frequenzen zu 
bestimmmen. Nun möchte ich gern mit Hilfe des Timer 1 zwei Eingänge 
abfragen. Den einen auf steigende und den anderen auf fallende Flanken 
und damit Interrupts auslösen bzw. die Abstände messen. Dazu habe ich in 
die "it.c" Datei nun den "TIM1_IRQHandler"  eingefügt. Setze ich hier 
allerdings Breakpoints kommt es zur Fehlermeldung sobald ich das 
Programm im Debugmodus staren möchte und beim Laden des Programms bleibe 
ich schon im Reset Handler stecken.
1
Reset_Handler:
2
3
/* Copy the data segment initializers from flash to SRAM */
4
  movs  r1, #0
5
  b  LoopCopyDataInit

Ist es möglich die beiden Flanken so abzufragen und was mache ich 
falsch?
Ich haben den Code mal auf das Minimum zusammengeschnitten:

Das Hauptprogramm:

1
#include "stm32f10x.h"
2
#include <math.h>
3
4
// ---------------------------------------------------------
5
6
void RCC_Configuration(void);
7
void TIM_Configuration(void);
8
void GPIO_Configuration(void);
9
void NVIC_Configuration(void);
10
void ADC_Configuration(void);
11
12
  int main(void)
13
  {
14
15
    //Konfigurationen
16
      RCC_Configuration();
17
      TIM_Configuration();
18
      GPIO_Configuration();
19
      NVIC_Configuration();
20
      ADC_Configuration();
21
22
      
23
//Auswahl Aktivierung der Interrupts
24
25
      //Interruptsperre Timer_1
26
        TIM_ITConfig(TIM1, TIM_IT_CC1, DISABLE);
27
        TIM_ITConfig(TIM1, TIM_IT_CC3, DISABLE);
28
        TIM_ITConfig(TIM1, TIM_FLAG_Update, DISABLE);
29
30
/*
31
      //Interruptfreigabe Timer_1
32
        TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
33
        TIM_ITConfig(TIM1, TIM_IT_CC3, ENABLE);
34
        TIM_ITConfig(TIM1, TIM_FLAG_Update, ENABLE);
35
*/
36
37
    while (1)
38
    {
39
40
    }
41
42
43
  }
44
45
46
void RCC_Configuration(void)
47
{
48
49
    RCC_ADCCLKConfig(RCC_PCLK2_Div6);
50
51
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_DAC, ENABLE);
52
53
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1  |
54
                       RCC_APB2Periph_GPIOC |
55
                       RCC_APB2Periph_TIM1  |
56
                       RCC_APB2Periph_GPIOA, ENABLE);
57
}
58
59
60
void TIM_Configuration(void)
61
{
62
63
  TIM_TimeBaseInitTypeDef      TIM_TimeBaseStructure;
64
  TIM_ICInitTypeDef        TIM_ICInitStructure;
65
66
67
/*Timer_1 Frequenzmessung*/
68
69
  TIM_ICInitStructure.TIM_Channel   = TIM_Channel_1;
70
  TIM_ICInitStructure.TIM_ICPolarity   = TIM_ICPolarity_Rising;
71
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
72
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
73
  TIM_ICInitStructure.TIM_ICFilter   = 0x0;
74
    TIM_ICInit(TIM1, &TIM_ICInitStructure);
75
76
  TIM_ICInitStructure.TIM_Channel   = TIM_Channel_3;
77
  TIM_ICInitStructure.TIM_ICPolarity   = TIM_ICPolarity_Falling;
78
  TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
79
  TIM_ICInitStructure.TIM_ICPrescaler = TIM_ICPSC_DIV1;
80
  TIM_ICInitStructure.TIM_ICFilter   = 0x0;
81
    TIM_ICInit(TIM1, &TIM_ICInitStructure);
82
83
// Timer_1 Base Konfiguration
84
  TIM_TimeBaseStructure.TIM_Period       = 0xFFFF;
85
  TIM_TimeBaseStructure.TIM_Prescaler     = 0;
86
  TIM_TimeBaseStructure.TIM_ClockDivision    = 0;
87
  TIM_TimeBaseStructure.TIM_CounterMode     = TIM_CounterMode_Up;
88
  TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
89
    TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
90
91
// Freigabe der Timer
92
  TIM_Cmd(TIM1, ENABLE);
93
94
}
95
96
void GPIO_Configuration(void)
97
{
98
  GPIO_InitTypeDef GPIO_InitStructure;
99
100
101
// ADC1 GPIO PC2 (ADC Channel_12) Analoger Eingang
102
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_2;
103
    GPIO_InitStructure.GPIO_Mode   = GPIO_Mode_AIN;
104
        GPIO_Init(GPIOC, &GPIO_InitStructure);
105
106
// TIM1 channel 1 pin (PA0) steigende Flanke
107
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_8;
108
    GPIO_InitStructure.GPIO_Mode   = GPIO_Mode_IN_FLOATING;
109
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
110
        GPIO_Init(GPIOA, &GPIO_InitStructure);
111
112
// TIM1 channel 3 pin (PA2) fallende Flanke
113
    GPIO_InitStructure.GPIO_Pin   = GPIO_Pin_10;
114
    GPIO_InitStructure.GPIO_Mode   = GPIO_Mode_IN_FLOATING;
115
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
116
      GPIO_Init(GPIOA, &GPIO_InitStructure);
117
118
}
119
120
121
void NVIC_Configuration(void)
122
{
123
124
NVIC_InitTypeDef       NVIC_InitStructure;
125
126
127
//Konfiguration und Freigabe der ADC Interrupts
128
  NVIC_InitStructure.NVIC_IRQChannel = ADC1_2_IRQn;
129
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
130
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
131
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
132
    NVIC_Init(&NVIC_InitStructure);
133
134
135
//Konfiguration und Freigabe Timer_1 Interrupts
136
  NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_IRQn;
137
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
138
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
139
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
140
    NVIC_Init(&NVIC_InitStructure);
141
142
}
143
144
  void ADC_Configuration(void)
145
  {
146
  ADC_InitTypeDef ADC_InitStructure;
147
148
// ADC1 configuration ------------------------------------------------------
149
  ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
150
  ADC_InitStructure.ADC_ScanConvMode = ENABLE;
151
  ADC_InitStructure.ADC_ContinuousConvMode = DISABLE;
152
  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1;
153
//  ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC3;
154
  ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right;
155
  ADC_InitStructure.ADC_NbrOfChannel = 1;
156
  ADC_Init(ADC1, &ADC_InitStructure);
157
158
  // ADC1 regular channel_12 configuration
159
    ADC_RegularChannelConfig(ADC1, ADC_Channel_12, 1, ADC_SampleTime_28Cycles5);
160
161
  //Channel 1 im Diskontinuierlichen Bereich betreiben
162
  ADC_DiscModeChannelCountConfig(ADC1, 1);
163
164
  //Freigabe des diskontinuierlichen Betriebs von ADC1
165
  ADC_DiscModeCmd(ADC1, ENABLE);
166
167
  //Freigabe ADC1 external trigger conversion
168
  ADC_ExternalTrigConvCmd(ADC1, ENABLE);
169
170
  // Enable ADC1 DMA
171
  ADC_DMACmd(ADC1, ENABLE);
172
173
  // Enable ADC1
174
  ADC_Cmd(ADC1, ENABLE);
175
176
  
177
/*ADC kalibirieren */
178
179
    ADC_ResetCalibration(ADC1);
180
    while(ADC_GetResetCalibrationStatus(ADC1));
181
182
    ADC_StartCalibration(ADC1);
183
    while(ADC_GetCalibrationStatus(ADC1));
184
  }


Die Interrupts:
1
void TIM1_IRQHandler(void)
2
{
3
4
5
//######### Interrupt Überläufe ###############
6
 if(TIM_GetFlagStatus(TIM1, TIM_FLAG_Update) == SET)
7
    {
8
      TIM_ClearFlag(TIM1, TIM_FLAG_Update);
9
    }
10
11
12
  if(TIM_GetITStatus(TIM1, TIM_IT_CC1) == SET)  //Wenn positive Flanke detektiert wurde
13
      {
14
        TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);  //Rücksetzen des Interruptbits
15
16
      }
17
18
/*
19
 if(TIM_GetITStatus(TIM1, TIM_IT_CC3) == SET)
20
  {
21
  TIM_ClearITPendingBit(TIM1, TIM_IT_CC3);
22
  }
23
24
*/
25
26
27
}
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.