Skip to main content
TLuom.1
Visitor II
March 23, 2020
Question

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

  • March 23, 2020
  • 1 reply
  • 736 views

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

This topic has been closed for replies.

1 reply

TDK
March 23, 2020
 /* 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""."