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?
Solved! Go to Solution.
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;
Playing around with the value of the prescaler, you can reach even lower frequencies.
I hope this helps!
Victor
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;
Playing around with the value of the prescaler, you can reach even lower frequencies.
I hope this helps!
Victor
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.