PWM with frequency 500 Hz

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

PWM with frequency 500 Hz

跳至解决方案
2,072 次查看
Gamka
Contributor III

I need to get a square waveform and be able to change frequencies. I thought to use PWM for that. I started with pwm example, only commenting out the changes to duty cycles. Originally the frequency was setup to 1000Hz and it works fine. But when I set it to 500Hz the output is about 1450Hz. Is there a way to generate low pwm signal? Or is there some other/better way to generate square wave signal and to be able to change its frequency?

标签 (1)
0 项奖励
回复
1 解答
2,060 次查看
victorjimenez
NXP TechSupport
NXP TechSupport

Hello, 

PWM is the right way to go. The only thing is that when you want to operate at lower frequencies, you need to modify the prescaler of the PWM clock. For example, for reaching a frequency of 500Hz, it's enough if you modify the prescaler to 2. 

/* Clock source prescale is set to divide by 1*/
pwmConfig.prescale = kPWM_Prescale_Divide_2;

victorjimenez_0-1616097146860.png

Playing around with the value of the prescaler, you can reach even lower frequencies. 

victorjimenez_1-1616097185796.png

I hope this helps! 
Victor 

在原帖中查看解决方案

0 项奖励
回复
2 回复数
2,061 次查看
victorjimenez
NXP TechSupport
NXP TechSupport

Hello, 

PWM is the right way to go. The only thing is that when you want to operate at lower frequencies, you need to modify the prescaler of the PWM clock. For example, for reaching a frequency of 500Hz, it's enough if you modify the prescaler to 2. 

/* Clock source prescale is set to divide by 1*/
pwmConfig.prescale = kPWM_Prescale_Divide_2;

victorjimenez_0-1616097146860.png

Playing around with the value of the prescaler, you can reach even lower frequencies. 

victorjimenez_1-1616097185796.png

I hope this helps! 
Victor 

0 项奖励
回复
2,050 次查看
Gamka
Contributor III

Thank you Victor, it helped. Playing with the prescaler value also solved my other issue: I did not want to change the clocks as was in the example.

0 项奖励
回复