Fehler beim Aufruf des Interrupts

OP #5525071
Lesenswert?
• ▲
▼
Hey Leute,

ich habe ein Problem beim Aufrufen eines Interrupts am STM32 über HAL 
und finde meinen Fehler einfach nicht. Das meiste habe ich dabei über 
CubeMX gemacht.
Dabei handelt es sich um 2 Timer die Synchronisiert sind. TIM2 gibt also 
die Laufzeit für TIM1 vor. Periode/Prescaler usw sind dabei jetzt 
erstmal nebensächlich. Vllt kann mir ja jemand von euch helfen.

Timer Initialisierung
1
/* TIM1 init function */
2
static void MX_TIM1_Init(void)
3
{
4

5
  TIM_SlaveConfigTypeDef sSlaveConfig;
6
  TIM_MasterConfigTypeDef sMasterConfig;
7
  TIM_OC_InitTypeDef sConfigOC;
8
  TIM_BreakDeadTimeConfigTypeDef sBreakDeadTimeConfig;
9

10
  htim1.Instance = TIM1;
11
  htim1.Init.Prescaler = 0;
12
  htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
13
  htim1.Init.Period = 20;
14
  htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
15
  htim1.Init.RepetitionCounter = 0;
16
  htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
17
  if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
18
  {
19
    _Error_Handler(__FILE__, __LINE__);
20
  }
21

22
  if (HAL_TIM_PWM_Init(&htim1) != HAL_OK)
23
  {
24
    _Error_Handler(__FILE__, __LINE__);
25
  }
26

27
  sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1;
28
  sSlaveConfig.InputTrigger = TIM_TS_ITR1;
29
  if (HAL_TIM_SlaveConfigSynchronization(&htim1, &sSlaveConfig) != HAL_OK)
30
  {
31
    _Error_Handler(__FILE__, __LINE__);
32
  }
33

34
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
35
  sMasterConfig.MasterOutputTrigger2 = TIM_TRGO2_RESET;
36
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_ENABLE;
37
  if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
38
  {
39
    _Error_Handler(__FILE__, __LINE__);
40
  }
41

42
  sConfigOC.OCMode = TIM_OCMODE_PWM1;
43
  sConfigOC.Pulse = 0;
44
  sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
45
  sConfigOC.OCNPolarity = TIM_OCNPOLARITY_HIGH;
46
  sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
47
  sConfigOC.OCIdleState = TIM_OCIDLESTATE_RESET;
48
  sConfigOC.OCNIdleState = TIM_OCNIDLESTATE_RESET;
49
  if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_1) != HAL_OK)
50
  {
51
    _Error_Handler(__FILE__, __LINE__);
52
  }
53

54
  if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
55
  {
56
    _Error_Handler(__FILE__, __LINE__);
57
  }
58

59
  if (HAL_TIM_PWM_ConfigChannel(&htim1, &sConfigOC, TIM_CHANNEL_3) != HAL_OK)
60
  {
61
    _Error_Handler(__FILE__, __LINE__);
62
  }
63

64
  sBreakDeadTimeConfig.OffStateRunMode = TIM_OSSR_DISABLE;
65
  sBreakDeadTimeConfig.OffStateIDLEMode = TIM_OSSI_DISABLE;
66
  sBreakDeadTimeConfig.LockLevel = TIM_LOCKLEVEL_OFF;
67
  sBreakDeadTimeConfig.DeadTime = 0;
68
  sBreakDeadTimeConfig.BreakState = TIM_BREAK_DISABLE;
69
  sBreakDeadTimeConfig.BreakPolarity = TIM_BREAKPOLARITY_LOW;
70
  sBreakDeadTimeConfig.BreakFilter = 0;
71
  sBreakDeadTimeConfig.Break2State = TIM_BREAK2_DISABLE;
72
  sBreakDeadTimeConfig.Break2Polarity = TIM_BREAK2POLARITY_HIGH;
73
  sBreakDeadTimeConfig.Break2Filter = 0;
74
  sBreakDeadTimeConfig.AutomaticOutput = TIM_AUTOMATICOUTPUT_DISABLE;
75
  if (HAL_TIMEx_ConfigBreakDeadTime(&htim1, &sBreakDeadTimeConfig) != HAL_OK)
76
  {
77
    _Error_Handler(__FILE__, __LINE__);
78
  }
79

80
  HAL_TIM_MspPostInit(&htim1);
81

82
}
83

