Is it possible to set all 6 PWM frequencies to a value between 2 and 5 kHz?

I've read that the base frequency for pins pins 5 and 6 is 62500 Hz. And the divisors for the pins 5 and 6 are only this ones: 1, 8, 64, 256, and 1024.

The closest I can get is 7.812,5 Hz with the 8 divisor. Are there any other possibilities to achieve this?

  • To be honest, I don't know. I haven't choosed yet. My first attempt was to do it with the Raspberry, but the suggestion was to use Arduino. So I found this example: playground.arduino.cc/Code/PwmFrequency – Wa Kai May 26 '19 at 21:08
  • So I know it's goin to be an Arduino, but not exactly which model, because I didn't knew which are capable of my requirements in my question. If this sooo unclear to you, then go on and vote. – Wa Kai May 26 '19 at 21:39
  • ok, since you are talking about arduino for sure, I am removing the vote to close – jsotola May 27 '19 at 1:42

Judging from your mentioning 62.5 kHz as the base frequency for pins 5 and 6, I assume you are talking about an Arduino Uno or something similar.

If you set the timer 0 to phase correct PWM mode (which is how the Arduino core configures the other timers), then its base frequency is about 31.373 kHz (F_CPU/510). With the prescaler set to 8, you get a PWM frequency of about 3.922 kHz on pins 5 and 6.

Note that you can set all three timers in this mode and have 6 PWM channels at this frequency. But note also that by reconfiguring Timer 0 you loose all the standard Arduino timing functions.

  • Thank you for your answer. Are there any other models which are better suited for this? But nevertheless, this is quite helpfull. Thank You! – Wa Kai May 26 '19 at 21:09
  • @WaKai: A Mega has way more timers. On the other hand, if you don't need the Arduino timing functions, the Uno could do the job fine, and the Mega would be overkill. – Edgar Bonet May 26 '19 at 21:14
  • Ah, I see. Clock speed: 16 MHz divided by 510 in phase correct mode for the ~32 kHz base frequency. Neat :-) As far I can think ahead, I won't need any more timers. So the UNO should be perfect. – Wa Kai May 26 '19 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.