cancel
Showing results for 
Search instead for 
Did you mean: 

Changing MITx_CRRx and ARR on the fly

Wleon.1
Associate II

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 ?

3 REPLIES 3

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

JW

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

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