84
/* TIM2 init function */
85
static void MX_TIM2_Init(void)
86
{
87

88
  TIM_ClockConfigTypeDef sClockSourceConfig;
89
  TIM_MasterConfigTypeDef sMasterConfig;
90

91
  htim2.Instance = TIM2;
92
  htim2.Init.Prescaler = PWMPRESCALER;
93
  htim2.Init.CounterMode = TIM_COUNTERMODE_UP;
94
  htim2.Init.Period = 1000;
95
  htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
96
  htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
97
  if (HAL_TIM_Base_Init(&htim2) != HAL_OK)
98
  {
99
    _Error_Handler(__FILE__, __LINE__);
100
  }
101

102
  sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
103
  if (HAL_TIM_ConfigClockSource(&htim2, &sClockSourceConfig) != HAL_OK)
104
  {
105
    _Error_Handler(__FILE__, __LINE__);
106
  }
107

108
  sMasterConfig.MasterOutputTrigger = TIM_TRGO_UPDATE;
109
  sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
110
  if (HAL_TIMEx_MasterConfigSynchronization(&htim2, &sMasterConfig) != HAL_OK)
111
  {
112
    _Error_Handler(__FILE__, __LINE__);
113
  }
114

115
}
1
void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base)
2
{
3

4
  if(htim_base->Instance==TIM1)
5
  {
6
  /* USER CODE BEGIN TIM1_MspInit 0 */
7

8
  /* USER CODE END TIM1_MspInit 0 */
9
    /* Peripheral clock enable */
10
    __HAL_RCC_TIM1_CLK_ENABLE();
11
    /* TIM1 interrupt Init */
12
    HAL_NVIC_SetPriority(TIM1_BRK_TIM15_IRQn, 0, 0);
13
    HAL_NVIC_EnableIRQ(TIM1_BRK_TIM15_IRQn);
14
    HAL_NVIC_SetPriority(TIM1_CC_IRQn, 0, 0);
15
    HAL_NVIC_EnableIRQ(TIM1_CC_IRQn);
16
  /* USER CODE BEGIN TIM1_MspInit 1 */
17

18
  /* USER CODE END TIM1_MspInit 1 */
19
  }
20
  else if(htim_base->Instance==TIM2)
21
  {
22
  /* USER CODE BEGIN TIM2_MspInit 0 */
23

24
  /* USER CODE END TIM2_MspInit 0 */
25
    /* Peripheral clock enable */
26
    __HAL_RCC_TIM2_CLK_ENABLE();
27
    /* TIM2 interrupt Init */
28
    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 0);
29
    HAL_NVIC_EnableIRQ(TIM2_IRQn);
30
  /* USER CODE BEGIN TIM2_MspInit 1 */
31

32
  /* USER CODE END TIM2_MspInit 1 */
33
  }

Aufzurufende Funktion
1
//ISR for TIM2
2
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
3
{  
4
  if (htim->Instance == TIM2)
5
  {
6
    speeddelay=SetSpeed(PIDController(winkel2,WISHPOSITION));
7
    
8
    if (error>0)
9
      increment=1;
10
    else if (error<0)
11
      increment=-1;
12

13
    switch (COMMUTATIONMODE)
14
      case 1:
15
      {
16
        static int i=0;
17
        if (i>SIZEOFARRAY-1 && increment ==1)
18
        {
19
          i=0;
20
        }
21
        else if (i<0 && increment==-1)
22
        {
23
          i=SIZEOFARRAY-1;
24
        }
25
        
26
        if(counter==0 || counter%abs((int)(speeddelay))==0)
27
        {
28
          TIM1->ARR = PERIODE;
29
          TIM1->CCR1 = pwmSinU[i];
30
          TIM1->CCR2 = pwmSinV[i];
31
          TIM1->CCR3 = pwmSinW[i];
32
          i=i+increment;
33
          counter++;
34
        }
35
        else
36
        {
37
          counter++;
38
        }
39
    
40
        TIM1->PSC = PWMPRESCALER;
41
        break;
42
      case 2:
43
      {
44
        if(counter==0 || counter%(int)(speeddelay)==0)
45
        {
46
          TIM1->CCR1 = SpwmSin[currentStepA];
47
          TIM1->CCR2 = SpwmSin[currentStepB];
48
          TIM1->CCR3 = SpwmSin[currentStepC];
49

50
          //SPWM
51
          currentStepA = currentStepA - increment;
52
          currentStepB = currentStepB - increment;
53
          currentStepC = currentStepC - increment;
54
 
55
          //Check for lookup table overflow and return to opposite end if necessary
56
          if(currentStepA > sizeOfArray-1)  currentStepA = 0;
57
          if(currentStepA < 0)  currentStepA = sizeOfArray;
58
 
59
          if(currentStepB > sizeOfArray-1)  currentStepB = 0;
60
          if(currentStepB < 0)  currentStepB = sizeOfArray;
61
 
62
          if(currentStepC > sizeOfArray-1)  currentStepC = 0;
63
          if(currentStepC < 0) currentStepC = sizeOfArray; 
64
      
65
          counter++;
66
        }
67
          else
68
            counter++;
69
          TIM1->PSC = PWMPRESCALER;
70
        break;
71
        }
72
      }
73
    }
74
  }
OP #5525087
Lesenswert?
• ▲
▼
Daniel schrieb:
> Schau mal, ob die Interrupt Handler in der stm32fxxx_it.c erstellt
> worden sind und ob deine Funktion aufgerufen wird.

Das Update Event wird zumindest aufgerufen aber wenn ich Schritt für 
Schritt durchgehe überspringt es PeriodElapsedCallback
1
/* TIM Update event */
2
  if(__HAL_TIM_GET_FLAG(htim, TIM_FLAG_UPDATE) != RESET)
3
  {
4
    if(__HAL_TIM_GET_IT_SOURCE(htim, TIM_IT_UPDATE) !=RESET)
5
    { 
6
      __HAL_TIM_CLEAR_FLAG(htim, TIM_FLAG_UPDATE);
7
      HAL_TIM_PeriodElapsedCallback(htim);
8
    }

Liegt dann an GET_IT_Source oder? Sry bin noch relativ neu und brauch 
noch mehr Übung

Antwort schreiben

Hinweis: der ursprüngliche Beitrag ist mehr als 6 Monate alt. Bitte hier nur auf die ursprüngliche Frage antworten, für neue Fragen einen neuen Beitrag erstellen.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.