Skip to content

Commit

Permalink
Timer12の設定追加
Browse files Browse the repository at this point in the history
  • Loading branch information
ShunjiHashimoto committed Aug 12, 2024
1 parent 4787839 commit 1f00637
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 1 deletion.
1 change: 1 addition & 0 deletions Core/Inc/stm32f4xx_it.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void PendSV_Handler(void);
void SysTick_Handler(void);
void TIM1_BRK_TIM9_IRQHandler(void);
void TIM4_IRQHandler(void);
void TIM8_BRK_TIM12_IRQHandler(void);
void TIM5_IRQHandler(void);
/* USER CODE BEGIN EFP */

Expand Down
3 changes: 3 additions & 0 deletions Core/Inc/tim.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ extern TIM_HandleTypeDef htim5;

extern TIM_HandleTypeDef htim9;

extern TIM_HandleTypeDef htim12;

/* USER CODE BEGIN Private defines */

/* USER CODE END Private defines */
Expand All @@ -54,6 +56,7 @@ void MX_TIM3_Init(void);
void MX_TIM4_Init(void);
void MX_TIM5_Init(void);
void MX_TIM9_Init(void);
void MX_TIM12_Init(void);

void HAL_TIM_MspPostInit(TIM_HandleTypeDef *htim);

Expand Down
3 changes: 3 additions & 0 deletions Core/Src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ void initInterrupt(void) {
HAL_TIM_Base_Start_IT(&htim4); // 割り込み処理開始
HAL_TIM_Base_Start_IT(&htim5); // 割り込み処理開始
HAL_TIM_Base_Start_IT(&htim9); // 割り込み処理開始
HAL_TIM_Base_Start_IT(&htim12); // 割り込み処理開始
initEncoder(&encoder_l, &htim2, MotorParam::PULSE_PER_TIRE_ONEROTATION, true);
initEncoder(&encoder_r, &htim3, MotorParam::PULSE_PER_TIRE_ONEROTATION, false);
}
Expand Down Expand Up @@ -120,6 +121,7 @@ int main(void)
MX_ADC2_Init();
MX_TIM5_Init();
MX_TIM9_Init();
MX_TIM12_Init();
/* USER CODE BEGIN 2 */
setbuf(stdout, NULL); // std::outのバッファリングを無効にし、ログを即出力する
gyroInit(&gyro);
Expand All @@ -133,6 +135,7 @@ int main(void)
ledBlink.toggle();
robot_controller.mainControl();
HAL_Delay(MotorParam::RATE);
// printf("encoder_l: %lf, encoder_r: %lf\n\r", encoder_l.rotation_speed, encoder_r.rotation_speed);
/* USER CODE END WHILE */

/* USER CODE BEGIN 3 */
Expand Down
19 changes: 18 additions & 1 deletion Core/Src/stm32f4xx_it.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "gyro.h"

extern void pwmControl();
extern void updateTargetVelocity();
extern void updateModeManager();
extern void updateLog();
/* USER CODE END Includes */
Expand Down Expand Up @@ -67,6 +68,7 @@ extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim4;
extern TIM_HandleTypeDef htim5;
extern TIM_HandleTypeDef htim9;
extern TIM_HandleTypeDef htim12;
/* USER CODE BEGIN EV */

/* USER CODE END EV */
Expand Down Expand Up @@ -219,9 +221,9 @@ void TIM1_BRK_TIM9_IRQHandler(void)
/* USER CODE END TIM1_BRK_TIM9_IRQn 0 */
HAL_TIM_IRQHandler(&htim1);
HAL_TIM_IRQHandler(&htim9);
/* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 1 */
updateModeManager();
updateLog();
/* USER CODE BEGIN TIM1_BRK_TIM9_IRQn 1 */

/* USER CODE END TIM1_BRK_TIM9_IRQn 1 */
}
Expand All @@ -246,6 +248,21 @@ void TIM4_IRQHandler(void)
/* USER CODE END TIM4_IRQn 1 */
}

/**
* @brief This function handles TIM8 break interrupt and TIM12 global interrupt.
*/
void TIM8_BRK_TIM12_IRQHandler(void)
{
/* USER CODE BEGIN TIM8_BRK_TIM12_IRQn 0 */
updateTargetVelocity();

/* USER CODE END TIM8_BRK_TIM12_IRQn 0 */
HAL_TIM_IRQHandler(&htim12);
/* USER CODE BEGIN TIM8_BRK_TIM12_IRQn 1 */

/* USER CODE END TIM8_BRK_TIM12_IRQn 1 */
}

/**
* @brief This function handles TIM5 global interrupt.
*/
Expand Down
63 changes: 63 additions & 0 deletions Core/Src/tim.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ TIM_HandleTypeDef htim3;
TIM_HandleTypeDef htim4;
TIM_HandleTypeDef htim5;
TIM_HandleTypeDef htim9;
TIM_HandleTypeDef htim12;

/* TIM1 init function */
void MX_TIM1_Init(void)
Expand Down Expand Up @@ -305,6 +306,39 @@ void MX_TIM9_Init(void)

/* USER CODE END TIM9_Init 2 */

}
/* TIM12 init function */
void MX_TIM12_Init(void)
{

/* USER CODE BEGIN TIM12_Init 0 */

/* USER CODE END TIM12_Init 0 */

TIM_ClockConfigTypeDef sClockSourceConfig = {0};

/* USER CODE BEGIN TIM12_Init 1 */

/* USER CODE END TIM12_Init 1 */
htim12.Instance = TIM12;
htim12.Init.Prescaler = 84-1;
htim12.Init.CounterMode = TIM_COUNTERMODE_UP;
htim12.Init.Period = 1000-1;
htim12.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim12.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if (HAL_TIM_Base_Init(&htim12) != HAL_OK)
{
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if (HAL_TIM_ConfigClockSource(&htim12, &sClockSourceConfig) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN TIM12_Init 2 */

/* USER CODE END TIM12_Init 2 */

}

void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)
Expand Down Expand Up @@ -370,6 +404,21 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* tim_baseHandle)

/* USER CODE END TIM9_MspInit 1 */
}
else if(tim_baseHandle->Instance==TIM12)
{
/* USER CODE BEGIN TIM12_MspInit 0 */

/* USER CODE END TIM12_MspInit 0 */
/* TIM12 clock enable */
__HAL_RCC_TIM12_CLK_ENABLE();

/* TIM12 interrupt Init */
HAL_NVIC_SetPriority(TIM8_BRK_TIM12_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM8_BRK_TIM12_IRQn);
/* USER CODE BEGIN TIM12_MspInit 1 */

/* USER CODE END TIM12_MspInit 1 */
}
}

void HAL_TIM_Encoder_MspInit(TIM_HandleTypeDef* tim_encoderHandle)
Expand Down Expand Up @@ -527,6 +576,20 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* tim_baseHandle)

/* USER CODE END TIM9_MspDeInit 1 */
}
else if(tim_baseHandle->Instance==TIM12)
{
/* USER CODE BEGIN TIM12_MspDeInit 0 */

/* USER CODE END TIM12_MspDeInit 0 */
/* Peripheral clock disable */
__HAL_RCC_TIM12_CLK_DISABLE();

/* TIM12 interrupt Deinit */
HAL_NVIC_DisableIRQ(TIM8_BRK_TIM12_IRQn);
/* USER CODE BEGIN TIM12_MspDeInit 1 */

/* USER CODE END TIM12_MspDeInit 1 */
}
}

void HAL_TIM_Encoder_MspDeInit(TIM_HandleTypeDef* tim_encoderHandle)
Expand Down

0 comments on commit 1f00637

Please sign in to comment.