cancel
Showing results for 
Search instead for 
Did you mean: 

PWM Frequency Variation Issue in STM32G0C1RET6

Rohit007
Associate III

Hello, 

I am trying to vary the PWM frequency of Timer 2 in between 20Khz to 200 Khz in stm32G0C1RET6 Board.

1. Whenever I change the Frequency from 200 Khz to 20 Khz, it works. but then I change it again to 200Khz it just doesn't work. my PWM line goes low.

2. but, this issue does not occur with Timer 1 and Timer 3, which I am using to generate other PWM pulses with same configurations as Timer 2.

3. This issue occurs only in changing the Frequency using the ARR value, there is no issue in changing the Duty-cycle using the CCR value.

4. this issue is only occurred in Timer 2, others are working fine.

5. The above one is example of what I am actually need, but I have tried varying the frequency from 1khz to 2khz and vice versa, and it still has the same issue.

Does anyone has any idea what wrong I am doing ?? 

this is a snap of the code, I am working on.

while (1)

{

if (ir == 0) {

TIM2->ARR = 2000 ;

TIM2->CCR1= 1000;

TIM2->CCR2= 1000;

HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);

printf("ir60\r\n");

ir = 1;

} else {

TIM2->ARR = 1000 ;

TIM2->CCR1= 500;

TIM2->CCR2= 500;

HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);

HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);

printf("ir40\r\n");

ir = 0;

}

printf("ARR %d CCR1 %d CCR2 %d\r\n",TIM2->ARR,TIM2->CCR1,TIM2->CCR2);

HAL_Delay(5000);

HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);

HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_2);

HAL_Delay(5000);

 

/* USER CODE END WHILE */

 

/* USER CODE BEGIN 3 */

}

1 REPLY 1

Use ARR preload (i.e. TIMx_CR1.ARPE=1).

JW