cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I'm using 32L152CDISCOVERY to generate PWM. I try to change the PWM from 78% -> 50% -> 78% -> 50% in loop.There is something wrong while generating PWM. If PWM is not changed on fly, the set value is OK. BR, Tomi

TLuom.1
Associate

Code found in the main.c and figure of the issue seen in PWM_scope_NOK.png.

1 REPLY 1
TDK
Guru
  /* Infinite loop */
  while (1)
  {
	  for (int j=0; j<2; j++)
	  {
		  TIM3->CCR1 = duty_values[j];
	  }
  }

Your code doesn't wait for an update or anything, it just continuously changes the duty cycle between two values.

If you want to alternate between 50% and 78%, you'll need to change CCR1 in a timer update interrupt, or something similar.

If you feel a post has answered your question, please click "Accept as Solution".