PWM with frequency 500 Hz

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

PWM with frequency 500 Hz

Jump to solution
2,071 Views
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?

Labels (1)
0 Kudos
Reply
1 Solution
2,059 Views
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 

View solution in original post

0 Kudos
Reply
2 Replies
2,060 Views
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 Kudos
Reply
2,049 Views
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 Kudos
Reply