From 997460673417bc84249179a3d008b527f155d86d Mon Sep 17 00:00:00 2001 From: Theodor Chikin Date: Tue, 15 Apr 2025 21:29:24 +0300 Subject: [PATCH] =?UTF-8?q?partially=20solved=20issue=20with=20random=20mo?= =?UTF-8?q?dulator=20and=20ADC=20clock=20stopping=20at=20the=20end=20of=20?= =?UTF-8?q?=D0=9B=D0=A7=D0=9C.=20Done:=20when=20we=20want=20to=20stop=20cl?= =?UTF-8?q?ocks=20--=20enable=20IRQ=20on=20sloewr=20clock=20(TIM11).=20In?= =?UTF-8?q?=20IRQ=20switches=20TIM4,=20TIM11=20to=20one-pulse=20mode,=20di?= =?UTF-8?q?sables=20IRQ.=20When=20we=20starting=20these=20timers=20th=20ne?= =?UTF-8?q?xt=20time=20--=20we=20resets=20their=20counters,=20one-pulse=20?= =?UTF-8?q?mode=20disables.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- For_stm32.ioc | 1 + Inc/stm32f7xx_it.h | 1 + Src/main.c | 22 ++++++++++++++++++++-- Src/stm32f7xx_hal_msp.c | 6 ++++++ Src/stm32f7xx_it.c | 17 +++++++++++++++++ 5 files changed, 45 insertions(+), 2 deletions(-) diff --git a/For_stm32.ioc b/For_stm32.ioc index 5d8daa6..566167c 100644 --- a/For_stm32.ioc +++ b/For_stm32.ioc @@ -185,6 +185,7 @@ NVIC.PendSV_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.PriorityGroup=NVIC_PRIORITYGROUP_4 NVIC.SVCall_IRQn=true\:0\:0\:false\:false\:true\:false\:false\:false NVIC.SysTick_IRQn=true\:0\:0\:false\:false\:true\:false\:true\:false +NVIC.TIM1_TRG_COM_TIM11_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.TIM1_UP_TIM10_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.TIM2_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true NVIC.TIM5_IRQn=true\:0\:0\:false\:false\:true\:true\:true\:true diff --git a/Inc/stm32f7xx_it.h b/Inc/stm32f7xx_it.h index 2efb81c..bdc73dc 100644 --- a/Inc/stm32f7xx_it.h +++ b/Inc/stm32f7xx_it.h @@ -57,6 +57,7 @@ void PendSV_Handler(void); void SysTick_Handler(void); void ADC_IRQHandler(void); void TIM1_UP_TIM10_IRQHandler(void); +void TIM1_TRG_COM_TIM11_IRQHandler(void); void TIM2_IRQHandler(void); void USART1_IRQHandler(void); void TIM8_UP_TIM13_IRQHandler(void); diff --git a/Src/main.c b/Src/main.c index 4df5070..50dd2e2 100644 --- a/Src/main.c +++ b/Src/main.c @@ -421,8 +421,19 @@ int main(void) uint16_t trigger_counter = 0; uint16_t trigger_step = (uint8_t )((task.max_param - task.current_param)/task.delta_param * 10); uint16_t task_sheduler = 0; + + + + HAL_TIM_PWM_Stop(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator + HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); //start modulating by Mach-Zander modulator + TIM11 -> CR1 &= ~(1 << 3); //disables one-pulse mode + TIM4 -> CR1 &= ~(1 << 3); //disables one-pulse mode + + + TIM11 -> CNT = 0; TIM4 -> CNT = 0; + HAL_TIM_PWM_Start(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3); //start modulating by Mach-Zander modulator while (task.current_param < task.max_param) @@ -468,8 +479,15 @@ int main(void) //*/ } } - HAL_TIM_PWM_Stop(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator - HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); //start modulating by Mach-Zander modulator + TIM11 -> DIER |= 1; //enable update interrupt. In this IRQ handler we will set both tims to one-pulse mode. + //TIM11 -> CR1 |= 1 << 3; //sets timer to one-pulse mode. So it will turn off at the next UpdateEvent + //TIM4 -> CR1 |= 1 << 3; //sets timer to one-pulse mode. So it will turn off at the next UpdateEvent + //but one-pulse mode should be disabled + + //HAL_TIM_PWM_Stop(&htim11, TIM_CHANNEL_1); //start modulating by Mach-Zander modulator + //HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3); //start modulating by Mach-Zander modulator + + Stop_TIM10(); diff --git a/Src/stm32f7xx_hal_msp.c b/Src/stm32f7xx_hal_msp.c index caaa490..57ccd69 100644 --- a/Src/stm32f7xx_hal_msp.c +++ b/Src/stm32f7xx_hal_msp.c @@ -378,6 +378,9 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) /* USER CODE END TIM11_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_TIM11_CLK_ENABLE(); + /* TIM11 interrupt Init */ + HAL_NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn, 0, 0); + HAL_NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn); /* USER CODE BEGIN TIM11_MspInit 1 */ /* USER CODE END TIM11_MspInit 1 */ @@ -485,6 +488,9 @@ void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) /* USER CODE END TIM11_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM11_CLK_DISABLE(); + + /* TIM11 interrupt DeInit */ + HAL_NVIC_DisableIRQ(TIM1_TRG_COM_TIM11_IRQn); /* USER CODE BEGIN TIM11_MspDeInit 1 */ /* USER CODE END TIM11_MspDeInit 1 */ diff --git a/Src/stm32f7xx_it.c b/Src/stm32f7xx_it.c index b4fcbe4..87e5988 100644 --- a/Src/stm32f7xx_it.c +++ b/Src/stm32f7xx_it.c @@ -65,6 +65,7 @@ extern ADC_HandleTypeDef hadc1; extern ADC_HandleTypeDef hadc3; extern TIM_HandleTypeDef htim8; extern TIM_HandleTypeDef htim10; +extern TIM_HandleTypeDef htim11; /* USER CODE BEGIN EV */ /* USER CODE END EV */ @@ -240,6 +241,22 @@ void TIM1_UP_TIM10_IRQHandler(void) /* USER CODE END TIM1_UP_TIM10_IRQn 1 */ } +/** + * @brief This function handles TIM1 trigger and commutation interrupts and TIM11 global interrupt. + */ +void TIM1_TRG_COM_TIM11_IRQHandler(void) +{ + /* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 0 */ + TIM11 -> CR1 |= 1 << 3; //sets timer to one-pulse mode. So it will turn off at the next UpdateEvent + TIM4 -> CR1 |= 1 << 3; //sets timer to one-pulse mode. So it will turn off at the next UpdateEvent + TIM11 -> DIER &= ~(1); //disable interrupt + /* USER CODE END TIM1_TRG_COM_TIM11_IRQn 0 */ + HAL_TIM_IRQHandler(&htim11); + /* USER CODE BEGIN TIM1_TRG_COM_TIM11_IRQn 1 */ + + /* USER CODE END TIM1_TRG_COM_TIM11_IRQn 1 */ +} + /** * @brief This function handles TIM2 global interrupt. */