Skip to main content
Wleon.1
Associate III
March 6, 2020
Question

Changing MITx_CRRx and ARR on the fly

  • March 6, 2020
  • 3 replies
  • 791 views

Hi, I am trying to change MIT4_CRR2 on the fly to change the period of the PWM output by doing:

void EXTI4_IRQHandler(void)
{
 /* USER CODE BEGIN EXTI0_IRQn 0 */
 htim4.Instance->CNT = 0;
 htim4.Instance->CCR3 = 0x0000A978;
 
 /* USER CODE END EXTI0_IRQn 0 */
 HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_4);
 /* USER CODE BEGIN EXTI0_IRQn 1 */
 
 /* USER CODE END EXTI0_IRQn 1 */
} 

Somehow I sometime can see that the value resets itself to the original value. is that the correct way to do it ?

Can I also change ARR on the fly ?

This topic has been closed for replies.

3 replies

waclawek.jan
Super User
March 6, 2020

Check in the respective TIMx_CCMRy, if preload is switched on for the given CCR.

JW

Wleon.1
Wleon.1Author
Associate III
March 6, 2020

Hi, I am using STM32F733ZET6 and I can find no TIM4_CCMR3 register...

waclawek.jan
Super User
March 6, 2020

This is tricky indeed - the CCMR registers contain bits for two channels each, i.e. CCMR1 is related to CH1 and CH2 and CCMR2 is related to CH3 and CH4.

Read the CCMR registers' description in the TIM chapter of RM.

JW